How to use the diffcp.cones.unvec_symm function in diffcp

To help you get started, we’ve selected a few diffcp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cvxgrp / diffcp / tests.py View on Github external
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)
github cvxgrp / diffcp / tests.py View on Github external
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)
github cvxgrp / diffcp / tests.py View on Github external
def test_proj_psd(self):
        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))
github cvxgrp / diffcp / tests.py View on Github external
def test_proj_psd(self):
        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))