-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support broadcasting over structured block matrices #53909
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Should we perhaps have some failing tests, like matrices of matrices whose elements don't match in size, or something?
I'm actually struggling to come up with an example that specifically fails despite this, and isn't related to the properties of the elements (or missing |
I was thinking of something like A = Diagonal([zeros(2,3) for _ in 1:3]) # or zeros(3,3)
B = Diagonal([zeros(2,2) for _ in 1:3])
@testthrows SomeError A .+ B |
854c779
to
02924c8
Compare
I've added a test with incompatible element sizes, and also one that is directly related to this PR's changes: julia> D = Diagonal([ones(1,1), ones(1,1)])
2×2 Diagonal{Matrix{Float64}, Vector{Matrix{Float64}}}:
[1.0;;] ⋅
⋅ [1.0;;]
julia> size.(D)
ERROR: MethodError: no method matching size(::UniformScaling{Float64})
The function `size` exists, but no method is defined for this combination of argument types.
[...] Thankfully, this isn't a regression, as the operation didn't work before either. In fact, the following works now: julia> ndims.(D)
2×2 Matrix{Int64}:
2 2
2 2 |
This reverts commit 243ebc3.
…#53909" (JuliaLang#54460) This was reverted in JuliaLang#54332. This needs JuliaLang#54459 for the tests to pass. Opening this now to not forget about it.
Fix JuliaLang/LinearAlgebra.jl#985
After this, broadcasting over structured block matrices with matrix-valued elements works:
Such operations show up when using
BlockArrays
.The implementation is a bit hacky as it uses
0I
as the zero element infzero
, which isn't really the correct zero if the blocks are rectangular. Nonetheless, this works, asfzero
is only used to determine if the structure is preserved.