Skip to content

Broadcasting with ComponentMatrix and Diagonal doesn't work #60

@jonniedie

Description

@jonniedie
julia> using ComponentArrays, LinearAlgebra

julia> a = ComponentArray(rand(3,3), Axis(x=1, y=2, z=3), Axis(x=1, y=2, z=3))
3×3 ComponentMatrix{Float64} with axes Axis(x = 1, y = 2, z = 3) × Axis(x = 1, y = 2, z = 3)
 0.538767  0.431139  0.859582
 0.46988   0.730784  0.289708
 0.110348  0.744679  0.0160751

julia> a + I(3)
ERROR: MethodError: no method matching similar(::Base.Broadcast.Broadcasted{Base.Broadcast.Unknown,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(+),Tuple{ComponentMatrix{Float64},LinearAlgebra.Diagonal{Bool,Array{Bool,1}}}}, ::Type{Float64}, ::Tuple{Base.OneTo{Int64},Base.OneTo{Int64}})
Closest candidates are:
  similar(::AbstractArray, ::Type{T}, ::Tuple{Union{Integer, Base.OneTo},Vararg{Union{Integer, Base.OneTo},N} where N}) where T at abstractarray.jl:638
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{N},Axes,F,Args} where Args<:Tuple where F where Axes, ::Type{ElType}, ::Any) where {N, ElType} at broadcast.jl:197
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.ArrayConflict,Axes,F,Args} where Args<:Tuple where F where Axes, ::Type{ElType}, ::Any) where ElType at broadcast.jl:202
  ...
Stacktrace:
 [1] similar(::Base.Broadcast.Broadcasted{Base.Broadcast.Unknown,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(+),Tuple{ComponentMatrix{Float64},LinearAlgebra.Diagonal{Bool,Array{Bool,1}}}}, ::Type{Float64}) at .\broadcast.jl:196
 [2] similar(::Base.Broadcast.Broadcasted{ComponentArrays.CAStyle{Base.Broadcast.Unknown,Tuple{Axis{(x = 1, y = 2, z = 3)},Axis{(x = 1, y = 2, z = 3)}},2},Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(+),Tuple{ComponentMatrix{Float64},LinearAlgebra.Diagonal{Bool,Array{Bool,1}}}}, ::Type{T} where T) at C:\Users\jdiegelm\.julia\packages\ComponentArrays\caTe8\src\broadcasting.jl:65
 [3] copy at .\broadcast.jl:862 [inlined]
 [4] materialize at .\broadcast.jl:837 [inlined]
 [5] broadcast_preserving_zero_d at .\broadcast.jl:826 [inlined]
 [6] +(::ComponentMatrix{Float64}, ::LinearAlgebra.Diagonal{Bool,Array{Bool,1}}) at .\arraymath.jl:39
 [7] top-level scope at REPL[136]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions