Skip to content

Commit

Permalink
Add more tests for shapes and dual shapes (#3816)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 2, 2024
1 parent 4783914 commit 526a013
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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

0 comments on commit 526a013

Please sign in to comment.