Skip to content

Fix dpnp.mgrid/dpnp.ogrid inconsistency for complex steps with non-integer magnitude#2971

Merged
antonwolfy merged 5 commits into
masterfrom
fix-issue-in-nd_grid
Jun 25, 2026
Merged

Fix dpnp.mgrid/dpnp.ogrid inconsistency for complex steps with non-integer magnitude#2971
antonwolfy merged 5 commits into
masterfrom
fix-issue-in-nd_grid

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

For a complex step, the integer part of its magnitude is the number of points to generate (start and stop inclusive). The single-slice and tuple-of-slices code paths disagreed when the step magnitude was not an integer (e.g. 2.5j):

  • the tuple path used int(abs(step)) - 1 as the divisor (correct), while
  • the single-slice path used the float magnitude abs(step) - 1 as the divisor.

As a result dpnp.mgrid[0:10:2.5j] and dpnp.mgrid[0:10:2.5j,] produced different arrays, and the single-slice form disagreed with NumPy.

>>> dpnp.mgrid[0:10:2.5j]      # before: [0. , 6.667]   after: [ 0., 10.]
>>> dpnp.mgrid[0:10:2.5j,][0]  # always: [ 0., 10.]     (matches NumPy)
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.21.0 release milestone Jun 24, 2026
@antonwolfy antonwolfy self-assigned this Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@coveralls

coveralls commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.066% (-0.003%) from 78.069% — fix-issue-in-nd_grid into master

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev1=py313h509198e_29 ran successfully.
Passed: 1355
Failed: 5
Skipped: 16

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you @antonwolfy

@antonwolfy antonwolfy merged commit 09ff0a8 into master Jun 25, 2026
86 of 88 checks passed
@antonwolfy antonwolfy deleted the fix-issue-in-nd_grid branch June 25, 2026 14:31
github-actions Bot added a commit that referenced this pull request Jun 25, 2026
…n-integer magnitude (#2971)

For a complex step, the integer part of its magnitude is the number of
points to generate (start and stop inclusive). The single-slice and
tuple-of-slices code paths disagreed when the step magnitude was **not**
an integer (e.g. `2.5j`):
- the tuple path used `int(abs(step)) - 1` as the divisor (correct),
while
- the single-slice path used the float magnitude `abs(step) - 1` as the
divisor.

As a result `dpnp.mgrid[0:10:2.5j]` and `dpnp.mgrid[0:10:2.5j,]`
produced different arrays, and the single-slice form disagreed with
NumPy.

```python
>>> dpnp.mgrid[0:10:2.5j]      # before: [0. , 6.667]   after: [ 0., 10.]
>>> dpnp.mgrid[0:10:2.5j,][0]  # always: [ 0., 10.]     (matches NumPy)
``` 09ff0a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants