-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Avoid explicitly evaluating zero elements in certain structured matrix broadcast operations #985
Comments
Hello, could you please advise on why this may be advantageous? |
This is more about getting edge cases working so that there are no surprises when writing generic code. The specific example presented above may not mean much |
Actually, turns out that this is needed for |
This was referenced Mar 31, 2024
jishnub
referenced
this issue
in JuliaLang/julia
Apr 7, 2024
Fix https://github.com/JuliaLang/julia/issues/48664 After this, broadcasting over structured block matrices with matrix-valued elements works: ```julia julia> D = Diagonal([[1 2; 3 4], [5 6; 7 8]]) 2×2 Diagonal{Matrix{Int64}, Vector{Matrix{Int64}}}: [1 2; 3 4] ⋅ ⋅ [5 6; 7 8] julia> D .+ D 2×2 Diagonal{Matrix{Int64}, Vector{Matrix{Int64}}}: [2 4; 6 8] ⋅ ⋅ [10 12; 14 16] julia> cos.(D) 2×2 Matrix{Matrix{Float64}}: [0.855423 -0.110876; -0.166315 0.689109] [1.0 0.0; 0.0 1.0] [1.0 0.0; 0.0 1.0] [0.928384 -0.069963; -0.0816235 0.893403] ``` Such operations show up when using `BlockArrays`. The implementation is a bit hacky as it uses `0I` as the zero element in `fzero`, which isn't really the correct zero if the blocks are rectangular. Nonetheless, this works, as `fzero` is only used to determine if the structure is preserved.
KristofferC
referenced
this issue
Nov 14, 2024
Fix https://github.com/JuliaLang/julia/issues/48664 After this, broadcasting over structured block matrices with matrix-valued elements works: ```julia julia> D = Diagonal([[1 2; 3 4], [5 6; 7 8]]) 2×2 Diagonal{Matrix{Int64}, Vector{Matrix{Int64}}}: [1 2; 3 4] ⋅ ⋅ [5 6; 7 8] julia> D .+ D 2×2 Diagonal{Matrix{Int64}, Vector{Matrix{Int64}}}: [2 4; 6 8] ⋅ ⋅ [10 12; 14 16] julia> cos.(D) 2×2 Matrix{Matrix{Float64}}: [0.855423 -0.110876; -0.166315 0.689109] [1.0 0.0; 0.0 1.0] [1.0 0.0; 0.0 1.0] [0.928384 -0.069963; -0.0816235 0.893403] ``` Such operations show up when using `BlockArrays`. The implementation is a bit hacky as it uses `0I` as the zero element in `fzero`, which isn't really the correct zero if the blocks are rectangular. Nonetheless, this works, as `fzero` is only used to determine if the structure is preserved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For block-banded structured matrix types, the zero elements may not be well-defined, e.g:
However, in this case, the result may be obtained without any reference to the zeros.
I wonder if it might be possible to evaluate the result using broadcasting without explicitly evaluating the zero elements?
The text was updated successfully, but these errors were encountered: