PERF: fast-path no-op roll cases#31894
Draft
KRRT7 wants to merge 2 commits into
Draft
Conversation
eendebakpt
reviewed
Jul 7, 2026
| for ax, offset in shifts.items(): | ||
| offset %= a.shape[ax] or 1 # If `a` is empty, nothing matters. | ||
| if offset: | ||
| roll_needed = True |
Contributor
There was a problem hiding this comment.
This adds a (tiny) bit of overhead for all cases. How important is the case where no roll is needed? Or where axis is empty?
Member
There was a problem hiding this comment.
would show up as a slower benchmark if it was noticeable no?
Contributor
Author
There was a problem hiding this comment.
either way, I have more PRs that build on top of this and recover whatever (imo, negligible) losses there might be.
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.
PR summary
Fast-paths two no-op
np.rollcases:axis=()Addresses gh-12389.
Benchmarks from
spin bench --compare main HEAD -t bench_manipulate.DimsManipulations:time_roll_empty_axes: 59-64% fastertime_roll_zero_shift: 16-18% fasterFirst time committer introduction
I am a NumPy user/contributor looking at small, focused performance improvements in common array operations. I will handle review discussion and follow-up changes directly.
AI Disclosure
LLM / Harness: hybrid.
AI assistance was used to inspect the codebase, run local commands and benchmarks, draft PR text, and help prepare candidate patches. I reviewed the generated suggestions, selected the final changes, and am responsible for the code, submission, and follow-up discussion. Some PR text and candidate code edits were drafted with AI assistance; the final patch and text were reviewed and edited by me.