Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring for hermitian check #3296

Merged
merged 1 commit into from
Mar 23, 2023
Merged
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
21 changes: 7 additions & 14 deletions src/sd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,6 @@ function build_variable(
variables::Matrix{<:AbstractVariable},
::HermitianMatrixSpace,
)
if any(_is_binary, variables) || any(_is_integer, variables)
# We would then need to fix the imaginary value to zero. Let's wait to
# see if there is need for such complication first.
_error(
"Binary or integer variables in a Hermitian matrix are not supported.",
)
end
n = _square_side(_error, variables)
set = MOI.Reals(
MOI.dimension(MOI.HermitianPositiveSemidefiniteConeTriangle(n)),
Expand Down Expand Up @@ -613,6 +606,13 @@ function reshape_vector(v::Vector{T}, shape::HermitianMatrixShape) where {T}
end

function _vectorize_complex_variables(_error::Function, matrix::Matrix)
if any(_is_binary, matrix) || any(_is_integer, matrix)
# We would then need to fix the imaginary value to zero. Let's wait to
# see if there is need for such complication first.
_error(
"Binary or integer variables in a Hermitian matrix are not supported.",
)
end
n = LinearAlgebra.checksquare(matrix)
for j in 1:n
if !_isreal(matrix[j, j])
Expand All @@ -639,13 +639,6 @@ function build_variable(
n = _square_side(_error, variables)
set = MOI.HermitianPositiveSemidefiniteConeTriangle(n)
shape = HermitianMatrixShape(n)
if any(_is_binary, variables) || any(_is_integer, variables)
# We would then need to fix the imaginary value to zero. Let's wait to
# see if there is need for such complication first.
_error(
"Binary or integer variables in a Hermitian matrix is not supported.",
)
end
return VariablesConstrainedOnCreation(
_vectorize_complex_variables(_error, variables),
set,
Expand Down