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
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
14 changes: 14 additions & 0 deletions docs/src/developers/checklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,17 @@ Use the following checklist when adding a new solver to the JuMP documentation.

- [ ] Add package metadata to `docs/packages.toml`
````

## Adding a new shape

Use the following checklist when adding a new `AbstractShape`

````
## Basic

- [ ] Add a new subtype of `AbstractShape`
- [ ] Implement `vectorize(data, ::NewShape)::Vector`
- [ ] Implement `reshape_vector(vector, ::NewShape)`
- [ ] Implement `dual_shape`, or verify that the shape is self-dual
- [ ] Add the tests from https://github.com/jump-dev/JuMP.jl/pull/3816
````
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