array-api-strict 2.3__py3-none-any.whl → 2.4__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/__init__.py +11 -5
- array_api_strict/_array_object.py +226 -200
- array_api_strict/_constants.py +1 -1
- array_api_strict/_creation_functions.py +97 -119
- array_api_strict/_data_type_functions.py +73 -64
- array_api_strict/_dtypes.py +35 -24
- array_api_strict/_elementwise_functions.py +138 -482
- array_api_strict/_fft.py +28 -32
- array_api_strict/_flags.py +65 -26
- array_api_strict/_helpers.py +23 -14
- array_api_strict/_indexing_functions.py +3 -8
- array_api_strict/_info.py +64 -69
- array_api_strict/_linalg.py +57 -53
- array_api_strict/_linear_algebra_functions.py +11 -9
- array_api_strict/_manipulation_functions.py +30 -30
- array_api_strict/_searching_functions.py +22 -33
- array_api_strict/_set_functions.py +4 -6
- array_api_strict/_sorting_functions.py +6 -6
- array_api_strict/_statistical_functions.py +57 -64
- array_api_strict/_typing.py +30 -50
- array_api_strict/_utility_functions.py +11 -13
- array_api_strict/_version.py +2 -2
- array_api_strict/py.typed +0 -0
- array_api_strict/tests/test_array_object.py +163 -56
- array_api_strict/tests/test_creation_functions.py +14 -12
- array_api_strict/tests/test_data_type_functions.py +40 -6
- array_api_strict/tests/test_elementwise_functions.py +94 -45
- array_api_strict/tests/test_searching_functions.py +79 -1
- array_api_strict/tests/test_validation.py +1 -3
- {array_api_strict-2.3.dist-info → array_api_strict-2.4.dist-info}/METADATA +5 -4
- array_api_strict-2.4.dist-info/RECORD +44 -0
- {array_api_strict-2.3.dist-info → array_api_strict-2.4.dist-info}/WHEEL +1 -1
- array_api_strict-2.3.dist-info/RECORD +0 -43
- {array_api_strict-2.3.dist-info → array_api_strict-2.4.dist-info}/LICENSE +0 -0
- {array_api_strict-2.3.dist-info → array_api_strict-2.4.dist-info}/top_level.txt +0 -0
array_api_strict/_dtypes.py
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
+
import builtins
|
|
1
2
|
import warnings
|
|
3
|
+
from typing import Any, Final
|
|
2
4
|
|
|
3
5
|
import numpy as np
|
|
6
|
+
import numpy.typing as npt
|
|
4
7
|
|
|
5
8
|
# Note: we wrap the NumPy dtype objects in a bare class, so that none of the
|
|
6
9
|
# additional methods and behaviors of NumPy dtype objects are exposed.
|
|
7
10
|
|
|
8
|
-
class _DType:
|
|
9
|
-
def __init__(self, np_dtype):
|
|
10
|
-
np_dtype = np.dtype(np_dtype)
|
|
11
|
-
self._np_dtype = np_dtype
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
class DType:
|
|
13
|
+
_np_dtype: Final[np.dtype[Any]]
|
|
14
|
+
__slots__ = ("_np_dtype", "__weakref__")
|
|
15
|
+
|
|
16
|
+
def __init__(self, np_dtype: npt.DTypeLike):
|
|
17
|
+
self._np_dtype = np.dtype(np_dtype)
|
|
18
|
+
|
|
19
|
+
def __repr__(self) -> str:
|
|
14
20
|
return f"array_api_strict.{self._np_dtype.name}"
|
|
15
21
|
|
|
16
|
-
def __eq__(self, other):
|
|
22
|
+
def __eq__(self, other: object) -> builtins.bool:
|
|
17
23
|
# See https://github.com/numpy/numpy/pull/25370/files#r1423259515.
|
|
18
24
|
# Avoid the user error of array_api_strict.float32 == numpy.float32,
|
|
19
25
|
# which gives False. Making == error is probably too egregious, so
|
|
@@ -26,12 +32,13 @@ class _DType:
|
|
|
26
32
|
a NumPy native dtype object, but you probably don't want to do this. \
|
|
27
33
|
array_api_strict dtype objects compare unequal to their NumPy equivalents. \
|
|
28
34
|
Such cross-library comparison is not supported by the standard.""",
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
stacklevel=2,
|
|
36
|
+
)
|
|
37
|
+
if not isinstance(other, DType):
|
|
38
|
+
return False
|
|
32
39
|
return self._np_dtype == other._np_dtype
|
|
33
40
|
|
|
34
|
-
def __hash__(self):
|
|
41
|
+
def __hash__(self) -> int:
|
|
35
42
|
# Note: this is not strictly required
|
|
36
43
|
# (https://github.com/data-apis/array-api/issues/582), but makes the
|
|
37
44
|
# dtype objects much easier to work with here and elsewhere if they
|
|
@@ -39,20 +46,24 @@ Such cross-library comparison is not supported by the standard.""",
|
|
|
39
46
|
return hash(self._np_dtype)
|
|
40
47
|
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
def _np_dtype(dtype: DType | None) -> np.dtype[Any] | None:
|
|
50
|
+
return dtype._np_dtype if dtype is not None else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
int8 = DType("int8")
|
|
54
|
+
int16 = DType("int16")
|
|
55
|
+
int32 = DType("int32")
|
|
56
|
+
int64 = DType("int64")
|
|
57
|
+
uint8 = DType("uint8")
|
|
58
|
+
uint16 = DType("uint16")
|
|
59
|
+
uint32 = DType("uint32")
|
|
60
|
+
uint64 = DType("uint64")
|
|
61
|
+
float32 = DType("float32")
|
|
62
|
+
float64 = DType("float64")
|
|
63
|
+
complex64 = DType("complex64")
|
|
64
|
+
complex128 = DType("complex128")
|
|
54
65
|
# Note: This name is changed
|
|
55
|
-
bool =
|
|
66
|
+
bool = DType("bool")
|
|
56
67
|
|
|
57
68
|
_all_dtypes = (
|
|
58
69
|
int8,
|
|
@@ -212,7 +223,7 @@ _promotion_table = {
|
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
|
|
215
|
-
def _result_type(type1, type2):
|
|
226
|
+
def _result_type(type1: DType, type2: DType) -> DType:
|
|
216
227
|
if (type1, type2) in _promotion_table:
|
|
217
228
|
return _promotion_table[type1, type2]
|
|
218
229
|
raise TypeError(f"{type1} and {type2} cannot be type promoted together")
|