Support broadcasting over structured block matrices#53909
Merged
Conversation
dkarrasch
approved these changes
Apr 3, 2024
Member
dkarrasch
left a comment
There was a problem hiding this comment.
Awesome! Should we perhaps have some failing tests, like matrices of matrices whose elements don't match in size, or something?
Member
Author
|
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 |
Member
|
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
Member
Author
|
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 |
KristofferC
pushed a commit
that referenced
this pull request
May 13, 2024
This reverts commit 243ebc3.
jishnub
added a commit
that referenced
this pull request
May 17, 2024
lazarusA
pushed a commit
to lazarusA/julia
that referenced
this pull request
Jul 12, 2024
…#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
0Ias the zero element infzero, which isn't really the correct zero if the blocks are rectangular. Nonetheless, this works, asfzerois only used to determine if the structure is preserved.