Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: properly handle negative indexes in ufunc_at fast path #24150

Merged
merged 1 commit into from Jul 9, 2023

Conversation

mattip
Copy link
Member

@mattip mattip commented Jul 9, 2023

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:

Test added that failed before, passes after

@mattip mattip added the 09 - Backport-Candidate PRs tagged should be backported label Jul 9, 2023
@charris charris merged commit c19ce9c into numpy:main Jul 9, 2023
59 checks passed
@charris
Copy link
Member

charris commented Jul 9, 2023

Thanks Matti.

assert a[-1] == 11 # issue 24147
assert a[1] == 2
assert a[2] == 3

Copy link
Member

Choose a reason for hiding this comment

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

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: (1.25.0) ufunc.at returns wrong results when indices is an array containing negative ints
3 participants