summaryrefslogtreecommitdiff
path: root/numpy/array_api/tests/test_array_object.py
diff options
context:
space:
mode:
authorAmit Kumar <dtu.amit@gmail.com>2021-11-03 11:09:28 +0000
committerGitHub <noreply@github.com>2021-11-03 12:09:28 +0100
commitbc087bb2b3104547b097e03e669fb5fa77b16f05 (patch)
tree3f418c1eedbce154cb8bd36b50835bccdf43c8cf /numpy/array_api/tests/test_array_object.py
parentd9c3689cbe06ad7ebc268123d6bd6e659222bca7 (diff)
downloadnumpy-bc087bb2b3104547b097e03e669fb5fa77b16f05.tar.gz
TST: Add a test for device property in `array_api` namespace (#20271)
Diffstat (limited to 'numpy/array_api/tests/test_array_object.py')
-rw-r--r--numpy/array_api/tests/test_array_object.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/numpy/array_api/tests/test_array_object.py b/numpy/array_api/tests/test_array_object.py
index 7959f92b4..fb42cf621 100644
--- a/numpy/array_api/tests/test_array_object.py
+++ b/numpy/array_api/tests/test_array_object.py
@@ -285,3 +285,14 @@ def test_python_scalar_construtors():
assert_raises(TypeError, lambda: operator.index(b))
assert_raises(TypeError, lambda: operator.index(f))
+
+
+def test_device_property():
+ a = ones((3, 4))
+ assert a.device == 'cpu'
+
+ assert np.array_equal(a.to_device('cpu'), a)
+ assert_raises(ValueError, lambda: a.to_device('gpu'))
+
+ assert np.array_equal(asarray(a, device='cpu'), a)
+ assert_raises(ValueError, lambda: asarray(a, device='gpu'))