Skip to content

Commit e802a92

Browse files
committed
Add release note and further clarify tests.
Original NumPy Commit: b1a8ff8fa73b744416e12cdd4bb70594717b5336
1 parent e2b1032 commit e802a92

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

array_api_strict/tests/test_asarray.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import itertools
2+
13
import numpy as np
24

35

@@ -24,22 +26,39 @@ def test_dtype_identity():
2426
annotated_int_array = np.asarray(int_array, dtype=unequal_type)
2527
assert annotated_int_array is not int_array
2628
assert annotated_int_array.base is int_array
27-
28-
# These ``asarray()`` calls may produce a new view or a copy,
29-
# but never the same object.
30-
long_int_array = np.asarray(int_array, dtype='l')
31-
assert long_int_array is not int_array
32-
assert np.asarray(int_array, dtype='q') is not int_array
33-
assert np.asarray(long_int_array, dtype='q') is not long_int_array
34-
assert long_int_array is not np.asarray(int_array, dtype='l')
35-
assert long_int_array.base is np.asarray(int_array, dtype='l').base
36-
29+
# Create an equivalent descriptor with a new and distinct dtype instance.
3730
equivalent_requirement = np.dtype('i', metadata={'spam': True})
3831
annotated_int_array_alt = np.asarray(annotated_int_array,
3932
dtype=equivalent_requirement)
40-
# The descriptors are equivalent, but we have created
41-
# distinct dtype instances.
4233
assert unequal_type == equivalent_requirement
4334
assert unequal_type is not equivalent_requirement
4435
assert annotated_int_array_alt is not annotated_int_array
4536
assert annotated_int_array_alt.dtype is equivalent_requirement
37+
38+
# Check the same logic for a pair of C types whose equivalence may vary
39+
# between computing environments.
40+
# Find an equivalent pair.
41+
integer_type_codes = ('i', 'l', 'q')
42+
integer_dtypes = [np.dtype(code) for code in integer_type_codes]
43+
typeA = None
44+
typeB = None
45+
for typeA, typeB in itertools.permutations(integer_dtypes, r=2):
46+
if typeA == typeB:
47+
assert typeA is not typeB
48+
break
49+
assert isinstance(typeA, np.dtype) and isinstance(typeB, np.dtype)
50+
51+
# These ``asarray()`` calls may produce a new view or a copy,
52+
# but never the same object.
53+
long_int_array = np.asarray(int_array, dtype='l')
54+
long_long_int_array = np.asarray(int_array, dtype='q')
55+
assert long_int_array is not int_array
56+
assert long_long_int_array is not int_array
57+
assert np.asarray(long_int_array, dtype='q') is not long_int_array
58+
array_a = np.asarray(int_array, dtype=typeA)
59+
assert typeA == typeB
60+
assert typeA is not typeB
61+
assert array_a.dtype is typeA
62+
assert array_a is not np.asarray(array_a, dtype=typeB)
63+
assert np.asarray(array_a, dtype=typeB).dtype is typeB
64+
assert array_a is np.asarray(array_a, dtype=typeB).base

0 commit comments

Comments
 (0)