LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

Structured matrices don't extend missing dimensions correctly in broadcasting

Open jishnub opened this issue 1 year ago • 1 comments

julia> D1 = Diagonal([1]); D2 = Diagonal([1,2]);

julia> D1 .+ D2
2×2 Diagonal{Int64, Vector{Int64}}:
 2  ⋅
 ⋅  3

julia> Matrix(D1) .+ D2
2×2 Matrix{Int64}:
 2  1
 1  3

Ideally, these should produce identical results. In the structured case, the 1x1 matrix D1 isn't expanded to ones(size(D2)), but instead it's expanded to Diagonal(ones(Int, size(D2,1))). I'm unsure if there's a way to resolve this while preserving type-stability.

jishnub avatar Apr 15 '24 06:04 jishnub