Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,18 @@ function build_constraint(
)
end

function build_constraint(
_error::Function,
Q::AbstractMatrix{<:AbstractJuMPScalar},
cone::HermitianPSDCone,
)
return _error(
"Unable to add matrix in HermitianPSDCone because the matrix is " *
"not a subtype of `LinearAlgebra.Hermitian`. To fix, wrap the matrix " *
"`H` in `LinearAlgebra.Hermitian(H)`.",
)
end

function build_constraint(_error::Function, H::LinearAlgebra.Hermitian, ::Zeros)
n = LinearAlgebra.checksquare(H)
shape = HermitianMatrixShape(n)
Expand Down
23 changes: 21 additions & 2 deletions test/test_complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using JuMP
using Test

import LinearAlgebra
import MutableArithmetics
import MutableArithmetics as MA
import SparseArrays

const MA = MutableArithmetics
include(joinpath(@__DIR__, "utilities.jl"))

function _test_dot(a, b)
@test LinearAlgebra.dot(a, b) == conj(a) * b
Expand Down Expand Up @@ -273,4 +273,23 @@ function test_isreal()
return
end

function test_HermitianPSDCone_general_matrix_error()
model = Model()
@variable(model, X[1:2, 1:2] in HermitianPSDCone())
@variable(model, t)
Y = X + LinearAlgebra.I(2) * t
@test LinearAlgebra.ishermitian(Y)
@test !(Y isa LinearAlgebra.Hermitian)
@test_throws_strip(
ErrorException(
"In `@constraint(model, Y in HermitianPSDCone())`: " *
"Unable to add matrix in HermitianPSDCone because the matrix is " *
"not a subtype of `LinearAlgebra.Hermitian`. To fix, wrap the " *
"matrix `H` in `LinearAlgebra.Hermitian(H)`.",
),
@constraint(model, Y in HermitianPSDCone()),
)
return
end

end