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

Drop support for mixed blocks in broadcast?

Open dlfivefifty opened this issue 4 years ago • 0 comments

At the moment we combine the block structure in broadcasting. E.g.:

julia> mortar([[1,2],[3,4,5]]) + mortar([[1],[2,3,4],[5]])
4-blocked 5-element BlockVector{Int64}:
  2
 ──
  4
 ──
  6
  8
 ──
 10

But this was an arbitrary decision with a major drawback: it makes it hard to preserve specialised block structure in a type-stable way. E.g. here we allocate since its impossible at compile time to determine Fill(2,2) is the same:

julia> x = BlockArray(1:4, Fill(2,2))
2-blocked 4-element BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{StepRange{Int64, Int64}}}}:
 1
 2
 ─
 3
 4

julia> x + x
2-blocked 4-element BlockVector{Int64}:
 2
 4
 ─
 6
 8

I suspect it would be more useful to error out if the block structure doesn't match. With the exception of the length-1 special case to still support:


julia> x .+ x'
2×2-blocked 4×4 BlockMatrix{Int64, Matrix{Matrix{Int64}}, Tuple{BlockedUnitRange{StepRange{Int64, Int64}}, BlockedUnitRange{StepRange{Int64, Int64}}}}:
 2  3  │  4  5
 3  4  │  5  6
 ──────┼──────
 4  5  │  6  7
 5  6  │  7  8

dlfivefifty avatar Sep 28 '21 15:09 dlfivefifty