MCPcopy
hub / github.com/scikit-learn/scikit-learn / test_move_to_sparse

Function test_move_to_sparse

sklearn/utils/tests/test_array_api.py:171–192  ·  view source on GitHub ↗

Check sparse inputs are handled correctly.

()

Source from the content-addressed store, hash-verified

169
170
171def test_move_to_sparse():
172 """Check sparse inputs are handled correctly."""
173 xp_numpy, _ = _array_api_for_tests("numpy", device_name=None)
174 xp_torch, device = _array_api_for_tests("torch", device_name="cpu")
175
176 sparse1 = sp.csr_array([0, 1, 2, 3])
177 numpy_array = numpy.array([1, 2, 3])
178
179 with config_context(array_api_dispatch=True):
180 device_cpu = device
181
182 # sparse and None to NumPy
183 result1, result2 = move_to(sparse1, None, xp=xp_numpy, device=None)
184 assert result1 is sparse1
185 assert result2 is None
186
187 # sparse to non-NumPy
188 msg = r"Sparse arrays are only accepted \(and passed through\)"
189 with pytest.raises(TypeError, match=msg):
190 move_to(sparse1, numpy_array, xp=xp_torch, device=device_cpu)
191 with pytest.raises(TypeError, match=msg):
192 move_to(sparse1, None, xp=xp_torch, device=device_cpu)
193
194
195@pytest.mark.parametrize("array_api", ["numpy", "array_api_strict"])

Callers

nothing calls this directly

Calls 3

_array_api_for_testsFunction · 0.90
config_contextFunction · 0.90
move_toFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…