Skip to content

Commit

Permalink
fix matrix multiplication interaction with HermOrSym and Diagonal (#2…
Browse files Browse the repository at this point in the history
…2474)

(cherry picked from commit 0990d9b)
  • Loading branch information
fredrikekre authored and vtjnash committed Sep 14, 2017
1 parent dc35b97 commit 94a8bd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ end
(*)(D::Diagonal, B::AbstractTriangular) = A_mul_B!(D, copy(B))

(*)(A::AbstractMatrix, D::Diagonal) =
scale!(similar(A, promote_op(*, eltype(A), eltype(D.diag))), A, D.diag)
scale!(similar(A, promote_op(*, eltype(A), eltype(D.diag)), size(A)), A, D.diag)
(*)(D::Diagonal, A::AbstractMatrix) =
scale!(similar(A, promote_op(*, eltype(A), eltype(D.diag))), D.diag, A)
scale!(similar(A, promote_op(*, eltype(A), eltype(D.diag)), size(A)), D.diag, A)

A_mul_B!(A::Union{LowerTriangular,UpperTriangular}, D::Diagonal) =
typeof(A)(A_mul_B!(A.data, D))
Expand Down
15 changes: 15 additions & 0 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,18 @@ end
@test logm(D) == Diagonal([logm([1 2; 3 4]), logm([1 2; 3 4])])
@test sqrtm(D) == Diagonal([sqrtm([1 2; 3 4]), sqrtm([1 2; 3 4])])
end

@testset "multiplication with Symmetric/Hermitian" begin
for T in (Float64, Complex128)
D = Diagonal(randn(T, n))
A = randn(T, n, n); A = A'A
S = Symmetric(A)
H = Hermitian(A)
for f in (*, Ac_mul_B, A_mul_Bc, Ac_mul_Bc, At_mul_B, A_mul_Bt, At_mul_Bt)
@test f(D, S) f(Matrix(D), Matrix(S))
@test f(D, H) f(Matrix(D), Matrix(H))
@test f(S, D) f(Matrix(S), Matrix(D))
@test f(S, H) f(Matrix(S), Matrix(H))
end
end
end

0 comments on commit 94a8bd8

Please sign in to comment.