Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: do not modify the input to ufunc_at #24272

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

Merged
merged 2 commits into from
Jul 27, 2023
Merged

Conversation

mattip
Copy link
Member

@mattip mattip commented Jul 27, 2023

@seberg pointed out that PR #24150 changes the input of the index argument when it has negative values. Instead, push the calculation down into the inner loop function. Another option would be to allocate a temporary buffer, but this solution avoids the allocation and removes the double-traversal of the indexes (once when preparing the arguments, once in the inner loop call).

This aligns the indexed inner loops with what is done in the other instances of this type of code, as shown at the top of #24150.

@mattip mattip added 09 - Backport-Candidate PRs tagged should be backported 00 - Bug and removed 00 - Bug labels Jul 27, 2023
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good!

Mid/Long-term, I would prefer the other solution. Especially if we can push the "within range" check into the same buffer filling step at least sometimes.
(That is a bit tricky since it would remove the promise of not mutating the input array if there is an out-of-bound index somewhere.)

Maybe that adds a bit of overhead to the main optimized (and most common) path. But I think it should allow to sanely merge the different branches at least partially. (i.e. we can fill a single offset/pointer buffer even for N-dimensional indexing.)

@seberg
Copy link
Member

seberg commented Jul 27, 2023

Would be nice to cover those branches, but let's get this in for backporting, they all follow the same tested pattern after all. Thanks again.

@seberg seberg merged commit 859af34 into numpy:main Jul 27, 2023
seberg added a commit to seberg/numpy that referenced this pull request Jul 28, 2023
This is a follow-up to numpygh-24272 which missed a few files.
@charris charris added this to the 1.25.2 release milestone Jul 30, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 30, 2023
@charris charris removed this from the 1.25.2 release milestone Jul 30, 2023
charris pushed a commit to charris/numpy that referenced this pull request Jul 30, 2023
This is a follow-up to numpygh-24272 which missed a few files.
@mattip mattip deleted the ufunc_at-buffer branch May 5, 2025 11:20
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.

3 participants