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

Add more tests for shapes and dual shapes #3816

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Changes from 2 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
39 changes: 39 additions & 0 deletions test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2118,4 +2118,43 @@ function test_issue_3812()
return
end

function _test_shape(primal, dual, con::VectorConstraint)
vec_primal = vectorize(primal, con.shape)
vec_dual = vectorize(dual, dual_shape(con.shape))
@test primal == reshape_vector(vec_primal, con.shape)
@test dual == reshape_vector(vec_dual, dual_shape(con.shape))
moi_dot = MOI.Utilities.set_dot(vec_primal, vec_dual, con.set)
@test LinearAlgebra.dot(primal, dual) == moi_dot
return
end

function test_symmetric_adjoint_shape()
model = Model()
@variable(model, x[1:2, 1:2], Symmetric)
c = @constraint(model, x == LinearAlgebra.Symmetric([1 2; 2 3]))
_test_shape([1 2; 2 3], [1 1; 1 1], constraint_object(c))
return
end

function test_symmetric_shape()
model = Model()
@variable(model, x[1:2, 1:2], PSD)
c = @constraint(model, x == LinearAlgebra.Symmetric([1 2; 2 3]))
_test_shape([1 2; 2 3], [1 1; 1 1], constraint_object(c))
return
end

function test_hermitian_shape()
model = Model()
@variable(model, x[1:2, 1:2], Hermitian)
c = @constraint(model, x == LinearAlgebra.Symmetric([1 2; 2 3]))
_test_shape([1 2; 2 3], [2 4; 4 6], constraint_object(c))
model = Model()
@variable(model, x[1:2, 1:2], Hermitian)
primal = [1 2+4im; 2-4im 3]
d = @constraint(model, x == LinearAlgebra.Hermitian(primal))
_test_shape(primal, [2 4+8im; 4-8im 6], constraint_object(d))
return
end

end # module
Loading