summaryrefslogtreecommitdiff
path: root/numpy/array_api/tests
diff options
context:
space:
mode:
authorDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
committerDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
commit9fe353e048bc317099bb13cae4cb5a4de8c0c656 (patch)
tree4976e4328da9906d99cd2478547ca1e2829e071d /numpy/array_api/tests
parent66ca468b97873c1c8bfe69bddac6df633780c71c (diff)
parent5e9ce0c0529e3085498ac892941a020a65c7369a (diff)
downloadnumpy-9fe353e048bc317099bb13cae4cb5a4de8c0c656.tar.gz
Merge branch 'as_min_max' of https://github.com/Developer-Ecosystem-Engineering/numpy into as_min_max
Diffstat (limited to 'numpy/array_api/tests')
-rw-r--r--numpy/array_api/tests/test_array_object.py28
-rw-r--r--numpy/array_api/tests/test_creation_functions.py39
2 files changed, 42 insertions, 25 deletions
diff --git a/numpy/array_api/tests/test_array_object.py b/numpy/array_api/tests/test_array_object.py
index 7959f92b4..12479d765 100644
--- a/numpy/array_api/tests/test_array_object.py
+++ b/numpy/array_api/tests/test_array_object.py
@@ -3,7 +3,7 @@ import operator
from numpy.testing import assert_raises
import numpy as np
-from .. import ones, asarray, result_type
+from .. import ones, asarray, result_type, all, equal
from .._dtypes import (
_all_dtypes,
_boolean_dtypes,
@@ -39,18 +39,18 @@ def test_validate_index():
assert_raises(IndexError, lambda: a[:-4])
assert_raises(IndexError, lambda: a[:3:-1])
assert_raises(IndexError, lambda: a[:-5:-1])
- assert_raises(IndexError, lambda: a[3:])
+ assert_raises(IndexError, lambda: a[4:])
assert_raises(IndexError, lambda: a[-4:])
- assert_raises(IndexError, lambda: a[3::-1])
+ assert_raises(IndexError, lambda: a[4::-1])
assert_raises(IndexError, lambda: a[-4::-1])
assert_raises(IndexError, lambda: a[...,:5])
assert_raises(IndexError, lambda: a[...,:-5])
- assert_raises(IndexError, lambda: a[...,:4:-1])
+ assert_raises(IndexError, lambda: a[...,:5:-1])
assert_raises(IndexError, lambda: a[...,:-6:-1])
- assert_raises(IndexError, lambda: a[...,4:])
+ assert_raises(IndexError, lambda: a[...,5:])
assert_raises(IndexError, lambda: a[...,-5:])
- assert_raises(IndexError, lambda: a[...,4::-1])
+ assert_raises(IndexError, lambda: a[...,5::-1])
assert_raises(IndexError, lambda: a[...,-5::-1])
# Boolean indices cannot be part of a larger tuple index
@@ -74,6 +74,11 @@ def test_validate_index():
assert_raises(IndexError, lambda: a[None, ...])
assert_raises(IndexError, lambda: a[..., None])
+ # Multiaxis indices must contain exactly as many indices as dimensions
+ assert_raises(IndexError, lambda: a[()])
+ assert_raises(IndexError, lambda: a[0,])
+ assert_raises(IndexError, lambda: a[0])
+ assert_raises(IndexError, lambda: a[:])
def test_operators():
# For every operator, we test that it works for the required type
@@ -285,3 +290,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 all(equal(a.to_device('cpu'), a))
+ assert_raises(ValueError, lambda: a.to_device('gpu'))
+
+ assert all(equal(asarray(a, device='cpu'), a))
+ assert_raises(ValueError, lambda: asarray(a, device='gpu'))
diff --git a/numpy/array_api/tests/test_creation_functions.py b/numpy/array_api/tests/test_creation_functions.py
index 3cb8865cd..be9eaa383 100644
--- a/numpy/array_api/tests/test_creation_functions.py
+++ b/numpy/array_api/tests/test_creation_functions.py
@@ -8,7 +8,6 @@ from .._creation_functions import (
empty,
empty_like,
eye,
- from_dlpack,
full,
full_like,
linspace,
@@ -18,20 +17,8 @@ from .._creation_functions import (
zeros,
zeros_like,
)
+from .._dtypes import float32, float64
from .._array_object import Array
-from .._dtypes import (
- _all_dtypes,
- _boolean_dtypes,
- _floating_dtypes,
- _integer_dtypes,
- _integer_or_boolean_dtypes,
- _numeric_dtypes,
- int8,
- int16,
- int32,
- int64,
- uint64,
-)
def test_asarray_errors():
@@ -56,12 +43,18 @@ def test_asarray_copy():
a[0] = 0
assert all(b[0] == 1)
assert all(a[0] == 0)
- # Once copy=False is implemented, replace this with
- # a = asarray([1])
- # b = asarray(a, copy=False)
- # a[0] = 0
- # assert all(b[0] == 0)
+ a = asarray([1])
+ b = asarray(a, copy=np._CopyMode.ALWAYS)
+ a[0] = 0
+ assert all(b[0] == 1)
+ assert all(a[0] == 0)
+ a = asarray([1])
+ b = asarray(a, copy=np._CopyMode.NEVER)
+ a[0] = 0
+ assert all(b[0] == 0)
assert_raises(NotImplementedError, lambda: asarray(a, copy=False))
+ assert_raises(NotImplementedError,
+ lambda: asarray(a, copy=np._CopyMode.IF_NEEDED))
def test_arange_errors():
@@ -139,3 +132,11 @@ def test_zeros_like_errors():
assert_raises(ValueError, lambda: zeros_like(asarray(1), device="gpu"))
assert_raises(ValueError, lambda: zeros_like(asarray(1), dtype=int))
assert_raises(ValueError, lambda: zeros_like(asarray(1), dtype="i"))
+
+def test_meshgrid_dtype_errors():
+ # Doesn't raise
+ meshgrid()
+ meshgrid(asarray([1.], dtype=float32))
+ meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float32))
+
+ assert_raises(ValueError, lambda: meshgrid(asarray([1.], dtype=float32), asarray([1.], dtype=float64)))