MCPcopy Create free account
hub / github.com/cvxpy/cvxpy / test_get_param_tensor

Method test_get_param_tensor

cvxpy/tests/test_python_backends.py:2881–2894  ·  view source on GitHub ↗
(self, scipy_backend)

Source from the content-addressed store, hash-verified

2879 assert (tensor != expected).nnz == 0
2880
2881 def test_get_param_tensor(self, scipy_backend):
2882 shape = (2, 2)
2883 size = np.prod(shape)
2884 scipy_backend.param_to_size = {-1: 1, 3: 4}
2885 outer = scipy_backend.get_param_tensor(shape, 3)
2886 assert outer.keys() == {-1}, "Should only be constant variable ID."
2887 inner = outer[-1]
2888 assert inner.keys() == {3}, "Should only be the parameter slice of parameter with id 3."
2889 tensor = inner[3]
2890 assert sp.issparse(tensor), "Should be scipy sparse"
2891 assert tensor.shape == (16, 1), "Should be a 4*4x1 tensor"
2892 assert (
2893 tensor.reshape((size, size)) != sp.eye_array(size, format="csr")
2894 ).nnz == 0, "Should be eye(4) when reshaping"
2895
2896 def test_tensor_view_add_dicts(self, scipy_backend):
2897 view = scipy_backend.get_empty_view()

Callers

nothing calls this directly

Calls 4

keysMethod · 0.80
prodMethod · 0.45
get_param_tensorMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected