diff options
Diffstat (limited to 'numpy/array_api/tests/test_asarray.py')
-rw-r--r-- | numpy/array_api/tests/test_asarray.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/numpy/array_api/tests/test_asarray.py b/numpy/array_api/tests/test_asarray.py new file mode 100644 index 000000000..d9bbc675b --- /dev/null +++ b/numpy/array_api/tests/test_asarray.py @@ -0,0 +1,24 @@ +import numpy as np + + +def test_fast_return(): + """""" + a = np.array([1, 2, 3], dtype='i') + assert np.asarray(a) is a + assert np.asarray(a, dtype='i') is a + # This may produce a new view or a copy, but is never the same object. + assert np.asarray(a, dtype='l') is not a + + unequal_type = np.dtype('i', metadata={'spam': True}) + b = np.asarray(a, dtype=unequal_type) + assert b is not a + assert b.base is a + + equivalent_requirement = np.dtype('i', metadata={'spam': True}) + c = np.asarray(b, dtype=equivalent_requirement) + # A quirk of the metadata test is that equivalent metadata dicts are still + # separate objects and so don't evaluate as the same array type description. + assert unequal_type == equivalent_requirement + assert unequal_type is not equivalent_requirement + assert c is not b + assert c.dtype is equivalent_requirement |