Skip to content

Commit 704235b

Browse files
authored
Fix LinearAlgebra.issymmetric(::AbstractJuMPScalar) (#3997)
1 parent 63336f9 commit 704235b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/JuMP.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,13 +1207,19 @@ Base.eltype(::Type{T}) where {T<:AbstractJuMPScalar} = T
12071207

12081208
# These are required to create symmetric containers of AbstractJuMPScalars.
12091209
LinearAlgebra.symmetric_type(::Type{T}) where {T<:AbstractJuMPScalar} = T
1210-
LinearAlgebra.hermitian_type(::Type{T}) where {T<:AbstractJuMPScalar} = T
1210+
12111211
LinearAlgebra.symmetric(scalar::AbstractJuMPScalar, ::Symbol) = scalar
12121212

1213+
LinearAlgebra.issymmetric(::AbstractJuMPScalar) = true
1214+
1215+
LinearAlgebra.hermitian_type(::Type{T}) where {T<:AbstractJuMPScalar} = T
1216+
12131217
function LinearAlgebra.hermitian(x::F, ::Symbol) where {F<:AbstractJuMPScalar}
12141218
return convert(F, real(x))
12151219
end
12161220

1221+
LinearAlgebra.ishermitian(x::AbstractJuMPScalar) = isreal(x)
1222+
12171223
LinearAlgebra.adjoint(scalar::AbstractJuMPScalar) = conj(scalar)
12181224

12191225
Base.iterate(x::AbstractJuMPScalar) = (x, true)

test/test_operator.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,23 @@ function test_is_symmetric()
739739
@test !LinearAlgebra.issymmetric([x[1] x[2]; x[3] x[3]])
740740
@test !LinearAlgebra.issymmetric([x[1] x[2]])
741741
@test LinearAlgebra.issymmetric([x[1] x[2]; x[2] x[3]])
742+
@test LinearAlgebra.issymmetric(x[1])
743+
@test LinearAlgebra.issymmetric(1.0 * x[1] + 2.0)
744+
@test LinearAlgebra.issymmetric(x[1] * x[1])
745+
@test LinearAlgebra.issymmetric(log(x[1]))
742746
return
743747
end
744748

749+
function test_is_hermitian()
750+
model = Model()
751+
@variable(model, x)
752+
@test LinearAlgebra.ishermitian(x)
753+
@test LinearAlgebra.ishermitian(1.0 * x + 2.0)
754+
@test LinearAlgebra.ishermitian(x^2)
755+
@test LinearAlgebra.ishermitian(log(x))
756+
@test !LinearAlgebra.ishermitian(2.0 * im * x)
757+
@test !LinearAlgebra.ishermitian(2.0 * im * x * x)
758+
return
745759
end
760+
761+
end # module

0 commit comments

Comments
 (0)