Skip to content

Fix dpnp.ndarray.flat indexing edge cases - #3045

Draft
antonwolfy wants to merge 5 commits into
masterfrom
fix/SAT-8204-flatiter-indexing
Draft

Fix dpnp.ndarray.flat indexing edge cases#3045
antonwolfy wants to merge 5 commits into
masterfrom
fix/SAT-8204-flatiter-indexing

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR reworks dpnp.flatiter (dpnp.ndarray.flat) indexing so it aligns with NumPy's flat-iterator semantics, which were tightened in NumPy 2.4.

Previously dpnp.ndarray.flat accepted only a single integer index and raised TypeError for everything else. Indexing now delegates to regular array indexing of the flattened array, so it supports the full set of flat index types and matches NumPy's error behavior.

  • 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?

Support slices, ellipsis, empty tuple, and integer/boolean array indices
in flatiter __getitem__/__setitem__, reusing regular array indexing for
validation. Reject numpy.newaxis (None), raise IndexError for
out-of-bounds integer array indices, and reject assignment with a 0-D
index, matching NumPy (gh-28590). Return copies from __getitem__ rather
than views.

SAT-8204
Cover slices, ellipsis, empty tuple, integer/boolean array indices,
newaxis rejection, out-of-bounds, non-contiguous write-back, and
copy-not-view semantics. Cross-check against NumPy where behavior is
shared, and gate NumPy 2.4-only cases (numpy-gh-28590) with
testing.with_requires.
Match numpy's np.put-style cycling when a flat assignment value is
shorter than the selection (dpnp.put broadcasts instead). Enable the
previously-disabled slice/ellipsis/empty-tuple parametrizations in the
cupy flatiter iterate tests, and drop the IndexError cases that became
valid indices in numpy 2.4 (numpy-gh-28590).
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Aug 27, 2026
@antonwolfy antonwolfy self-assigned this Aug 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev6=py314ha0e2e8e_23 ran successfully.
Passed: 1375
Failed: 0
Skipped: 7

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.495% (+0.01%) from 78.483% — fix/SAT-8204-flatiter-indexing into master

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.

2 participants