Skip to content

Commit 405b7e7

Browse files
committed
Add conversion to NumPy test
The default device should continue to convert, but other arrays from other devices should error.
1 parent 23f390e commit 405b7e7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

array_api_strict/tests/test_array_object.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,17 @@ def test___array__():
349349
assert np.all(np.equal(b, np.ones((2, 3), dtype=np.float64)))
350350
assert b.dtype == np.float64
351351

352+
def test_array_conversion():
353+
# Check that arrays on the CPU device can be converted to NumPy
354+
# but arrays on other devices can't
355+
a = ones((2, 3))
356+
np.asarray(a)
357+
358+
for device in ("device1", "device2"):
359+
a = ones((2, 3), device=array_api_strict.Device(device))
360+
with pytest.raises(RuntimeError, match="Can not convert array"):
361+
np.asarray(a)
362+
352363
def test_allow_newaxis():
353364
a = ones(5)
354365
indexed_a = a[None, :]

0 commit comments

Comments
 (0)