array-api-strict 2.3__py3-none-any.whl → 2.3.1__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/_helpers.py +1 -1
- array_api_strict/_searching_functions.py +2 -12
- array_api_strict/_version.py +2 -2
- array_api_strict/tests/test_searching_functions.py +21 -1
- {array_api_strict-2.3.dist-info → array_api_strict-2.3.1.dist-info}/METADATA +2 -2
- {array_api_strict-2.3.dist-info → array_api_strict-2.3.1.dist-info}/RECORD +9 -9
- {array_api_strict-2.3.dist-info → array_api_strict-2.3.1.dist-info}/WHEEL +1 -1
- {array_api_strict-2.3.dist-info → array_api_strict-2.3.1.dist-info}/LICENSE +0 -0
- {array_api_strict-2.3.dist-info → array_api_strict-2.3.1.dist-info}/top_level.txt +0 -0
array_api_strict/_helpers.py
CHANGED
|
@@ -31,7 +31,7 @@ def _maybe_normalize_py_scalars(x1, x2, dtype_category, func_name):
|
|
|
31
31
|
x2 = x1._promote_scalar(x2)
|
|
32
32
|
else:
|
|
33
33
|
if x1.dtype not in _allowed_dtypes or x2.dtype not in _allowed_dtypes:
|
|
34
|
-
raise TypeError(f"Only {dtype_category} dtypes are allowed {func_name}. "
|
|
34
|
+
raise TypeError(f"Only {dtype_category} dtypes are allowed in {func_name}(...). "
|
|
35
35
|
f"Got {x1.dtype} and {x2.dtype}.")
|
|
36
36
|
return x1, x2
|
|
37
37
|
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from ._array_object import Array
|
|
4
4
|
from ._dtypes import _result_type, _real_numeric_dtypes, bool as _bool
|
|
5
5
|
from ._flags import requires_data_dependent_shapes, requires_api_version, get_array_api_strict_flags
|
|
6
|
+
from ._helpers import _maybe_normalize_py_scalars
|
|
6
7
|
|
|
7
8
|
from typing import TYPE_CHECKING
|
|
8
9
|
if TYPE_CHECKING:
|
|
@@ -101,18 +102,7 @@ def where(
|
|
|
101
102
|
See its docstring for more information.
|
|
102
103
|
"""
|
|
103
104
|
if get_array_api_strict_flags()['api_version'] > '2023.12':
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if isinstance(x1, (bool, float, complex, int)):
|
|
107
|
-
x1 = Array._new(np.asarray(x1), device=condition.device)
|
|
108
|
-
num_scalars += 1
|
|
109
|
-
|
|
110
|
-
if isinstance(x2, (bool, float, complex, int)):
|
|
111
|
-
x2 = Array._new(np.asarray(x2), device=condition.device)
|
|
112
|
-
num_scalars += 1
|
|
113
|
-
|
|
114
|
-
if num_scalars == 2:
|
|
115
|
-
raise ValueError("One of x1, x2 arguments must be an array.")
|
|
105
|
+
x1, x2 = _maybe_normalize_py_scalars(x1, x2, "all", "where")
|
|
116
106
|
|
|
117
107
|
# Call result type here just to raise on disallowed type combinations
|
|
118
108
|
_result_type(x1.dtype, x2.dtype)
|
array_api_strict/_version.py
CHANGED
|
@@ -20,5 +20,25 @@ def test_where_with_scalars():
|
|
|
20
20
|
assert xp.all(x_where == expected)
|
|
21
21
|
|
|
22
22
|
# The spec does not allow both x1 and x2 to be scalars
|
|
23
|
-
with pytest.raises(
|
|
23
|
+
with pytest.raises(TypeError, match="Two scalars"):
|
|
24
24
|
xp.where(x == 1, 42, 44)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_where_mixed_dtypes():
|
|
28
|
+
# https://github.com/data-apis/array-api-strict/issues/131
|
|
29
|
+
x = xp.asarray([1., 2.])
|
|
30
|
+
res = xp.where(x > 1.5, x, 0)
|
|
31
|
+
assert res.dtype == x.dtype
|
|
32
|
+
assert all(res == xp.asarray([0., 2.]))
|
|
33
|
+
|
|
34
|
+
# retry with boolean x1, x2
|
|
35
|
+
c = x > 1.5
|
|
36
|
+
res = xp.where(c, False, c)
|
|
37
|
+
assert all(res == xp.asarray([False, False]))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_where_f32():
|
|
41
|
+
# https://github.com/data-apis/array-api-strict/issues/131#issuecomment-2723016294
|
|
42
|
+
res = xp.where(xp.asarray([True, False]), 1., xp.asarray([2, 2], dtype=xp.float32))
|
|
43
|
+
assert res.dtype == xp.float32
|
|
44
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: array_api_strict
|
|
3
|
-
Version: 2.3
|
|
3
|
+
Version: 2.3.1
|
|
4
4
|
Summary: A strict, minimal implementation of the Python array API standard.
|
|
5
5
|
Author: Consortium for Python Data API Standards
|
|
6
6
|
License: Copyright (c) 2021-2024, NumPy Developers, Consortium for Python Data API Standards
|
|
@@ -7,19 +7,19 @@ array_api_strict/_dtypes.py,sha256=UxX6e2pEBeRrd_V21bdg85Wxr94d1YUq4USrT1I8Ioo,6
|
|
|
7
7
|
array_api_strict/_elementwise_functions.py,sha256=ClJ2aDwPazGW_wvYnGjzBXL-YdgY6ejkU8s_Ev8wif4,23510
|
|
8
8
|
array_api_strict/_fft.py,sha256=qm9xcjKQAxjmNuq6fgkf-49E6OHhLodyHpfPIpoHmxc,10302
|
|
9
9
|
array_api_strict/_flags.py,sha256=m3Q117wbnOmgg4fr4cBuDw5x4VAOUn05pnPrTFAZ5vk,13647
|
|
10
|
-
array_api_strict/_helpers.py,sha256=
|
|
10
|
+
array_api_strict/_helpers.py,sha256=MUUbpaahyweRK-TbSp-mHUn05y-x6hSWg0N4JqBpVqs,1336
|
|
11
11
|
array_api_strict/_indexing_functions.py,sha256=3AqC8Mgi9BakrStlZoIV34d0Au5dMk6qT07TxpvvCGk,1520
|
|
12
12
|
array_api_strict/_info.py,sha256=QvW1PV7dO2oGPWAerG3wJn61QAqjqxx4iHkWPUturI4,4455
|
|
13
13
|
array_api_strict/_linalg.py,sha256=sfmd5fuq2nHy_9kD2QQ23_JbbVZo7LHFgb10qjrr7nw,19846
|
|
14
14
|
array_api_strict/_linear_algebra_functions.py,sha256=FNvaEbiOL4HkHpTtav9OvEFsSrv-6ezaqeajRPALn1Y,3881
|
|
15
15
|
array_api_strict/_manipulation_functions.py,sha256=njyE4GiGsjLL-wNC8Uw4hk9H6bLaEUneyn2DAYB6TDM,6878
|
|
16
|
-
array_api_strict/_searching_functions.py,sha256=
|
|
16
|
+
array_api_strict/_searching_functions.py,sha256=7dxQPuKq8-TV260mxLCBjTMvzF03h0TDvEMdkMcVP-I,4106
|
|
17
17
|
array_api_strict/_set_functions.py,sha256=PZVsxkRQi5Zi104dI2fHZBFqpluOAW0IJzzdJSyajiI,3295
|
|
18
18
|
array_api_strict/_sorting_functions.py,sha256=GG7g2NYCFn2G2fFS6ZdfYOWpuuSIrdZdJWEuL72_-LI,2065
|
|
19
19
|
array_api_strict/_statistical_functions.py,sha256=I_nNZyv4aKRmrJjdsw0PJZCtQ-TgKuMyaBMWbSioTlI,6237
|
|
20
20
|
array_api_strict/_typing.py,sha256=oaHM01VhgC5JIHxXMouEEajNs0OXtwOasnIznK7z9fk,1889
|
|
21
21
|
array_api_strict/_utility_functions.py,sha256=Mu07FogReaAFToPMHE_j90YBEDEvxD5jPcMK3zeUiG0,2007
|
|
22
|
-
array_api_strict/_version.py,sha256=
|
|
22
|
+
array_api_strict/_version.py,sha256=4lLWfgycoQE7rafXKcKQeSzbG6DAo6_kH0qn9J_0diQ,511
|
|
23
23
|
array_api_strict/tests/__init__.py,sha256=t_2GZ3lKcsu4ec4GMKPUDYaeMUJyDquBlQAcPgj7kFE,282
|
|
24
24
|
array_api_strict/tests/conftest.py,sha256=-wIDryl2MdRLdSonU1G1xWssNq2TFKiWuHquNasXYA8,468
|
|
25
25
|
array_api_strict/tests/test_array_object.py,sha256=N84q_642ypibxihmRssWth4eHPs8AbpQrktCbZDipIc,23567
|
|
@@ -31,13 +31,13 @@ array_api_strict/tests/test_flags.py,sha256=kcBbFB4aq3XY_9HM1j3wKmq8MVNfU4YxwK21
|
|
|
31
31
|
array_api_strict/tests/test_indexing_functions.py,sha256=C23FnuowVDC1OBuDH06pvsd61qM2dTpTwzw6UgC4BoY,1281
|
|
32
32
|
array_api_strict/tests/test_linalg.py,sha256=CJ4JnCkWyysMUAih3PI-ZZeOH-X39H0p-RKBoEwk6Jw,5675
|
|
33
33
|
array_api_strict/tests/test_manipulation_functions.py,sha256=Yc92IvA3FaTZueqAUOFMkx3MH4PXCHDof7ckrJxudQs,1078
|
|
34
|
-
array_api_strict/tests/test_searching_functions.py,sha256=
|
|
34
|
+
array_api_strict/tests/test_searching_functions.py,sha256=ivDcpggiQkSdGVqboJmwczj3Zfmgojp86tNWJphxB0k,1352
|
|
35
35
|
array_api_strict/tests/test_set_functions.py,sha256=ikzab1j3SXxGf0OqwHrOAM13HwQetdhtB60Zc_gc1DE,542
|
|
36
36
|
array_api_strict/tests/test_sorting_functions.py,sha256=1xvQBKts5KTKYc-puMITX9iR_KTbzzVB8fY-SObad_Y,899
|
|
37
37
|
array_api_strict/tests/test_statistical_functions.py,sha256=0ihnw4W9vOqU6RMBOUw29Fg-xumXpfz0h05v0E0RsMQ,1814
|
|
38
38
|
array_api_strict/tests/test_validation.py,sha256=Dtl-kGRtdslaPVWWtr3rBrIsJPuj7LZz6_pw2yjwkWE,674
|
|
39
|
-
array_api_strict-2.3.dist-info/LICENSE,sha256=djDm4UfHAJmycwFUNyUmrTdRkrFF9Ac8uqIlbxH7j5Y,1585
|
|
40
|
-
array_api_strict-2.3.dist-info/METADATA,sha256=
|
|
41
|
-
array_api_strict-2.3.dist-info/WHEEL,sha256=
|
|
42
|
-
array_api_strict-2.3.dist-info/top_level.txt,sha256=M4cE8VLgRHp_d9TPkbk7_I4JriELFdEJz-NKJJqAkAE,17
|
|
43
|
-
array_api_strict-2.3.dist-info/RECORD,,
|
|
39
|
+
array_api_strict-2.3.1.dist-info/LICENSE,sha256=djDm4UfHAJmycwFUNyUmrTdRkrFF9Ac8uqIlbxH7j5Y,1585
|
|
40
|
+
array_api_strict-2.3.1.dist-info/METADATA,sha256=VURFsgnmY7crtgcQGW8mXfQzlD_YMZoFXP2WmYokTdI,3425
|
|
41
|
+
array_api_strict-2.3.1.dist-info/WHEEL,sha256=5Mi1sN9lKoFv_gxcPtisEVrJZihrm_beibeg5R6xb4I,91
|
|
42
|
+
array_api_strict-2.3.1.dist-info/top_level.txt,sha256=M4cE8VLgRHp_d9TPkbk7_I4JriELFdEJz-NKJJqAkAE,17
|
|
43
|
+
array_api_strict-2.3.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|