Fix dpnp.insert ignoring out-of-bounds negative indices in multi-element obj - #3041
Open
antonwolfy wants to merge 3 commits into
Open
Fix dpnp.insert ignoring out-of-bounds negative indices in multi-element obj#3041antonwolfy wants to merge 3 commits into
antonwolfy wants to merge 3 commits into
Conversation
Contributor
|
Array API standard conformance tests for dpnp=0.21.0dev6=py314ha0e2e8e_20 ran successfully. |
Collaborator
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3041/index.html |
antonwolfy
marked this pull request as ready for review
August 26, 2026 11:16
antonwolfy
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
August 26, 2026 11:16
…ent obj Backport of numpy#31782. The multi-element index path in _insert_array_indices normalized negative indices without any bounds check, so an out-of-bounds negative index mixed with in-bounds ones silently produced wrong results instead of raising. Add the same bounds validation numpy uses so any out-of-bounds index raises IndexError, and extend the test to cover the mixed case.
Parametrize the out-of-bounds test over both numpy and dpnp and add multi-element cases that exercise the newly added bounds check in _insert_array_indices, including the positive (max > n) branch, plus an ND case validating axis/size reporting for a non-zero axis.
antonwolfy
force-pushed
the
fix-insert-oob-negative-indices
branch
from
August 26, 2026 17:57
68c84e6 to
97b4495
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dpnp.inserthas two index paths: the singleton path (_insert_singleton_index) already validated bounds, but the multi-element array path (_insert_array_indices) normalized negative indices withindices[indices < 0] += nwithout any bounds check. As a result, an out-of-bounds negative index mixed with in-bounds ones — e.g.dpnp.insert([0, 1, 2], [-6, 0], [9, 8])— silently produced a wrong result instead of raising.This PR adds the same bounds validation NumPy introduced: if any index is
< -nor> n,IndexErroris raised with the standardindex {i} is out of bounds for axis {axis} with size {n}message. In-bounds and out-of-bounds indices mixed in a single call now consistently raise.