array-api-extra 0.10.3__py3-none-any.whl → 0.11.0__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.
@@ -29,7 +29,7 @@ from ._lib._funcs import (
29
29
  )
30
30
  from ._lib._lazy import lazy_apply
31
31
 
32
- __version__ = "0.10.3"
32
+ __version__ = "0.11.0"
33
33
 
34
34
  # pylint: disable=duplicate-code
35
35
  __all__ = [
@@ -15,7 +15,7 @@ from ._lib._utils._compat import (
15
15
  is_torch_namespace,
16
16
  )
17
17
  from ._lib._utils._compat import device as get_device
18
- from ._lib._utils._helpers import asarrays, eager_shape
18
+ from ._lib._utils._helpers import asarrays, deprecated, eager_shape
19
19
  from ._lib._utils._typing import Array, DType
20
20
 
21
21
  __all__ = [
@@ -83,19 +83,23 @@ def atleast_nd(x: Array, /, *, ndim: int, xp: ModuleType | None = None) -> Array
83
83
  return _funcs.atleast_nd(x, ndim=ndim, xp=xp)
84
84
 
85
85
 
86
+ @deprecated(
87
+ "`xpx.broadcast_shapes` is deprecated and will be removed in v1.0.0. "
88
+ "`xp.broadcast_shapes` exists in the standard as of v2025.12."
89
+ )
86
90
  def broadcast_shapes(
87
91
  *shapes: tuple[float | None, ...], xp: ModuleType | None = None
88
92
  ) -> tuple[int | None, ...]:
89
93
  """
90
94
  Compute the shape of the broadcasted arrays.
91
95
 
96
+ .. deprecated:: 0.11.0
97
+ :func:`broadcast_shapes` is deprecated and will be removed in v1.0.0.
98
+ :func:`array_api.broadcast_shapes` exists in the standard as of v2025.12.
99
+
92
100
  Duplicates :func:`numpy.broadcast_shapes`, with additional support for
93
101
  None and NaN sizes.
94
102
 
95
- This is equivalent to ``xp.broadcast_arrays(arr1, arr2, ...)[0].shape``
96
- without needing to worry about the backend potentially deep copying
97
- the arrays.
98
-
99
103
  Parameters
100
104
  ----------
101
105
  *shapes : tuple[int | None, ...]
@@ -300,18 +304,25 @@ def create_diagonal(
300
304
  return _funcs.create_diagonal(x, offset=offset, xp=xp)
301
305
 
302
306
 
307
+ @deprecated(
308
+ "`xpx.expand_dims` is deprecated and will be removed in v1.0.0. "
309
+ "`xp.expand_dims` with support for a tuple of ints in `axis` "
310
+ "exists in the standard as of v2025.12."
311
+ )
303
312
  def expand_dims(
304
313
  a: Array, /, *, axis: int | tuple[int, ...] = (0,), xp: ModuleType | None = None
305
314
  ) -> Array:
306
315
  """
307
316
  Expand the shape of an array.
308
317
 
318
+ .. deprecated:: 0.11.0
319
+ :func:`expand_dims` is deprecated and will be removed in v1.0.0.
320
+ :func:`array_api.expand_dims` with support for a tuple of ints in `axis`
321
+ exists in the standard as of v2025.12.
322
+
309
323
  Insert (a) new axis/axes that will appear at the position(s) specified by
310
324
  `axis` in the expanded array shape.
311
325
 
312
- This is ``xp.expand_dims`` for `axis` an int *or a tuple of ints*.
313
- Roughly equivalent to ``numpy.expand_dims`` for NumPy arrays.
314
-
315
326
  Parameters
316
327
  ----------
317
328
  a : array
@@ -804,7 +815,7 @@ def searchsorted(
804
815
  Find the indices into a sorted array ``x1`` such that if the elements in ``x2``
805
816
  were inserted before the indices, the resulting array would remain sorted.
806
817
 
807
- The behavior of this function is similar to that of `array_api.searchsorted`,
818
+ The behavior of this function is similar to that of :func:`array_api.searchsorted`,
808
819
  but it relaxes the requirement that `x1` must be one-dimensional.
809
820
  This function is vectorized, treating slices along the last axis
810
821
  as elements and preceding axes as batch (or "loop") dimensions.
@@ -1220,8 +1231,8 @@ def isin(
1220
1231
  """
1221
1232
  Determine whether each element in `a` is present in `b`.
1222
1233
 
1223
- Return a boolean array of the same shape as `a` that is True for elements
1224
- that are in `b` and False otherwise.
1234
+ This is :func:`array_api.isin`, with additional `assume_unique`
1235
+ and `kind` parameters.
1225
1236
 
1226
1237
  Parameters
1227
1238
  ----------
@@ -2,10 +2,12 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import functools
5
6
  import io
6
7
  import math
7
8
  import pickle
8
9
  import types
10
+ import warnings
9
11
  from collections.abc import Callable, Generator, Iterable, Iterator
10
12
  from functools import wraps
11
13
  from types import ModuleType
@@ -48,6 +50,7 @@ T = TypeVar("T")
48
50
  __all__ = [
49
51
  "asarrays",
50
52
  "capabilities",
53
+ "deprecated",
51
54
  "eager_shape",
52
55
  "in1d",
53
56
  "is_python_scalar",
@@ -58,6 +61,26 @@ __all__ = [
58
61
  ]
59
62
 
60
63
 
64
+ def deprecated(
65
+ msg: str, stacklevel: int = 2
66
+ ) -> Callable[[Callable[P, T]], Callable[P, T]]: # numpydoc ignore=PR01,RT01
67
+ """Deprecate a function by emitting a warning on use."""
68
+
69
+ def decorate(func: Callable[P, T]) -> Callable[P, T]: # numpydoc ignore=GL08
70
+ @functools.wraps(func)
71
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: # numpydoc ignore=GL08
72
+ warnings.warn(
73
+ msg,
74
+ category=DeprecationWarning,
75
+ stacklevel=stacklevel,
76
+ )
77
+ return func(*args, **kwargs)
78
+
79
+ return wrapper
80
+
81
+ return decorate
82
+
83
+
61
84
  def in1d(
62
85
  x1: Array,
63
86
  x2: Array,
File without changes
@@ -598,22 +598,23 @@ def _check_ns_shape_dtype(
598
598
  np = _require_numpy()
599
599
 
600
600
  actual_xp = array_namespace(actual) # Raises on Python scalars and lists
601
- desired_xp = array_namespace(desired)
602
601
 
603
602
  if xp is not None:
604
603
  _msg = (
605
- "Namespace of desired array does not match the `xp` argument.\n"
606
- f"Desired array's namespace: {desired_xp.__name__}\n"
604
+ "Namespace of actual array does not match the `xp` argument.\n"
605
+ f"Actual array's namespace: {actual_xp.__name__}\n"
607
606
  f"Expected namespace: {xp.__name__}."
608
607
  )
609
- assert desired_xp == xp, _msg
610
-
611
- _msg = (
612
- "Namespaces of actual and desired arrays do not match.\n"
613
- f"Actual: {actual_xp.__name__}\n"
614
- f"Desired: {desired_xp.__name__}."
615
- )
616
- assert actual_xp == desired_xp, _msg
608
+ assert actual_xp == xp, _msg
609
+ desired_xp = xp
610
+ else:
611
+ desired_xp = array_namespace(desired)
612
+ _msg = (
613
+ "Namespaces of actual and desired arrays do not match.\n"
614
+ f"Actual: {actual_xp.__name__}\n"
615
+ f"Desired: {desired_xp.__name__}."
616
+ )
617
+ assert actual_xp == desired_xp, _msg
617
618
 
618
619
  if is_numpy_namespace(actual_xp) and check_scalar:
619
620
  # only NumPy distinguishes between scalars and arrays; we do if check_scalar.
@@ -650,6 +651,7 @@ def _check_ns_shape_dtype(
650
651
  msg = f"sizes do not match: {actual_size} != {desired_size}"
651
652
  assert actual_size == desired_size, msg
652
653
 
654
+ desired = desired_xp.asarray(desired)
653
655
  if check_dtype:
654
656
  msg = f"dtypes do not match: {actual.dtype} != {desired.dtype}"
655
657
  assert actual.dtype == desired.dtype, msg
@@ -774,6 +776,7 @@ def assert_close(
774
776
 
775
777
  Array arguments to `atol` and `rtol` must be valid input to :class:`float`.
776
778
  """
779
+ __tracebackhide__ = True
777
780
  actual, desired, xp, np = _check_ns_shape_dtype(
778
781
  actual, desired, check_dtype, check_shape, check_scalar, xp
779
782
  )
@@ -857,6 +860,7 @@ def assert_equal(
857
860
  assert_close : Similar function for inexact equality checks.
858
861
  numpy.testing.assert_array_equal : Similar function for NumPy arrays.
859
862
  """
863
+ __tracebackhide__ = True
860
864
  actual, desired, xp, np = _check_ns_shape_dtype(
861
865
  actual, desired, check_dtype, check_shape, check_scalar, xp
862
866
  )
@@ -918,6 +922,7 @@ def assert_less(
918
922
  assert_close : Similar function for inexact equality checks.
919
923
  numpy.testing.assert_array_less : Similar function for NumPy arrays.
920
924
  """
925
+ __tracebackhide__ = True
921
926
  x, y, xp, np = _check_ns_shape_dtype(
922
927
  x, y, check_dtype, check_shape, check_scalar, xp
923
928
  )
@@ -128,6 +128,9 @@ def xp(
128
128
  # Possibly wrap module with array_api_compat
129
129
  xp = array_namespace(xp.empty(0))
130
130
 
131
+ if library.like(Backend.ARRAY_API_STRICT):
132
+ xp.set_array_api_strict_flags(api_version="2025.12")
133
+
131
134
  if library == Backend.ARRAY_API_STRICTEST:
132
135
  with xp.ArrayAPIStrictFlags(
133
136
  boolean_indexing=False,
@@ -0,0 +1,15 @@
1
+ from types import ModuleType
2
+
3
+ import pytest
4
+
5
+ from array_api_extra import broadcast_shapes, expand_dims
6
+
7
+
8
+ class TestDeprecatedFunctions:
9
+ def test_broadcast_shapes(self, xp: ModuleType):
10
+ with pytest.raises(DeprecationWarning, match=r"removed in v1.0.0"):
11
+ _ = broadcast_shapes((2, 3), (2, 1), xp=xp)
12
+
13
+ def test_expand_dims(self, xp: ModuleType):
14
+ with pytest.raises(DeprecationWarning, match=r"removed in v1.0.0"):
15
+ _ = expand_dims(xp.ones(2), axis=0, xp=xp)
@@ -488,6 +488,7 @@ class TestAtLeastND:
488
488
  assert_equal(y, xp.asarray([[[[[[[[[3.0]], [[2.0]]]]]]]]]))
489
489
 
490
490
 
491
+ @pytest.mark.filterwarnings("ignore:.*removed in v1.0.0.*:DeprecationWarning")
491
492
  class TestBroadcastShapes:
492
493
  def test_delegates_known_integer_shapes(self, monkeypatch: pytest.MonkeyPatch):
493
494
  calls = []
@@ -828,6 +829,7 @@ class TestDefaultDType:
828
829
  assert default_dtype(xp, "complex floating") == xp.complex64
829
830
 
830
831
 
832
+ @pytest.mark.filterwarnings(r"ignore:.*removed in v1.0.0.*:DeprecationWarning")
831
833
  class TestExpandDims:
832
834
  def test_single_axis(self, xp: ModuleType):
833
835
  """Trivial case where xpx.expand_dims doesn't add anything to xp.expand_dims"""
@@ -81,10 +81,11 @@ class TestAssertEqualCloseLess:
81
81
  func(xp.asarray(0), 0)
82
82
  with pytest.raises(TypeError, match="list is not a supported array type"):
83
83
  func(xp.asarray([0]), [0])
84
+ func(xp.asarray(0), xp.asarray(1 if func is assert_less else 0), xp=xp)
84
85
  with (
85
86
  pytest.raises(
86
87
  AssertionError,
87
- match="Namespace of desired array does not match the `xp` argument",
88
+ match="Namespace of actual array does not match the `xp` argument",
88
89
  ),
89
90
  ):
90
91
  func(xp.asarray(0), xp.asarray(0), xp=np)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: array-api-extra
3
- Version: 0.10.3
3
+ Version: 0.11.0
4
4
  Summary: Extra array functions built on top of the array API standard.
5
5
  Author-Email: Lucas Colley <lucas.colley8@gmail.com>
6
6
  License-Expression: MIT
@@ -130,6 +130,7 @@ This project exists thanks to the following contributors
130
130
  <td align="center" valign="top" width="14.28%"><a href="http://steppi.github.io"><img src="https://avatars.githubusercontent.com/u/1953382?v=4?s=100" width="100px;" alt="Albert Steppi"/><br /><sub><b>Albert Steppi</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=steppi" title="Code">💻</a> <a href="#ideas-steppi" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=steppi" title="Tests">⚠️</a></td>
131
131
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/prady0t"><img src="https://avatars.githubusercontent.com/u/99216956?v=4?s=100" width="100px;" alt="Pradyot Ranjan"/><br /><sub><b>Pradyot Ranjan</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=prady0t" title="Code">💻</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=prady0t" title="Documentation">📖</a> <a href="#ideas-prady0t" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/data-apis/array-api-extra/commits?author=prady0t" title="Tests">⚠️</a></td>
132
132
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/lundybernard"><img src="https://avatars.githubusercontent.com/u/17297695?v=4?s=100" width="100px;" alt="Lundy Bernard"/><br /><sub><b>Lundy Bernard</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/pulls?q=is%3Apr+reviewed-by%3Alundybernard" title="Reviewed Pull Requests">👀</a></td>
133
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Cyril-36"><img src="https://avatars.githubusercontent.com/u/138621648?v=4?s=100" width="100px;" alt="Chaitanya Pudota"/><br /><sub><b>Chaitanya Pudota</b></sub></a><br /><a href="https://github.com/data-apis/array-api-extra/commits?author=Cyril-36" title="Code">💻</a></td>
133
134
  </tr>
134
135
  </tbody>
135
136
  </table>
@@ -1,9 +1,10 @@
1
- array_api_extra-0.10.3.dist-info/METADATA,sha256=g78TkA9OPq7CJGBKyf9NR7e9RUbdDx2UAvmARQnQY94,20220
2
- array_api_extra-0.10.3.dist-info/WHEEL,sha256=5J4neoE7k6LMgx4Fz1FHgBiO3YevhJGtNQ3muDrdLQM,75
3
- array_api_extra-0.10.3.dist-info/licenses/LICENSE,sha256=WElDmP4Uf9znamiy3s1MCM46HqI3ttZ4UAHBX4IsbtY,1097
4
- array_api_extra/__init__.py,sha256=odvk8MxQ5ErbJZikYT4YhZ-5bcsK7WHkC0eshCGE_L0,995
5
- array_api_extra/_delegation.py,sha256=8kTLW-nuETTuZnfVsbZZEwmoytZ5GvftDUVNzwmR48E,41854
6
- array_api_extra/testing.py,sha256=eBsY1WO0G8du2FTZi4Q7jKvvTUDOaKJR2r5BNoKlVa4,36385
1
+ array_api_extra-0.11.0.dist-info/METADATA,sha256=T_IXJ_m-X_R-xxBfH9BtBjPRpsYmbX9Pe9R9XJeDthM,20577
2
+ array_api_extra-0.11.0.dist-info/WHEEL,sha256=5J4neoE7k6LMgx4Fz1FHgBiO3YevhJGtNQ3muDrdLQM,75
3
+ array_api_extra-0.11.0.dist-info/licenses/LICENSE,sha256=WElDmP4Uf9znamiy3s1MCM46HqI3ttZ4UAHBX4IsbtY,1097
4
+ array_api_extra/__init__.py,sha256=JkiNKaBRN77esjadhofAQoWDURapapJbukZ6P1uZ98E,995
5
+ array_api_extra/_delegation.py,sha256=qORUZOA3RVlG2ddbzHl_ycidTITPRcAjgkGplPCSZSg,42316
6
+ array_api_extra/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ array_api_extra/testing.py,sha256=WWzhqiCk0ERgpNf9XtForYR22FmxrbbYrORsqVqEpWc,36571
7
8
  array_api_extra/_lib/__init__.py,sha256=Mht4YV9Rpkzg5kORPlgjOOXk4y7bvdngowS6KGSHqNE,36
8
9
  array_api_extra/_lib/_at.py,sha256=7SSK_xlyQJtyE6YT3MKtGSkiRUdhl1WXHZQoVZUBCWo,15821
9
10
  array_api_extra/_lib/_backends.py,sha256=sJJ38eOA_ej-GXWwrZBDjrHiLNJbsyH6RyP9-h7jmLY,2170
@@ -13,18 +14,19 @@ array_api_extra/_lib/_testing.py,sha256=7LFCLWAGD0aGOeCGXYfd8bHbVKe1q9yECy3yTpZW
13
14
  array_api_extra/_lib/_utils/__init__.py,sha256=8ICffM2MprXpWZd8ia0-5ZTnKtDfeZD0gExLveDrXZs,49
14
15
  array_api_extra/_lib/_utils/_compat.py,sha256=4A5a_S4qo88_H8LKmQal2e_1PVQAY1eInKDZsCgPNYU,1812
15
16
  array_api_extra/_lib/_utils/_compat.pyi,sha256=6QexmJx0rPSEtvVQAt2HbS87F8njDMsD9UhyIJsen8c,1720
16
- array_api_extra/_lib/_utils/_helpers.py,sha256=vC9vy2_4E7SyDCOk5Q4pxrMx4mLrmVTc8xacDhtmGj0,18657
17
+ array_api_extra/_lib/_utils/_helpers.py,sha256=IGit80yi2j2z1LppsgbxgJciF2P_a-zP88bIe5SJRjk,19330
17
18
  array_api_extra/_lib/_utils/_typing.py,sha256=0NSYWpdXH58Dx9T7HsNPM0NW2iPlTZS6xOrR-5tFOYc,228
18
19
  array_api_extra/_lib/_utils/_typing.pyi,sha256=tfmj1bK5a1RWFc8qXR10FhLlXBwzyItFrN0zcXTWntM,4665
19
20
  array_api_extra/tests/__init__.py,sha256=GhZu68trXNtwWKcx-VzlMf34Rzu76O2xZC8OOVO_400,56
20
- array_api_extra/tests/conftest.py,sha256=f1_9k-s5MRHbOQjazHp41UiMkUsRB0qtxgHVncjQstg,8464
21
+ array_api_extra/tests/conftest.py,sha256=nUnjNvue4cLM0CHUSlbyXUbS0kUixHawqMpmT75gJas,8573
21
22
  array_api_extra/tests/test_at.py,sha256=S5LS-sX0Wp-X1UI3RBTNIsf7E1WZIAesVSnghJwXaqU,11333
22
- array_api_extra/tests/test_funcs.py,sha256=p_CLq0RSBwuoNv1jxOs_L6uDrBHH_nhleC67-i1D9l8,71346
23
+ array_api_extra/tests/test_deprecation.py,sha256=CAnfkERt6iW7Y6WrKzlO_Fe6YAFF2vf5st0MMPtRvQA,501
24
+ array_api_extra/tests/test_funcs.py,sha256=b8dO319ow0dAvNTfp45VnA4raYd36twCYyeIjpCBw2g,71505
23
25
  array_api_extra/tests/test_helpers.py,sha256=TE3TpmJbkQKQGSxl857JGVOL8TS4WdGhi0ZiG098-wU,14470
24
26
  array_api_extra/tests/test_lazy.py,sha256=OF0OgQ1ZkogVJXUT5CrdBYzNk-KvuTjuUSP10GDUhzM,15633
25
- array_api_extra/tests/test_testing.py,sha256=rWLc2JTiuq0cAMbBxv-Y3-OrFFUtIQBMkKTEaxfC7T4,23577
27
+ array_api_extra/tests/test_testing.py,sha256=9X7724DKN4a_Dj-01lAh0SfemKlMdlLa6IlaVWmFVvw,23656
26
28
  array_api_extra/tests/test_version.py,sha256=Jq62FYkngisYvklCZz6rqCAyaehvtX16h7RQ39GYazo,155
27
29
  array_api_extra/vendor_tests/__init__.py,sha256=M5dKkq1u6J2453lWeKDqjK-6jUhd9Qn6SABBZOXwicc,54
28
30
  array_api_extra/vendor_tests/_array_api_compat_vendor.py,sha256=Wy5ImPjXOZV2RKKaSyR9wPh0vzi09PEW1CLhBIH0rnE,688
29
31
  array_api_extra/vendor_tests/test_vendor.py,sha256=QrzrB_PT56q2UNFdvPv-uoAykMwuWc5MyXjfOU5ooRU,2272
30
- array_api_extra-0.10.3.dist-info/RECORD,,
32
+ array_api_extra-0.11.0.dist-info/RECORD,,