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

Resolve mul!(::Matrix, ::Diagonal, ::Adjoint) ambiguity #27405

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ mul!(out::AbstractVector, A::Transpose{<:Any,<:Diagonal}, in::AbstractVector) =
mul!(out::AbstractMatrix, A::Diagonal, in::AbstractMatrix) = out .= A.diag .* in
mul!(out::AbstractMatrix, A::Adjoint{<:Any,<:Diagonal}, in::AbstractMatrix) = out .= adjoint.(A.parent.diag) .* in
mul!(out::AbstractMatrix, A::Transpose{<:Any,<:Diagonal}, in::AbstractMatrix) = out .= transpose.(A.parent.diag) .* in
mul!(out::AbstractMatrix, A::Adjoint{<:Any,<:Diagonal}, in::Adjoint{<:Any, <:AbstractMatrix}) = out .= adjoint.(A.parent.diag) .* in
mul!(out::AbstractMatrix, A::Transpose{<:Any,<:Diagonal}, in::Transpose{<:Any,<:AbstractMatrix}) = out .= transpose.(A.parent.diag) .* in

mul!(out::AbstractMatrix, A::Diagonal, in::Adjoint{<:Any,<:AbstractMatrix}) = out .= A.diag .* in
mul!(out::AbstractMatrix, A::Diagonal, in::Transpose{<:Any,<:AbstractMatrix}) = out .= A.diag .* in

# ambiguities with Symmetric/Hermitian
# RealHermSymComplex[Sym]/[Herm] only include Number; invariant to [c]transpose
Expand Down
12 changes: 12 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ srand(1)
@test (r = Matrix(D)' * UU ; mul!(UUU, adjoint(D), UU) ≈ r ≈ UUU)
@test (r = transpose(Matrix(D)) * UU ; mul!(UUU, transpose(D), UU) ≈ r ≈ UUU)

# Performance specialisations / ambiguity checks for A_mul_B*!
@test (r = Matrix(D) * UU' ; mul!(UUU, D, adjoint(UU)) ≈ r ≈ UUU)
@test (r = Matrix(D) * transpose(UU) ; mul!(UUU, D, transpose(UU)) ≈ r ≈ UUU)

# Performance specialisations / ambiguity checks for A*_mul_B*!
# Using non-lazy adjoint/transpose (so it's actually A_mul_B*!):
@test (r = Matrix(D') * UU' ; mul!(UUU, adjoint(D), adjoint(UU)) ≈ r ≈ UUU)
@test (r = Matrix(transpose(D)) * transpose(UU) ; mul!(UUU, transpose(D), transpose(UU)) ≈ r ≈ UUU)
# Using lazy Adjoint/Transpose:
@test (r = Matrix(D') * UU' ; mul!(UUU, Adjoint(D), adjoint(UU)) ≈ r ≈ UUU)
@test (r = Matrix(transpose(D)) * Transpose(UU) ; mul!(UUU, transpose(D), transpose(UU)) ≈ r ≈ UUU)

# make sure that mul!(A, {Adj|Trans}(B)) works with B as a Diagonal
VV = Array(D)
DD = copy(D)
Expand Down