Check sparse inputs are handled correctly.
()
| 169 | |
| 170 | |
| 171 | def 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"]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…