ENH: allow start-stop array for indices in reduceat #25476
Draft
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.
Triggered by #834 seeing some comments again, a draft just to see how it would look to allow
reduceat
to take a set of start, stop indices (treated as slices), to make the interface a bit more easily comprehensible without making a truly new method. It also allows passing in aninitial
to deal with empty slices.Fixes #834
Draft only, since no new test cases yet. Mostly to discuss whether we want this at all, and, if so, what the API should be. So probably best not to worry too much about implementation (the duplication of code, both in
reduceat
itself and withreduce
is large).Sample use:
Writing it out like this, I think a different order may be useful, i.e.,
np.add(a, [(1, 2), (3, -1), (5, 0)])
. The reason I picked the other one was that I liked the idea of triggering it by usingslice(start, stop)
, with bothstart
andstop
possibly arrays and a tuple of two lists was closer to that (although internally it just turns it into an array). The list of tuples suggests more a structured array with start and stop (and step?) entries.p.s. Fairly trivially extensible to
start, stop, step
.