diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2dc01b898..a9dc748fe34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ This release is compatible with NumPy 2.5. * Fixed `PytestRemovedIn10Warning` raised by `pytest` 9.1.0 by converting class-scoped fixtures to class methods [#2952](https://github.com/IntelPython/dpnp/pull/2952) * Fixed `dpnp.linalg.svd(..., hermitian=True)` returning a non-unitary `vh` for singular input arrays due to a zero sign appearing [#2954](https://github.com/IntelPython/dpnp/pull/2954) * Fixed scalar conversion of size-one `dpnp.tensor.usm_ndarray` (e.g. `int()`, `float()`, indexing) which failed with NumPy 2.5 after the in-place `ndarray.shape` assignment was deprecated [#2958](https://github.com/IntelPython/dpnp/pull/2958) +* Fixed `dpnp.mgrid` and `dpnp.ogrid` to return consistent results between single-slice and tuple-of-slices syntax when the step is a complex number with a non-integer magnitude (e.g. `2.5j`) [#2971](https://github.com/IntelPython/dpnp/pull/2971) ### Security diff --git a/dpnp/dpnp_algo/dpnp_arraycreation.py b/dpnp/dpnp_algo/dpnp_arraycreation.py index 44b852e32e2..ff83209f4d2 100644 --- a/dpnp/dpnp_algo/dpnp_arraycreation.py +++ b/dpnp/dpnp_algo/dpnp_arraycreation.py @@ -356,11 +356,10 @@ def __getitem__(self, key): if start is None: start = 0 if isinstance(step, complex): - step = abs(step) - length = int(step) + step_float = abs(step) + step = length = int(step_float) if step != 1: step = (stop - start) / float(step - 1) - stop = stop + step return ( dpnp.arange( 0, diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index d6e72672636..e9800b3abb9 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -1071,6 +1071,8 @@ def check_results(self, result, expected): slice(0, 5, 0.5), # float step slice(0, 5, 1j), # complex step slice(0, 5, 5j), # complex step + slice(0, 10, 2.5j), # complex step with non-integer magnitude + slice(0, 10, 3.5j), # non-integer magnitude with interior points slice(None, 5, 1), # no start slice(0, 5, None), # no step ], @@ -1090,6 +1092,10 @@ def test_single_slice(self, grid, slice): slice(0.0, 5, 1), slice(0, 10, 1j), ), # float start and complex step + ( + slice(0, 10, 2.5j), + slice(0, 10, 3.5j), + ), # complex step with non-integer magnitude ], ) def test_md_slice(self, grid, slices):