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? |
base/deprecated.jl
Outdated
| @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.
cumop! wasn't exported, was it?
There was a problem hiding this comment.
Right, is the policy that only exported functions get deprecated? Should I remove this line?
There was a problem hiding this comment.
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 |
base/multidimensional.jl
Outdated
| """ | ||
| 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.
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. |
base/multidimensional.jl
Outdated
| ($fmod)(res, A, R1, R2, axis) | ||
| end | ||
| function accumulate_pairwise!(op, result::AbstractVector, v::AbstractVector) | ||
|
|
test/arrayops.jl
Outdated
| end | ||
| end | ||
|
|
||
| # exotic intexing |
base/multidimensional.jl
Outdated
| return s_ | ||
| end | ||
|
|
||
| function accumulate_pairwise!(op, result::AbstractVector, v::AbstractVector) |
There was a problem hiding this comment.
Does this need function accumulate_pairwise!{F}(op::F, result::AbstractVector, v::AbstractVector) Ref: #18207
There was a problem hiding this comment.
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.
Did you get any results? Same should apply to the function below?
There was a problem hiding this comment.
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 |
test/arrayops.jl
Outdated
| end | ||
| end | ||
|
|
||
| isdefined(:TestHelpers) || eval(Main, :(include(joinpath(dirname(@__FILE__), "TestHelpers.jl")))) |
There was a problem hiding this comment.
As noted, the isdefined check is wrong.
|
done |
|
|
|
The last hurdle. Then we dine in... er, I mean then we merge this PR! |
| * `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 |
NEWS.md
Outdated
| 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.
, 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.
typo here "situtations" has one too many t's
| @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.
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.