Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
A, b, c, cone_dims = utils.least_squares_eq_scs_data(m, n)
cone_dims.pop("q")
cone_dims.pop("s")
cone_dims.pop("ep")
x, y, s, derivative, adjoint_derivative = cone_prog.solve_and_derivative(
A, b, c, cone_dims, solver="ECOS")
# check optimality conditions
np.testing.assert_allclose(A @ x + s, b, atol=1e-8)
np.testing.assert_allclose(A.T @ y + c, 0, atol=1e-8)
np.testing.assert_allclose(s @ y, 0, atol=1e-8)
np.testing.assert_allclose(s, cone_lib.pi(
s, cone_lib.parse_cone_dict(cone_dims), dual=False), atol=1e-8)
np.testing.assert_allclose(y, cone_lib.pi(
y, cone_lib.parse_cone_dict(cone_dims), dual=True), atol=1e-8)
x = cp.Variable(10)
prob = cp.Problem(cp.Minimize(cp.sum_squares(np.random.randn(5, 10) @ x) + np.random.randn(10) @ x), [cp.norm2(x) <= 1, np.random.randn(2, 10) @ x == np.random.randn(2)])
A, b, c, cone_dims = utils.scs_data_from_cvxpy_problem(prob)
x, y, s, derivative, adjoint_derivative = cone_prog.solve_and_derivative(
A, b, c, cone_dims, solver="ECOS")
# check optimality conditions
np.testing.assert_allclose(A @ x + s, b, atol=1e-8)
np.testing.assert_allclose(A.T @ y + c, 0, atol=1e-8)
np.testing.assert_allclose(s @ y, 0, atol=1e-8)
np.testing.assert_allclose(s, cone_lib.pi(
s, cone_lib.parse_cone_dict(cone_dims), dual=False), atol=1e-8)
np.testing.assert_allclose(y, cone_lib.pi(
y, cone_lib.parse_cone_dict(cone_dims), dual=True), atol=1e-8)
s, cone_lib.parse_cone_dict(cone_dims), dual=False), atol=1e-8)
np.testing.assert_allclose(y, cone_lib.pi(
y, cone_lib.parse_cone_dict(cone_dims), dual=True), atol=1e-8)
x = cp.Variable(10)
prob = cp.Problem(cp.Minimize(cp.sum_squares(np.random.randn(5, 10) @ x) + np.random.randn(10) @ x), [cp.norm2(x) <= 1, np.random.randn(2, 10) @ x == np.random.randn(2)])
A, b, c, cone_dims = utils.scs_data_from_cvxpy_problem(prob)
x, y, s, derivative, adjoint_derivative = cone_prog.solve_and_derivative(
A, b, c, cone_dims, solver="ECOS")
# check optimality conditions
np.testing.assert_allclose(A @ x + s, b, atol=1e-8)
np.testing.assert_allclose(A.T @ y + c, 0, atol=1e-8)
np.testing.assert_allclose(s @ y, 0, atol=1e-8)
np.testing.assert_allclose(s, cone_lib.pi(
s, cone_lib.parse_cone_dict(cone_dims), dual=False), atol=1e-8)
np.testing.assert_allclose(y, cone_lib.pi(
y, cone_lib.parse_cone_dict(cone_dims), dual=True), atol=1e-8)
elif status != "Solved":
if raise_on_error:
raise SolverError("Solver scs returned status %s" % status)
else:
result["D"] = None
result["DT"] = None
return result
x = result["x"]
y = result["y"]
s = result["s"]
# pre-compute quantities for the derivative
m, n = A.shape
N = m + n + 1
cones = cone_lib.parse_cone_dict(cone_dict)
cones_parsed = cone_lib.parse_cone_dict_cpp(cones)
z = (x, y - s, np.array([1]))
u, v, w = z
Q = sparse.bmat([
[None, A.T, np.expand_dims(c, - 1)],
[-A, None, np.expand_dims(b, -1)],
[-np.expand_dims(c, -1).T, -np.expand_dims(b, -1).T, None]
])
D_proj_dual_cone = _diffcp.dprojection(v, cones_parsed, True)
if mode == "dense":
Q_dense = Q.todense()
M = _diffcp.M_dense(Q_dense, cones_parsed, u, v, w)
MT = M.T
else: