How to use the diffcp.cone_program.solve_and_derivative_batch 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
np.random.seed(0)
        m = 20
        n = 10
        As, bs, cs, cone_dicts = [], [], [], []
        results = []

        for _ in range(50):
            A, b, c, cone_dims = utils.least_squares_eq_scs_data(m, n)
            As += [A]
            bs += [b]
            cs += [c]
            cone_dicts += [cone_dims]
            results.append(cone_prog.solve_and_derivative(A, b, c, cone_dims))

        for n_jobs in [1, -1]:
            xs, ys, ss, _, DT_batch = cone_prog.solve_and_derivative_batch(
                As, bs, cs, cone_dicts, n_jobs_forward=n_jobs, n_jobs_backward=n_jobs)

            for i in range(50):
                np.testing.assert_allclose(results[i][0], xs[i])
                np.testing.assert_allclose(results[i][1], ys[i])
                np.testing.assert_allclose(results[i][2], ss[i])

            dAs, dbs, dcs = DT_batch(xs, ys, ss)
            for i in range(50):
                dA, db, dc = results[
                    i][-1](results[i][0], results[i][1], results[i][2])
                np.testing.assert_allclose(dA.todense(), dAs[i].todense())
                np.testing.assert_allclose(dbs[i], db)
                np.testing.assert_allclose(dcs[i], dc)