Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This release is compatible with NumPy 2.5.
* Aligned the signature of `dpnp.tensor.expand_dims` with the Python array API by making `axis` a required argument [#2988](https://github.com/IntelPython/dpnp/pull/2988)
* Removed dead code branches guarded by outdated oneMKL and DPC++ compiler version checks [#2999](https://github.com/IntelPython/dpnp/pull/2999)
* Replaced the deprecated `nd_item::barrier()` member calls in the `accumulators` and `gemm` kernels with the SYCL 2020 `sycl::group_barrier()` free function [#3006](https://github.com/IntelPython/dpnp/pull/3006)
* Changed `dpnp.broadcast_arrays` and `dpnp.tensor.broadcast_arrays` to return a tuple instead of a list, aligning with the 2025.12 Python array API spec [#2944](https://github.com/IntelPython/dpnp/pull/2944)

### Deprecated

Expand Down
12 changes: 6 additions & 6 deletions dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -1078,20 +1078,20 @@ 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]]))

"""

if subok is not 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):
Expand Down
6 changes: 3 additions & 3 deletions dpnp/tensor/_manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -245,7 +245,7 @@ def broadcast_arrays(*args):
if all(X.shape == shape for X in args):
return args
Comment thread
vlad-perevezentsev marked this conversation as resolved.

return [broadcast_to(X, shape) for X in args]
return tuple(broadcast_to(X, shape) for X in args)


def broadcast_to(X, /, shape):
Expand Down
8 changes: 8 additions & 0 deletions dpnp/tests/tensor/test_usm_ndarray_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ def test_incompatible_shapes_raise_valueerror(shapes):
assert_broadcast_arrays_raise(input_shapes[::-1])


def test_broadcast_arrays_tuple():
q = get_queue_or_skip()
out = dpt.broadcast_arrays(
dpt.ones((1, 3), sycl_queue=q), dpt.zeros((3, 1), sycl_queue=q)
)
assert isinstance(out, tuple)


def test_broadcast_arrays_no_args():
with pytest.raises(ValueError):
dpt.broadcast_arrays()
Expand Down
2 changes: 1 addition & 1 deletion dpnp/tests/test_arraymanipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_incompatible_shapes_raise_valueerror(self, shapes):
self.assert_broadcast_arrays_raise(input_shapes[::-1])

def test_broadcast_arrays_empty_input(self):
Comment thread
vlad-perevezentsev marked this conversation as resolved.
assert dpnp.broadcast_arrays() == []
assert dpnp.broadcast_arrays() == ()
Comment thread
vlad-perevezentsev marked this conversation as resolved.

def test_subok_error(self):
x = dpnp.ones(4)
Expand Down
4 changes: 4 additions & 0 deletions dpnp/tests/third_party/cupy/manipulation_tests/test_dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def test_broadcast_arrays(self, xp, dtype):
arrays = [testing.shaped_arange(s, xp, dtype) for s in self.shapes]
return xp.broadcast_arrays(*arrays)

def test_broadcast_arrays_tuple(self):
out = cupy.broadcast_arrays(cupy.ones(3), cupy.zeros(3))
assert isinstance(out, tuple)


@testing.parameterize(
{"shapes": [(3,), (2,)]},
Expand Down
Loading