Skip to content

Commit

Permalink
Fix product of Complex with Hermitian (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Feb 29, 2024
1 parent ccaa222 commit 69fbcaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,6 @@ function Base.:*(α::Number, A::LinearAlgebra.Symmetric{<:AbstractMutable})
return LinearAlgebra.Symmetric(B, c)
end

function Base.:*::Number, A::LinearAlgebra.Hermitian{<:AbstractMutable})
c = LinearAlgebra.sym_uplo(A.uplo)
B = c == :U ? _mult_upper(α, A) : _mult_lower(α, A)
return LinearAlgebra.Hermitian(B, c)
end

# Fix ambiguity identified by Aqua.jl.
function Base.:*::Real, A::LinearAlgebra.Hermitian{<:AbstractMutable})
c = LinearAlgebra.sym_uplo(A.uplo)
B = c == :U ? _mult_upper(α, A) : _mult_lower(α, A)
Expand Down
8 changes: 8 additions & 0 deletions test/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ end
@test all(MA.isequal_canonical.(2 * LinearAlgebra.Hermitian(A, :L), D))
@test all(MA.isequal_canonical.(2 * LinearAlgebra.Hermitian(A, :U), D))
end

@testset "*(::Complex, ::Hermitian)" begin
A = BigInt[1 2; 2 3]
B = LinearAlgebra.Hermitian(DummyBigInt.(A))
C = 2im * A
@test 2im * B == C
@test C isa Matrix{Complex{BigInt}}
end
2 changes: 2 additions & 0 deletions test/dummy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ end
function Base.:^(x::DummyBigInt, y::Union{Integer,UniformScaling{<:Integer}})
return DummyBigInt(x.data^y)
end

Base.:*(x::Complex, y::DummyBigInt) = x * y.data

0 comments on commit 69fbcaa

Please sign in to comment.