Skip to content
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

Generalize Diagonal * AdjOrTransAbsMat to arbitrary element types #52389

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 4, 2023

The current implementation assumes that the adjoint matrix may be copied to the destination, but this is not necessary in general. This PR changes the implementation to use mul! instead of copy + (l/r)mul! removes the specialized methods, so that the multiplication generalizes to arbitrary element types. In particular, the following works after this:

julia> SM = SMatrix{2,3}(reshape([1:6;],2,3))
2×3 SMatrix{2, 3, Int64, 6} with indices SOneTo(2)×SOneTo(3):
 1  3  5
 2  4  6

julia> D = Diagonal(fill(SM,2))
2×2 Diagonal{SMatrix{2, 3, Int64, 6}, Vector{SMatrix{2, 3, Int64, 6}}}:
 [1 3 5; 2 4 6]               
                [1 3 5; 2 4 6]

julia> A = fill(SM,2,2)'
2×2 adjoint(::Matrix{SMatrix{2, 3, Int64, 6}}) with eltype SMatrix{3, 2, Int64, 6}:
 [1 2; 3 4; 5 6]  [1 2; 3 4; 5 6]
 [1 2; 3 4; 5 6]  [1 2; 3 4; 5 6]

julia> D * A
2×2 Matrix{SMatrix{2, 2, Int64, 4}}:
 [35 44; 44 56]  [35 44; 44 56]
 [35 44; 44 56]  [35 44; 44 56]

julia> A * D
2×2 Matrix{SMatrix{3, 3, Int64, 9}}:
 [5 11 17; 11 25 39; 17 39 61]  [5 11 17; 11 25 39; 17 39 61]
 [5 11 17; 11 25 39; 17 39 61]  [5 11 17; 11 25 39; 17 39 61]

@jishnub jishnub added the linear algebra Linear algebra label Dec 4, 2023
@dkarrasch dkarrasch merged commit c1ca0d3 into master Dec 5, 2023
8 checks passed
@dkarrasch dkarrasch deleted the jishnub/diagadjmul branch December 5, 2023 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants