array-api-strict 2.1.1__py3-none-any.whl → 2.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- array_api_strict/_array_object.py +31 -17
- array_api_strict/_creation_functions.py +1 -1
- array_api_strict/_version.py +3 -3
- array_api_strict/tests/test_array_object.py +53 -17
- {array_api_strict-2.1.1.dist-info → array_api_strict-2.1.3.dist-info}/METADATA +1 -1
- {array_api_strict-2.1.1.dist-info → array_api_strict-2.1.3.dist-info}/RECORD +9 -9
- {array_api_strict-2.1.1.dist-info → array_api_strict-2.1.3.dist-info}/LICENSE +0 -0
- {array_api_strict-2.1.1.dist-info → array_api_strict-2.1.3.dist-info}/WHEEL +0 -0
- {array_api_strict-2.1.1.dist-info → array_api_strict-2.1.3.dist-info}/top_level.txt +0 -0
|
@@ -38,7 +38,7 @@ import types
|
|
|
38
38
|
|
|
39
39
|
if TYPE_CHECKING:
|
|
40
40
|
from typing import Optional, Tuple, Union, Any
|
|
41
|
-
from ._typing import PyCapsule,
|
|
41
|
+
from ._typing import PyCapsule, Dtype
|
|
42
42
|
import numpy.typing as npt
|
|
43
43
|
|
|
44
44
|
import numpy as np
|
|
@@ -66,7 +66,9 @@ ALL_DEVICES = (CPU_DEVICE, Device("device1"), Device("device2"))
|
|
|
66
66
|
|
|
67
67
|
_default = object()
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
# See https://github.com/data-apis/array-api-strict/issues/67 and the comment
|
|
70
|
+
# on __array__ below.
|
|
71
|
+
_allow_array = True
|
|
70
72
|
|
|
71
73
|
class Array:
|
|
72
74
|
"""
|
|
@@ -147,15 +149,18 @@ class Array:
|
|
|
147
149
|
mid = np.array2string(self._array, separator=', ', prefix=prefix, suffix=suffix)
|
|
148
150
|
return prefix + mid + suffix
|
|
149
151
|
|
|
150
|
-
#
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# used to do. But this isn't actually supported by the standard, so it can
|
|
152
|
+
# In the future, _allow_array will be set to False, which will disallow
|
|
153
|
+
# __array__. This means calling `np.func()` on an array_api_strict array
|
|
154
|
+
# will give an error. If we don't explicitly disallow it, NumPy defaults
|
|
155
|
+
# to creating an object dtype array, which would lead to confusing error
|
|
156
|
+
# messages at best and surprising bugs at worst. The reason for doing this
|
|
157
|
+
# is that __array__ is not actually supported by the standard, so it can
|
|
157
158
|
# lead to code assuming np.asarray(other_array) would always work in the
|
|
158
159
|
# standard.
|
|
160
|
+
#
|
|
161
|
+
# This was implemented historically for compatibility, and removing it has
|
|
162
|
+
# caused issues for some libraries (see
|
|
163
|
+
# https://github.com/data-apis/array-api-strict/issues/67).
|
|
159
164
|
def __array__(self, dtype: None | np.dtype[Any] = None, copy: None | bool = None) -> npt.NDArray[Any]:
|
|
160
165
|
# We have to allow this to be internally enabled as there's no other
|
|
161
166
|
# easy way to parse a list of Array objects in asarray().
|
|
@@ -586,15 +591,24 @@ class Array:
|
|
|
586
591
|
if copy is not _default:
|
|
587
592
|
raise ValueError("The copy argument to __dlpack__ requires at least version 2023.12 of the array API")
|
|
588
593
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
594
|
+
if np.lib.NumpyVersion(np.__version__) < '2.1.0':
|
|
595
|
+
if max_version not in [_default, None]:
|
|
596
|
+
raise NotImplementedError("The max_version argument to __dlpack__ is not yet implemented")
|
|
597
|
+
if dl_device not in [_default, None]:
|
|
598
|
+
raise NotImplementedError("The device argument to __dlpack__ is not yet implemented")
|
|
599
|
+
if copy not in [_default, None]:
|
|
600
|
+
raise NotImplementedError("The copy argument to __dlpack__ is not yet implemented")
|
|
596
601
|
|
|
597
|
-
|
|
602
|
+
return self._array.__dlpack__(stream=stream)
|
|
603
|
+
else:
|
|
604
|
+
kwargs = {'stream': stream}
|
|
605
|
+
if max_version is not _default:
|
|
606
|
+
kwargs['max_version'] = max_version
|
|
607
|
+
if dl_device is not _default:
|
|
608
|
+
kwargs['dl_device'] = dl_device
|
|
609
|
+
if copy is not _default:
|
|
610
|
+
kwargs['copy'] = copy
|
|
611
|
+
return self._array.__dlpack__(**kwargs)
|
|
598
612
|
|
|
599
613
|
def __dlpack_device__(self: Array, /) -> Tuple[IntEnum, int]:
|
|
600
614
|
"""
|
|
@@ -83,7 +83,7 @@ def asarray(
|
|
|
83
83
|
if isinstance(obj, Array) and device is None:
|
|
84
84
|
device = obj.device
|
|
85
85
|
|
|
86
|
-
if np.__version__
|
|
86
|
+
if np.lib.NumpyVersion(np.__version__) < '2.0.0':
|
|
87
87
|
if copy is False:
|
|
88
88
|
# Note: copy=False is not yet implemented in np.asarray for
|
|
89
89
|
# NumPy 1
|
array_api_strict/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "2024-11-
|
|
11
|
+
"date": "2024-11-08T16:00:41-0700",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "2.1.
|
|
14
|
+
"full-revisionid": "310bb626b04ea61e24feca146440dd4ec1f6cf5b",
|
|
15
|
+
"version": "2.1.3"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -364,6 +364,23 @@ def test_array_conversion():
|
|
|
364
364
|
with pytest.raises(RuntimeError, match="Can not convert array"):
|
|
365
365
|
asarray([a])
|
|
366
366
|
|
|
367
|
+
def test__array__():
|
|
368
|
+
# __array__ should work for now
|
|
369
|
+
a = ones((2, 3))
|
|
370
|
+
np.array(a)
|
|
371
|
+
|
|
372
|
+
# Test the _allow_array private global flag for disabling it in the
|
|
373
|
+
# future.
|
|
374
|
+
from .. import _array_object
|
|
375
|
+
original_value = _array_object._allow_array
|
|
376
|
+
try:
|
|
377
|
+
_array_object._allow_array = False
|
|
378
|
+
a = ones((2, 3))
|
|
379
|
+
with pytest.raises(ValueError, match="Conversion from an array_api_strict array to a NumPy ndarray is not supported"):
|
|
380
|
+
np.array(a)
|
|
381
|
+
finally:
|
|
382
|
+
_array_object._allow_array = original_value
|
|
383
|
+
|
|
367
384
|
def test_allow_newaxis():
|
|
368
385
|
a = ones(5)
|
|
369
386
|
indexed_a = a[None, :]
|
|
@@ -448,7 +465,7 @@ def test_iter():
|
|
|
448
465
|
pytest.raises(TypeError, lambda: iter(ones((3, 3))))
|
|
449
466
|
|
|
450
467
|
@pytest.mark.parametrize("api_version", ['2021.12', '2022.12', '2023.12'])
|
|
451
|
-
def
|
|
468
|
+
def test_dlpack_2023_12(api_version):
|
|
452
469
|
if api_version == '2021.12':
|
|
453
470
|
with pytest.warns(UserWarning):
|
|
454
471
|
set_array_api_strict_flags(api_version=api_version)
|
|
@@ -459,19 +476,38 @@ def dlpack_2023_12(api_version):
|
|
|
459
476
|
# Never an error
|
|
460
477
|
a.__dlpack__()
|
|
461
478
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
479
|
+
if api_version < '2023.12':
|
|
480
|
+
pytest.raises(ValueError, lambda:
|
|
481
|
+
a.__dlpack__(dl_device=a.__dlpack_device__()))
|
|
482
|
+
pytest.raises(ValueError, lambda:
|
|
483
|
+
a.__dlpack__(dl_device=None))
|
|
484
|
+
pytest.raises(ValueError, lambda:
|
|
485
|
+
a.__dlpack__(max_version=(1, 0)))
|
|
486
|
+
pytest.raises(ValueError, lambda:
|
|
487
|
+
a.__dlpack__(max_version=None))
|
|
488
|
+
pytest.raises(ValueError, lambda:
|
|
489
|
+
a.__dlpack__(copy=False))
|
|
490
|
+
pytest.raises(ValueError, lambda:
|
|
491
|
+
a.__dlpack__(copy=True))
|
|
492
|
+
pytest.raises(ValueError, lambda:
|
|
493
|
+
a.__dlpack__(copy=None))
|
|
494
|
+
elif np.lib.NumpyVersion(np.__version__) < '2.1.0':
|
|
495
|
+
pytest.raises(NotImplementedError, lambda:
|
|
496
|
+
a.__dlpack__(dl_device=CPU_DEVICE))
|
|
497
|
+
a.__dlpack__(dl_device=None)
|
|
498
|
+
pytest.raises(NotImplementedError, lambda:
|
|
499
|
+
a.__dlpack__(max_version=(1, 0)))
|
|
500
|
+
a.__dlpack__(max_version=None)
|
|
501
|
+
pytest.raises(NotImplementedError, lambda:
|
|
502
|
+
a.__dlpack__(copy=False))
|
|
503
|
+
pytest.raises(NotImplementedError, lambda:
|
|
504
|
+
a.__dlpack__(copy=True))
|
|
505
|
+
a.__dlpack__(copy=None)
|
|
506
|
+
else:
|
|
507
|
+
a.__dlpack__(dl_device=a.__dlpack_device__())
|
|
508
|
+
a.__dlpack__(dl_device=None)
|
|
509
|
+
a.__dlpack__(max_version=(1, 0))
|
|
510
|
+
a.__dlpack__(max_version=None)
|
|
511
|
+
a.__dlpack__(copy=False)
|
|
512
|
+
a.__dlpack__(copy=True)
|
|
513
|
+
a.__dlpack__(copy=None)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
array_api_strict/__init__.py,sha256=iQRjMJ4h-MoNqhxYeerCVRPORO6W6KePiQ8xIeecDac,6788
|
|
2
|
-
array_api_strict/_array_object.py,sha256=
|
|
2
|
+
array_api_strict/_array_object.py,sha256=Q69HJ8qdQqqugWIRf4RsifZUEypbhNV_y5EVSygmbrQ,52571
|
|
3
3
|
array_api_strict/_constants.py,sha256=AYayN2jf1Dp5rXZ7WPBdUhtPBo_JMCi-pD9oW5zmFkI,87
|
|
4
|
-
array_api_strict/_creation_functions.py,sha256=
|
|
4
|
+
array_api_strict/_creation_functions.py,sha256=A9TTvPSznF9NsxT0Pd_G9yU6IZAfW1tpBkFMYoJyguw,12985
|
|
5
5
|
array_api_strict/_data_type_functions.py,sha256=sKxKRQiwoXPwQJPbiN5BhF9rbc3ZtXfjRuglB7VsIgo,7016
|
|
6
6
|
array_api_strict/_dtypes.py,sha256=QDGo9rqiS_o3quv7QRFM0j6DkvOjRauQ1Ymikwlu8Ns,6213
|
|
7
7
|
array_api_strict/_elementwise_functions.py,sha256=g9YecX4gM4V6UCjl7b7I752EFXhRusjm-EKGZ12jDeI,38651
|
|
@@ -18,10 +18,10 @@ array_api_strict/_sorting_functions.py,sha256=GG7g2NYCFn2G2fFS6ZdfYOWpuuSIrdZdJW
|
|
|
18
18
|
array_api_strict/_statistical_functions.py,sha256=dMJ-x8TQW5MD2rFYCmRH6QthA2KDKXjhkj4hcbd3LSU,5148
|
|
19
19
|
array_api_strict/_typing.py,sha256=TpmU57g3EAPY9PT6hJEhzBduVrwXJUWvmoBlhy5bQuQ,1803
|
|
20
20
|
array_api_strict/_utility_functions.py,sha256=khxtvqPWSDpNp65VgoJUtO4zEfTiGfZZGu_MHwyfmmI,913
|
|
21
|
-
array_api_strict/_version.py,sha256=
|
|
21
|
+
array_api_strict/_version.py,sha256=xJzT1_4sE3FOyJjocQQw38msTHLnEXjUj33S0uEZQ5M,497
|
|
22
22
|
array_api_strict/tests/__init__.py,sha256=t_2GZ3lKcsu4ec4GMKPUDYaeMUJyDquBlQAcPgj7kFE,282
|
|
23
23
|
array_api_strict/tests/conftest.py,sha256=-wIDryl2MdRLdSonU1G1xWssNq2TFKiWuHquNasXYA8,468
|
|
24
|
-
array_api_strict/tests/test_array_object.py,sha256=
|
|
24
|
+
array_api_strict/tests/test_array_object.py,sha256=zzXoGDAHEdK8PBmp9owwoydlcKyIDMHFYg2e9XmjYrU,21685
|
|
25
25
|
array_api_strict/tests/test_creation_functions.py,sha256=ve0MeqZPrG2dmCG3hTVhap1YgIW-lAaSZIJ_ZoOV9cQ,8323
|
|
26
26
|
array_api_strict/tests/test_data_type_functions.py,sha256=pLAtm96gpAduNVqq-914JvjAollzhBp4YojVfNScBzs,2138
|
|
27
27
|
array_api_strict/tests/test_device_support.py,sha256=zpfhHxeRREoXfp0qZTlilm2ZceBc71uCKea1GMVe-ZU,855
|
|
@@ -34,8 +34,8 @@ array_api_strict/tests/test_set_functions.py,sha256=ikzab1j3SXxGf0OqwHrOAM13HwQe
|
|
|
34
34
|
array_api_strict/tests/test_sorting_functions.py,sha256=1xvQBKts5KTKYc-puMITX9iR_KTbzzVB8fY-SObad_Y,899
|
|
35
35
|
array_api_strict/tests/test_statistical_functions.py,sha256=JwS4DhASt5T0YUNtbFK2nSXgDrVVZx1tVpe7LU2aPK4,1365
|
|
36
36
|
array_api_strict/tests/test_validation.py,sha256=JdsK4z1M0U5YoJrfWSzOpEhmlehvZHF5SG0I0k6oDy8,672
|
|
37
|
-
array_api_strict-2.1.
|
|
38
|
-
array_api_strict-2.1.
|
|
39
|
-
array_api_strict-2.1.
|
|
40
|
-
array_api_strict-2.1.
|
|
41
|
-
array_api_strict-2.1.
|
|
37
|
+
array_api_strict-2.1.3.dist-info/LICENSE,sha256=djDm4UfHAJmycwFUNyUmrTdRkrFF9Ac8uqIlbxH7j5Y,1585
|
|
38
|
+
array_api_strict-2.1.3.dist-info/METADATA,sha256=cup_jx9CNgdyj14hC3Nou6-C7w7Lte1AqHZ58Fzc1Ug,1595
|
|
39
|
+
array_api_strict-2.1.3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
40
|
+
array_api_strict-2.1.3.dist-info/top_level.txt,sha256=M4cE8VLgRHp_d9TPkbk7_I4JriELFdEJz-NKJJqAkAE,17
|
|
41
|
+
array_api_strict-2.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|