-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Added prepend and append to cumsum #14542
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
Conversation
6c4f377
to
4051f10
Compare
API changes need to hit the mailing list numpy-discussion@python.org |
@mattip Definitely will do. I want to shape up the PR a bit first. There are currently no tests, for example. |
|
@paul-the-noob. Full invertibility of |
To be honest, on first sight, I am not sure I quite like this. Mainly because previously this was just a super thin wrapper around |
I was going to suggest that this might be useful for accumulators in general. Not sure about the best name, though. |
Quick question: why is the default value for the new parameters |
@WarrenWeckesser: In general the answer to that question is "because we are considering object arrays, where |
In most cases we currently use But, I think Eric is right, that here it may make sense to allow |
@eric-wieser & @seberg, thanks.
I think I missed something. Are you talking about a hypothetical object where |
I thought it might do |
About
There is a discussion thread about that use. The original use case was changing the name of an optional keyword argument.
|
This PR is tagged "needs decision", so the following comments are meant to help guide that decision. By far the most common use-case that I've seen is prepending a scalar. I think it would be valuable to expand the API to cover at least this use-case. The typical case arises when you have a sequence of sizes, and you want to create a corresponding sequence of offsets, e.g.:
The offsets:
Actually, in this case we typically don't need the final value:
Some examples in the numpy source code:
And a few from scipy (there are more than this):
If we enhance |
Bit of a drive-by comment, but my sense would be to add |
@madphysicist, thanks for contributing this PR. We discussed this in the developers call yesterday. The conclusion there matches the discussion that has taken place so far in the PR:
Would you be interested in working on adding |
Thanks for letting me know. I'll take a look at the functions you mentioned
and will let you know if this is something I can do.
Honestly, looking back at it I'm glad the PR was rejected. There's just too
much going on, with very little actually useful functionality.
Regards,
Joe
…On Thu, Mar 12, 2020, 11:59 AM Warren Weckesser ***@***.***> wrote:
@madphysicist <https://github.com/madphysicist>, thanks for contributing
this PR.
We discussed this in the developers call yesterday. The conclusion there
matches the discussion that has taken place so far in the PR:
- There is not a strong interest in adding prepend and append to cumsum,
so we won't continue with the PR.
- There is interest in the simpler option of prepending a single
initial value. If possible, this should be done in the accumulate
method of the ufuncs, by adding the parameter initial.
Would you be interested in working on adding initial to the accumulate
method? It looks like this would involve modifying the C functions
PyUFunc_GenericReduction and PyUFunc_Accumulate in the file ufunc_object.c
<https://github.com/numpy/numpy/blob/master/numpy/core/src/umath/ufunc_object.c>
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14542 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDHGMXCPL7TIOGWFLIVPWDRHEBF5ANCNFSM4IX25DKA>
.
|
Great, thanks for taking a look. In the meantime, I'll close this PR. |
Similar to
diff
, and equally useful, this PR addsprepend
andappend
arguments tonp.cumsum
. It does not add them to the C implementednp.ndarray.cumsum
, but rather re-uses the code indiff
at the top level.Inspiration: https://stackoverflow.com/questions/57965499/fill-vector-values-between-specified-indices/57965631#comment102355646_57965631
This is still a WIP, but I needed a PR number to create a release notes snippet.