forked from cvxpy/cvxpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William Zijie Zhang
authored and
William Zijie Zhang
committed
Aug 7, 2024
1 parent
ad53ec7
commit 652e453
Showing
2 changed files
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
|
||
import cvxpy as cp | ||
from cvxpy.constraints.psd import PSD | ||
from cvxpy.reductions.cvx_attr2constr import CvxAttr2Constr | ||
|
||
|
||
class Test_Attributes(): | ||
|
||
def test_multiple_attributes(self) -> None: | ||
x = cp.Variable(shape=(2,2), symmetric=True, nonneg=True, integer=True) | ||
target = np.array(np.eye(2) * 5) | ||
prob = cp.Problem(cp.Minimize(0), [x == target]) | ||
prob.solve() | ||
assert np.allclose(x.value, target) | ||
|
||
def test_nonneg_PSD(self) -> None: | ||
x = cp.Variable(shape=(2,2), PSD=True, nonneg=True) | ||
target = np.array(np.eye(2) * 5) | ||
prob = cp.Problem(cp.Minimize(0), [x == target]) | ||
prob.solve() | ||
assert np.allclose(x.value, target) | ||
|
||
def test_nonneg_NSD(self) -> None: | ||
x = cp.Variable(shape=(2,2), NSD=True, nonpos=True) | ||
target = np.array(np.eye(2) * 5) | ||
prob = cp.Problem(cp.Minimize(0), [x == -target]) | ||
|
||
new_prob = CvxAttr2Constr(prob) | ||
assert type(new_prob.apply(prob)[0].constraints[0]) is PSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters