Skip to content

Commit

Permalink
Fix multiplying Symmetric and Hermitian matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Feb 14, 2024
1 parent 48569d2 commit 22e0bac
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,26 +474,27 @@ Base.:*(A::AbstractArray, α::AbstractMutable) = A .* α

# Needed for Julia v1.0, otherwise, `broadcast(*, α, A)` gives a `Array` and
# not a `Symmetric`.

_mult_upper(α, A) = parent* LinearAlgebra.UpperTriangular(parent(A)))
_mult_lower(α, A) = parent* LinearAlgebra.LowerTriangular(parent(A)))

Check warning on line 479 in src/dispatch.jl

View check run for this annotation

Codecov / codecov/patch

src/dispatch.jl#L479

Added line #L479 was not covered by tests

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

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

Check warning on line 490 in src/dispatch.jl

View check run for this annotation

Codecov / codecov/patch

src/dispatch.jl#L488-L490

Added lines #L488 - L490 were not covered by tests
end

# Fix ambiguity identified by Aqua.jl.
function Base.:*::Real, A::LinearAlgebra.Hermitian{<:AbstractMutable})
return LinearAlgebra.Hermitian(
α * parent(A),
LinearAlgebra.sym_uplo(A.uplo),
)
c = LinearAlgebra.sym_uplo(A.uplo)
B = c == :U ? _mult_upper(α, A) : _mult_lower(α, A)
return LinearAlgebra.Hermitian(B, c)

Check warning on line 497 in src/dispatch.jl

View check run for this annotation

Codecov / codecov/patch

src/dispatch.jl#L495-L497

Added lines #L495 - L497 were not covered by tests
end

# These three have specific methods that just redirect to `Matrix{T}` which
Expand Down

0 comments on commit 22e0bac

Please sign in to comment.