diff --git a/CHANGELOG.md b/CHANGELOG.md index 4472233701e..2a6129a8f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This release is compatible with NumPy 2.4.5. * Replaced `.pxi` includes in `dpnp.tensor` with modular `.pxd`/`.pyx` Cython imports [#2913](https://github.com/IntelPython/dpnp/pull/2913) * Reimplemented `dpnp.eye` and `dpnp.tensor.eye` with a branchless kernel [gh-2937](https://github.com/IntelPython/dpnp/pull/2937) * Cleaned up Python bindings for indexing functions, renaming `usm_ndarray_take` and `usm_ndarray_put` to `py_take` and `py_put` and refactoring validation [gh-2935](https://github.com/IntelPython/dpnp/pull/2935) +* Changed `dpnp.broadcast_arrays` and `dpnp.tensor.broadcast_arrays` to return a tuple instead of a list, aligning with NumPy 2.x behavior and 2025.12 version of the Python array API standard [#2944](https://github.com/IntelPython/dpnp/pull/2944) ### Deprecated diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index b96d36a40e6..32d3742bf7b 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -1060,8 +1060,8 @@ def broadcast_arrays(*args, subok=False): Returns ------- - out : list of dpnp.ndarray - A list of arrays which are views on the original arrays from `args`. + out : tuple of dpnp.ndarray + A tuple of arrays which are views on the original arrays from `args`. Limitations ----------- @@ -1078,9 +1078,9 @@ def broadcast_arrays(*args, subok=False): >>> x = np.array([[1, 2, 3]]) >>> y = np.array([[4], [5]]) >>> np.broadcast_arrays(x, y) - [array([[1, 2, 3], + (array([[1, 2, 3], [1, 2, 3]]), array([[4, 4, 4], - [5, 5, 5]])] + [5, 5, 5]])) """ @@ -1088,10 +1088,10 @@ def broadcast_arrays(*args, subok=False): raise NotImplementedError(f"subok={subok} is currently not supported") if len(args) == 0: - return [] + return () usm_arrays = dpt.broadcast_arrays(*[dpnp.get_usm_ndarray(a) for a in args]) - return [dpnp_array._create_from_usm_ndarray(a) for a in usm_arrays] + return tuple(dpnp_array._create_from_usm_ndarray(a) for a in usm_arrays) def broadcast_shapes(*args): diff --git a/dpnp/tensor/_manipulation_functions.py b/dpnp/tensor/_manipulation_functions.py index 7347f62de11..4b7e2d13146 100644 --- a/dpnp/tensor/_manipulation_functions.py +++ b/dpnp/tensor/_manipulation_functions.py @@ -228,8 +228,8 @@ def broadcast_arrays(*args): broadcasted. Returns: - List[usm_ndarray]: - A list of broadcasted arrays. Each array + tuple[usm_ndarray, ...]: + A tuple of broadcasted arrays. Each array must have the same shape. Each array must have the same `dtype`, `device` and `usm_type` attributes as its corresponding input array. @@ -245,7 +245,7 @@ def broadcast_arrays(*args): if all(X.shape == shape for X in args): return args - return [broadcast_to(X, shape) for X in args] + return tuple(broadcast_to(X, shape) for X in args) def broadcast_to(X, /, shape): diff --git a/dpnp/tests/test_arraymanipulation.py b/dpnp/tests/test_arraymanipulation.py index 25c454b9761..7ef31eac703 100644 --- a/dpnp/tests/test_arraymanipulation.py +++ b/dpnp/tests/test_arraymanipulation.py @@ -289,7 +289,7 @@ def test_incompatible_shapes_raise_valueerror(self, shapes): self.assert_broadcast_arrays_raise(input_shapes[::-1]) def test_broadcast_arrays_empty_input(self): - assert dpnp.broadcast_arrays() == [] + assert dpnp.broadcast_arrays() == () def test_subok_error(self): x = dpnp.ones(4)