-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Added accumulate, accumulate! #18931
Conversation
If anything, I feel like we should deprecate |
I would keep What do you mean, when you say that |
Indeed, where does the name choice come from? I did a bit a googling, and I couldn't easily find another example of |
It's the standard name for the operation: https://en.wikipedia.org/wiki/Prefix_sum. |
Although I agree that it's a bit unfortunate. Perhaps we can pick a better name? |
@@ -144,6 +144,8 @@ end | |||
@deprecate chol(A::Number, ::Type{Val{:L}}) ctranspose(chol(A)) | |||
@deprecate chol(A::AbstractMatrix, ::Type{Val{:L}}) ctranspose(chol(A)) | |||
|
|||
@deprecate cumop! scan! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cumop!
wasn't exported, was it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, is the policy that only exported functions get deprecated? Should I remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth checking whether it's widely used in packages. if not, then maybe we can skip the deprecation. mainly the issue is the @deprecate
macro exports the old deprecated name, so isn't quite the right tool for deprecating something that was not originally exported
Thanks for the link, it's funny it didn't show up. Personally, anything sounding like "cumulative" would be clearer for me, including |
I would be happy with |
💯 for Edit: |
|
Using a verb is a great idea. I think I will go with |
I actually didn't know that "cumulate" was a word until I looked it up just now. It might be nice to stick with a more common word, at least IMHO. |
As another data point. For me, a non native speaker, |
I must confess that I was also not 100% sure whether cumulate was actually a word and looked it up to be safe 😄 . So maybe |
If it was 1680 we might have had to bike shed this for a while :P |
I really like Speaking of renaming and functions that carry out this type of task, do we want to rename the internal function |
I wonder should we have a left and a right |
+1 on |
""" | ||
accumulate!(op, B, A, dim=1) | ||
|
||
Cumulative operation `op` on A along a dimension, storing the result in B. The dimension defaults to 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we usually code highlight the input names A
, B
etc ?
edit: looks like the cumprod!
docstring does
@timholy Turns out that there are already two such semi incompatible implementations in Base. Namely I would still tend to merge |
We don't widen Float32 to Float64 in reductions, do we? We widen integer types which gives more range but not more precision. I think for an operation that returns an array, widening should be something that the user has to ask for. |
Right it is more about overflow, though |
Good point, it's more an issue for reductions than for accumulations---manual specification makes sense for the latter. |
($fmod)(res, A, R1, R2, axis) | ||
end | ||
function accumulate_pairwise!(op, result::AbstractVector, v::AbstractVector) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove blank line here
@@ -1905,4 +1908,8 @@ end | |||
end | |||
end | |||
|
|||
# exotic intexing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intexing -> indexing
return s_ | ||
end | ||
|
||
function accumulate_pairwise!(op, result::AbstractVector, v::AbstractVector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need function accumulate_pairwise!{F}(op::F, result::AbstractVector, v::AbstractVector)
Ref: #18207
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I will test if there is a performance difference. Since each final call covers 128 elements of v, it might be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get any results? Same should apply to the function below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had only one allocation even without op::F
, not sure why? I added the type annotation to _accumulate_pairwise!
anyway however.
NumPy also calls a similar operation Regarding widening, my inclination is also to not automatically widen. The only corner case is for |
@@ -1868,3 +1868,61 @@ end | |||
@test size(a) == size(b) | |||
end | |||
end | |||
|
|||
isdefined(:TestHelpers) || eval(Main, :(include(joinpath(dirname(@__FILE__), "TestHelpers.jl")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted, the isdefined
check is wrong.
done |
|
The last hurdle. Then we dine in... er, I mean then we merge this PR! |
@@ -76,6 +78,7 @@ Deprecated or removed | |||
|
|||
* `Dates.recur` has been deprecated in favor of `filter` ([#19288]) | |||
|
|||
* `cummin` and `cummax` have been deprecated in favor of `accumulate`. | |||
Julia v0.5.0 Release Notes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a blank line
@@ -60,6 +60,8 @@ Library improvements | |||
you can now do e.g. `[A I]` and it will concatenate an appropriately sized | |||
identity matrix ([#19305]). | |||
|
|||
* New `accumulate` and `accumulate!` functions, which generalize `cumsum` and `cumprod`. Also known as [scan](https://en.wikipedia.org/wiki/Prefix_sum) ([#18931]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, also known as a scan operation
|
Anything left that prevents this PR from merge? |
rcum_promote_type{T,N}(op, ::Type{Array{T,N}}) = Array{rcum_promote_type(op,T), N} | ||
|
||
# accumulate_pairwise slightly slower then accumulate, but more numerically | ||
# stable in certain situtations (e.g. sums). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here "situtations" has one too many t's
@@ -145,6 +145,10 @@ end | |||
@deprecate chol(A::Number, ::Type{Val{:L}}) ctranspose(chol(A)) | |||
@deprecate chol(A::AbstractMatrix, ::Type{Val{:L}}) ctranspose(chol(A)) | |||
|
|||
@deprecate cummin(A, dim=1) accumulate(min, A, dim=1) | |||
@deprecate cummax(A, dim=1) accumulate(max, A, dim=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these need to be at the end of the file where 0.6 deprecations go, not in the middle of the 0.5 deprecations
edit: got it in #19415
Added accumulate, accumulate! see #14730.