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)
  • Loading branch information
blegat authored and fredrikekre committed Jun 26, 2019
1 parent 7bec296 commit d958419
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 d958419

Please sign in to comment.