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

Method test_get_variable_tensor

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

Source from the content-addressed store, hash-verified

2857 return backend
2858
2859 def test_get_variable_tensor(self, scipy_backend):
2860 outer = scipy_backend.get_variable_tensor((2,), 1)
2861 assert outer.keys() == {1}, "Should only be in variable with ID 1"
2862 inner = outer[1]
2863 assert inner.keys() == {-1}, "Should only be in parameter slice -1, i.e. non parametrized."
2864 tensor = inner[-1]
2865 assert sp.issparse(tensor), "Should be a scipy sparse matrix or array"
2866 assert tensor.shape == (2, 2), "Should be a 1*2x2 tensor"
2867 assert np.all(tensor == np.eye(2)), "Should be eye(2)"
2868
2869 @pytest.mark.parametrize("data", [np.array([[1, 2], [3, 4]]), sp.eye_array(2) * 4])
2870 def test_get_data_tensor(self, scipy_backend, data):

Callers

nothing calls this directly

Calls 3

keysMethod · 0.80
get_variable_tensorMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected