Skip to content

Commit bc087bb

Browse files
authored
TST: Add a test for device property in array_api namespace (numpy#20271)
1 parent d9c3689 commit bc087bb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

numpy/array_api/tests/test_array_object.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,14 @@ def test_python_scalar_construtors():
285285

286286
assert_raises(TypeError, lambda: operator.index(b))
287287
assert_raises(TypeError, lambda: operator.index(f))
288+
289+
290+
def test_device_property():
291+
a = ones((3, 4))
292+
assert a.device == 'cpu'
293+
294+
assert np.array_equal(a.to_device('cpu'), a)
295+
assert_raises(ValueError, lambda: a.to_device('gpu'))
296+
297+
assert np.array_equal(asarray(a, device='cpu'), a)
298+
assert_raises(ValueError, lambda: asarray(a, device='gpu'))

0 commit comments

Comments
 (0)