array-api-strict 2.1.1__py3-none-any.whl → 2.1.2__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.
@@ -16,6 +16,12 @@ consuming libraries to test their array API usage.
16
16
 
17
17
  """
18
18
 
19
+ import numpy as np
20
+ from numpy.lib import NumpyVersion
21
+
22
+ if NumpyVersion(np.__version__) < NumpyVersion('2.1.0'):
23
+ raise ImportError("array-api-strict requires NumPy >= 2.1.0")
24
+
19
25
  __all__ = []
20
26
 
21
27
  # Warning: __array_api_version__ could change globally with
@@ -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, Device, Dtype
41
+ from ._typing import PyCapsule, Dtype
42
42
  import numpy.typing as npt
43
43
 
44
44
  import numpy as np
@@ -162,19 +162,7 @@ class Array:
162
162
  if _allow_array:
163
163
  if self._device != CPU_DEVICE:
164
164
  raise RuntimeError(f"Can not convert array on the '{self._device}' device to a Numpy array.")
165
- # copy keyword is new in 2.0.0; for older versions don't use it
166
- # retry without that keyword.
167
- if np.__version__[0] < '2':
168
- return np.asarray(self._array, dtype=dtype)
169
- elif np.__version__.startswith('2.0.0-dev0'):
170
- # Handle dev version for which we can't know based on version
171
- # number whether or not the copy keyword is supported.
172
- try:
173
- return np.asarray(self._array, dtype=dtype, copy=copy)
174
- except TypeError:
175
- return np.asarray(self._array, dtype=dtype)
176
- else:
177
- return np.asarray(self._array, dtype=dtype, copy=copy)
165
+ return np.asarray(self._array, dtype=dtype, copy=copy)
178
166
  raise ValueError("Conversion from an array_api_strict array to a NumPy ndarray is not supported")
179
167
 
180
168
  # These are various helper functions to make the array behavior match the
@@ -586,15 +574,14 @@ class Array:
586
574
  if copy is not _default:
587
575
  raise ValueError("The copy argument to __dlpack__ requires at least version 2023.12 of the array API")
588
576
 
589
- # Going to wait for upstream numpy support
590
- if max_version not in [_default, None]:
591
- raise NotImplementedError("The max_version argument to __dlpack__ is not yet implemented")
592
- if dl_device not in [_default, None]:
593
- raise NotImplementedError("The device argument to __dlpack__ is not yet implemented")
594
- if copy not in [_default, None]:
595
- raise NotImplementedError("The copy argument to __dlpack__ is not yet implemented")
596
-
597
- return self._array.__dlpack__(stream=stream)
577
+ kwargs = {'stream': stream}
578
+ if max_version is not _default:
579
+ kwargs['max_version'] = max_version
580
+ if dl_device is not _default:
581
+ kwargs['dl_device'] = dl_device
582
+ if copy is not _default:
583
+ kwargs['copy'] = copy
584
+ return self._array.__dlpack__(**kwargs)
598
585
 
599
586
  def __dlpack_device__(self: Array, /) -> Tuple[IntEnum, int]:
600
587
  """
