BUG: properly handle negative indexes in ufunc_at fast path#24150
Merged
charris merged 1 commit intonumpy:mainfrom Jul 9, 2023
Merged
BUG: properly handle negative indexes in ufunc_at fast path#24150charris merged 1 commit intonumpy:mainfrom
charris merged 1 commit intonumpy:mainfrom
Conversation
Member
|
Thanks Matti. |
seberg
reviewed
Jul 27, 2023
| assert a[-1] == 11 # issue 24147 | ||
| assert a[1] == 2 | ||
| assert a[2] == 3 | ||
|
|
Member
There was a problem hiding this comment.
An bad merge (locally) brought me here, but then I noticed that this can modify the original index array:
assert indxs[0] == -1
would fail. I think it shows that passing pointers or full offsets rather than indices makes more sense here (we need a temporary array anyway), but I have to think about how a hot-fix should look like.
Probably either need a local buffer here, or push the fixing into the indexed loop.
(Maybe local buffer is good, since that is what I would want to do with that hot-fix anyway in some form, even if it may make sense to push the buffer for that case slightly further up.)
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.
Fixes #24147
When avoiding the iter API for faster iteration, negative indexes need to be unwrapped.
Other places this is done in a similar way:
mapiter_@name@numpy/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
Lines 1683 to 1684 in c143f7b
PyArray_MapIterResetnumpy/numpy/core/src/multiarray/mapping.c
Lines 2281 to 2282 in c143f7b
PyArray_MapIterNextnumpy/numpy/core/src/multiarray/mapping.c
Lines 2335 to 2336 in c143f7b
Test added that failed before, passes after