diff options
author | M. Eric Irrgang <ericirrgang@gmail.com> | 2022-07-16 15:27:38 -0500 |
---|---|---|
committer | M. Eric Irrgang <ericirrgang@gmail.com> | 2022-07-16 15:27:38 -0500 |
commit | 81b97607339ac68b27cf72ba7923345d58e2895e (patch) | |
tree | a3d42aa85aedf7f76cababa00ca65a82ca83b19e /numpy/array_api/tests/test_asarray.py | |
parent | 45281b8a0f88b39b9444032578559a25e62763ec (diff) | |
download | numpy-81b97607339ac68b27cf72ba7923345d58e2895e.tar.gz |
Add unit testing.
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 |