@@ -83,29 +83,6 @@ def asarray(
83
83
  if isinstance(obj, Array) and device is None:
84
84
  device = obj.device
85
85
 
86
- if np.__version__[0] < '2':
87
- if copy is False:
88
- # Note: copy=False is not yet implemented in np.asarray for
89
- # NumPy 1
90
-
91
- # Work around it by creating the new array and seeing if NumPy
92
- # copies it.
93
- if isinstance(obj, Array):
94
- new_array = np.array(obj._array, copy=copy, dtype=_np_dtype)
95
- if new_array is not obj._array:
96
- raise ValueError("Unable to avoid copy while creating an array from given array.")
97
- return Array._new(new_array, device=device)
98
- elif _supports_buffer_protocol(obj):
99
- # Buffer protocol will always support no-copy
100
- return Array._new(np.array(obj, copy=copy, dtype=_np_dtype), device=device)
101
- else:
102
- # No-copy is unsupported for Python built-in types.
103
- raise ValueError("Unable to avoid copy while creating an array from given object.")
104
-
105
- if copy is None:
106
- # NumPy 1 treats copy=False the same as the standard copy=None
107
- copy = False
108
-
109
86
  if isinstance(obj, Array):
110
87
  return Array._new(np.array(obj._array, copy=copy, dtype=_np_dtype), device=device)
111
88
  if dtype is None and isinstance(obj, int) and (obj > 2 ** 64 or obj < -(2 ** 63)):
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-11-07T13:18:01-0700",
11
+ "date": "2024-11-07T18:09:02-0700",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "6e59494cbfd3ed949cf2009f778fc4cfdfc3eb04",
15
- "version": "2.1.1"
14
+ "full-revisionid": "c9fe697bec8de8e402d8beb71bbeb96ca70c772e",
15
+ "version": "2.1.2"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -456,22 +456,19 @@ def dlpack_2023_12(api_version):
456
456
  set_array_api_strict_flags(api_version=api_version)
457
457
 
458
458
  a = asarray([1, 2, 3], dtype=int8)
459
- # Never an error
460
- a.__dlpack__()
461
-
462
459
 
463
- exception = NotImplementedError if api_version >= '2023.12' else ValueError
464
- pytest.raises(exception, lambda:
465
- a.__dlpack__(dl_device=CPU_DEVICE))
466
- pytest.raises(exception, lambda:
467
- a.__dlpack__(dl_device=None))
468
- pytest.raises(exception, lambda:
469
- a.__dlpack__(max_version=(1, 0)))
470
- pytest.raises(exception, lambda:
471
- a.__dlpack__(max_version=None))
472
- pytest.raises(exception, lambda:
473
- a.__dlpack__(copy=False))
474
- pytest.raises(exception, lambda:
475
- a.__dlpack__(copy=True))
476
- pytest.raises(exception, lambda:
477
- a.__dlpack__(copy=None))
460
+ # Do not error
461
+ a.__dlpack__()
462
+ a.__dlpack__(dl_device=CPU_DEVICE)
463
+ a.__dlpack__(dl_device=None)
464
+ a.__dlpack__(max_version=(1, 0))
465
+ a.__dlpack__(max_version=None)
466
+ a.__dlpack__(copy=False)
467
+ a.__dlpack__(copy=True)
468
+ a.__dlpack__(copy=None)
469
+
470
+ x = np.from_dlpack(a)
471
+ assert isinstance(x, np.ndarray)
472
+ assert x.dtype == np.int8
473
+ assert x.shape == (3,)
474
+ assert np.all(x == np.asarray([1, 2, 3]))
@@ -1,21 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: array_api_strict
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: A strict, minimal implementation of the Python array API standard.
5
5
  Home-page: https://data-apis.org/array-api-strict/
6
6
  Author: Consortium for Python Data API Standards
7
7
  License: MIT
8
8
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.9
10
9
  Classifier: Programming Language :: Python :: 3.10
11
10
  Classifier: Programming Language :: Python :: 3.11
12
11
  Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Intended Audience :: Developers
13
14
  Classifier: License :: OSI Approved :: BSD License
14
15
  Classifier: Operating System :: OS Independent
15
- Requires-Python: >=3.9
16
+ Requires-Python: >=3.10
16
17
  Description-Content-Type: text/markdown
17
18
  License-File: LICENSE
18
- Requires-Dist: numpy
19
+ Requires-Dist: numpy >=2.1
19
20
 
20
21
  # array-api-strict
21
22
 
@@ -1,7 +1,7 @@
1
- array_api_strict/__init__.py,sha256=iQRjMJ4h-MoNqhxYeerCVRPORO6W6KePiQ8xIeecDac,6788
2
- array_api_strict/_array_object.py,sha256=ElW2-ppgMqMTmpqlleKqCg1Fq798D40-y8I17gCJpNQ,51876
1
+ array_api_strict/__init__.py,sha256=BKVX_n63ZyGiX5sod0pPMqESM1ae0nZIJtYBGMKQSps,6967
2
+ array_api_strict/_array_object.py,sha256=l79bhjmLZZpjUWGa_eo_vevCcfeuV7_y4eop4exy3Uo,51011
3
3
  array_api_strict/_constants.py,sha256=AYayN2jf1Dp5rXZ7WPBdUhtPBo_JMCi-pD9oW5zmFkI,87
4
- array_api_strict/_creation_functions.py,sha256=lmLDCAb0aq0naeJbCJ0NgnBRqp6eHs89jnARZhHMgJE,12963
4
+ array_api_strict/_creation_functions.py,sha256=6OCWwE_bXN77vkufSNIXlWd3gLFUQT53NSd3tDffLcs,11867
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=XW_77odg8qbb1HCC9FVKUxmwghy9Dj7x6np6j_akALk,497
21
+ array_api_strict/_version.py,sha256=pdm1CW0Mq5qsnK4lz9UzkaRIItnAetbWP3x598JT1sY,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=r4IpleRQghC-l3B2IhrDadpyxlZB94LZ_X-9JB3jbQg,20250
24
+ array_api_strict/tests/test_array_object.py,sha256=l-PYVbgjRd5O0c7A2ysMmS7jNjsv6pz6-Qd1kP_-DUg,19964
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.1.dist-info/LICENSE,sha256=djDm4UfHAJmycwFUNyUmrTdRkrFF9Ac8uqIlbxH7j5Y,1585
38
- array_api_strict-2.1.1.dist-info/METADATA,sha256=B-jmIvTszl9pwlOp5tY9diRXDLwWQvl7y7XxJzV52yQ,1595
39
- array_api_strict-2.1.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
40
- array_api_strict-2.1.1.dist-info/top_level.txt,sha256=M4cE8VLgRHp_d9TPkbk7_I4JriELFdEJz-NKJJqAkAE,17
41
- array_api_strict-2.1.1.dist-info/RECORD,,
37
+ array_api_strict-2.1.2.dist-info/LICENSE,sha256=djDm4UfHAJmycwFUNyUmrTdRkrFF9Ac8uqIlbxH7j5Y,1585
38
+ array_api_strict-2.1.2.dist-info/METADATA,sha256=I0frr8wfn_ufn0Oz65tfCCcO9ySe3SKiiGLn9xPmY7g,1647
39
+ array_api_strict-2.1.2.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
40
+ array_api_strict-2.1.2.dist-info/top_level.txt,sha256=M4cE8VLgRHp_d9TPkbk7_I4JriELFdEJz-NKJJqAkAE,17
41
+ array_api_strict-2.1.2.dist-info/RECORD,,