From 5596628c24eb539bfc734c32ab1af0d2314e3e03 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 24 Jun 2026 15:15:07 +0200 Subject: [PATCH 1/4] Fix inconsistency for complex steps with non-integer magnitude --- dpnp/dpnp_algo/dpnp_arraycreation.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_arraycreation.py b/dpnp/dpnp_algo/dpnp_arraycreation.py index 6052ad467272..441d1ed0f4d0 100644 --- a/dpnp/dpnp_algo/dpnp_arraycreation.py +++ b/dpnp/dpnp_algo/dpnp_arraycreation.py @@ -354,11 +354,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, From c5bf10292ada102603835f1845a337a6fa3a401c Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 24 Jun 2026 15:15:43 +0200 Subject: [PATCH 2/4] Extend tests coverage --- dpnp/tests/test_arraycreation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index d6e726726362..257a2265be87 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -1071,6 +1071,7 @@ 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(None, 5, 1), # no start slice(0, 5, None), # no step ], @@ -1090,6 +1091,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, 5, 1.5j), + ), # complex step with non-integer magnitude ], ) def test_md_slice(self, grid, slices): From 8ba59f171672d326d8085f5e2a3abbdceb131e64 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 24 Jun 2026 15:16:23 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2dc01b8987..a9dc748fe34c 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 From a20d112565800ace790cfa66d2999d1f75f684c4 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 24 Jun 2026 16:11:45 +0200 Subject: [PATCH 4/4] Strengthen tests with interior-point complex magnitude cases --- dpnp/tests/test_arraycreation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index 257a2265be87..e9800b3abb96 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -1072,6 +1072,7 @@ def check_results(self, result, expected): 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 ], @@ -1093,7 +1094,7 @@ def test_single_slice(self, grid, slice): ), # float start and complex step ( slice(0, 10, 2.5j), - slice(0, 5, 1.5j), + slice(0, 10, 3.5j), ), # complex step with non-integer magnitude ], )