def test_unvec_symm(self): np.random.seed(0) n = 5 x = np.random.randn(n, n) x = x + x.T np.testing.assert_allclose( cone_lib.unvec_symm(cone_lib.vec_symm(x), n), x)
def test_proj_psd(self): import cvxpy as cp np.random.seed(0) n = 10 for _ in range(15): x = np.random.randn(n, n) x = x + x.T x_vec = cone_lib.vec_symm(x) z = cp.Variable((n, n), PSD=True) objective = cp.Minimize(cp.sum_squares(z - x)) prob = cp.Problem(objective) prob.solve(solver="SCS", eps=1e-10) p = cone_lib.unvec_symm( cone_lib._proj(x_vec, cone_lib.PSD, dual=False), n) np.testing.assert_allclose(p, z.value, atol=1e-5, rtol=1e-5) np.testing.assert_allclose(p, cone_lib.unvec_symm( cone_lib._proj(x_vec, cone_lib.PSD, dual=True), n))
def test_vec_symm(self): np.random.seed(0) n = 5 x = np.random.randn(cone_lib.vec_psd_dim(n)) np.testing.assert_allclose( cone_lib.vec_symm(cone_lib.unvec_symm(x, n)), x)