From 60b1fea46a2900ae2ad589165ca88a789da008b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 26 Jun 2019 08:31:35 +0100 Subject: [PATCH] Fix element type of -Symmetric(A) for e.g. Bool or JuMP.VariableRef, fixes #32374 (#32375) (cherry picked from commit d95841934a66530ab54229aea2ed5d80dbc8c070) --- stdlib/LinearAlgebra/src/symmetric.jl | 4 ++-- stdlib/LinearAlgebra/test/symmetric.jl | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl index b5f6204361230..a43e338670ea0 100644 --- a/stdlib/LinearAlgebra/src/symmetric.jl +++ b/stdlib/LinearAlgebra/src/symmetric.jl @@ -390,8 +390,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)) ## Matvec mul!(y::StridedVector{T}, A::Symmetric{T,<:StridedMatrix}, x::StridedVector{T}) where {T<:BlasFloat} = diff --git a/stdlib/LinearAlgebra/test/symmetric.jl b/stdlib/LinearAlgebra/test/symmetric.jl index 9e9814895d7e6..8b62d8badb528 100644 --- a/stdlib/LinearAlgebra/test/symmetric.jl +++ b/stdlib/LinearAlgebra/test/symmetric.jl @@ -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 "getindex and unsafe_getindex" begin