Skip to content

Commit

Permalink
Fix element type of -Symmetric(A) for e.g. Bool or JuMP.VariableRef, f…
Browse files Browse the repository at this point in the history
…ixes #32374 (#32375)

(cherry picked from commit d958419)
  • Loading branch information
blegat authored and KristofferC committed Jul 1, 2019
1 parent 257c6ce commit 3546c63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ function triu(A::Symmetric, k::Integer=0)
end
end

(-)(A::Symmetric{Tv,S}) where {Tv,S} = Symmetric{Tv,S}(-A.data, A.uplo)
(-)(A::Hermitian{Tv,S}) where {Tv,S} = Hermitian{Tv,S}(-A.data, A.uplo)
(-)(A::Symmetric) = Symmetric(-A.data, sym_uplo(A.uplo))
(-)(A::Hermitian) = Hermitian(-A.data, sym_uplo(A.uplo))

## Addition/subtraction
for f in (:+, :-)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ end
@testset "Unary minus for Symmetric/Hermitian matrices" begin
@test (-Symmetric(asym))::typeof(Symmetric(asym)) == -asym
@test (-Hermitian(aherm))::typeof(Hermitian(aherm)) == -aherm
@test (-Symmetric([true true; false false]))::Symmetric{Int,Matrix{Int}} == [-1 -1; -1 0]
@test (-Hermitian([true false; true false]))::Hermitian{Int,Matrix{Int}} == [-1 0; 0 0]
end

@testset "Addition and subtraction for Symmetric/Hermitian matrices" begin
Expand Down

0 comments on commit 3546c63

Please sign in to comment.