Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
* Changed `dpnp.meshgrid` and `dpnp.tensor.meshgrid` to return a tuple instead of a list, aligning with NumPy 2.5+ behavior and 2025.12 version of the Python array API standard [#2854](https://github.com/IntelPython/dpnp/pull/2854)

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"):
)

if ndim < 1:
return []
return ()

s0 = (1,) * ndim
output = [
Expand All @@ -3132,7 +3132,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"):
if copy:
output = [dpt.copy(x) for x in output]

return [dpnp_array._create_from_usm_ndarray(x) for x in output]
Comment thread
antonwolfy marked this conversation as resolved.
return tuple(dpnp_array._create_from_usm_ndarray(x) for x in output)


class MGridClass:
Expand Down
10 changes: 5 additions & 5 deletions dpnp/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def linspace(

def meshgrid(*arrays, indexing="xy"):
"""
Creates list of :class:`dpctl.tensor.usm_ndarray` coordinate matrices
Creates tuple of :class:`dpctl.tensor.usm_ndarray` coordinate matrices
from vectors.

Args:
Expand All @@ -1456,8 +1456,8 @@ def meshgrid(*arrays, indexing="xy"):
keyword has no effect and should be ignored. Default: ``"xy"``

Returns:
List[array]:
list of ``N`` arrays, where ``N`` is the number of
Tuple[array]:
tuple of ``N`` arrays, where ``N`` is the number of
provided one-dimensional input arrays. Each returned array must
have rank ``N``.
For a set of ``n`` vectors with lengths ``N0``, ``N1``, ``N2``, ...
Expand Down Expand Up @@ -1495,7 +1495,7 @@ def meshgrid(*arrays, indexing="xy"):
)
n = len(arrays)
if n == 0:
return []
return ()

sh = (-1,) + (1,) * (n - 1)

Expand All @@ -1511,7 +1511,7 @@ def meshgrid(*arrays, indexing="xy"):

output = dpt.broadcast_arrays(*res)

return output
return tuple(output)


def ones(
Expand Down
3 changes: 2 additions & 1 deletion dpnp/tests/tensor/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,8 @@ def test_meshgrid():
assert n == len(Znp)
for i in range(n):
assert np.array_equal(dpt.asnumpy(Z[i]), Znp[i])
assert dpt.meshgrid() == []
assert isinstance(Z, tuple)
assert dpt.meshgrid() == ()
# dimension > 1 must raise ValueError
with pytest.raises(ValueError):
dpt.meshgrid(dpt.usm_ndarray((4, 4)))
Expand Down
10 changes: 8 additions & 2 deletions dpnp/tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,13 +984,19 @@ def test_dpctl_tensor_input(func, args):
[[], [[1]], [[1, 2, 3], [4, 5, 6]], [[1, 2], [3, 4], [5, 6]]],
ids=["[]", "[[1]]", "[[1, 2, 3], [4, 5, 6]]", "[[1, 2], [3, 4], [5, 6]]"],
)
@pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False))
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_none=True, no_float16=False)
)
@pytest.mark.parametrize("indexing", ["ij", "xy"])
def test_meshgrid(arrays, dtype, indexing):
func = lambda xp, xi: xp.meshgrid(*xi, indexing=indexing)
a = tuple(numpy.array(array, dtype=dtype) for array in arrays)
ia = tuple(dpnp.array(array, dtype=dtype) for array in arrays)
assert_array_equal(func(numpy, a), func(dpnp, ia))

result = func(dpnp, ia)
expected = func(numpy, a)
assert_array_equal(result, expected, strict=True)
assert isinstance(result, tuple)


@pytest.mark.parametrize("shape", [(24,), (4, 6), (2, 3, 4), (2, 3, 2, 2)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def test_meshgrid0(self, dtype):
out = cupy.meshgrid(
indexing=self.indexing, sparse=self.sparse, copy=self.copy
)
assert out == []
assert out == ()

@testing.for_all_dtypes()
@testing.numpy_cupy_array_equal()
Expand Down
Loading