-
-
Notifications
You must be signed in to change notification settings - Fork 743
Add std.algorithm.iteration.cumulativeFold #3972
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
Add std.algorithm.iteration.cumulativeFold #3972
Conversation
This seems to be a rather useful function, but |
Actually I find the name quite good. It is already used in haskell [1] and C++ [2] seams to adopt it also. |
5eac01f
to
a38bcd8
Compare
Thanks for the contribution. I don't have bandwidth for it just now, but I'll note that the name does not do it justice. I'd already forgotten what the algorithm does (something with partial sums) and the name definitely didn't remind me of anything, maybe except... FoxPro :o). |
On wikipedia it is called "prefix sum", "scan" or "cumulative sum". Considering the generic implementation, I think that the name that does not contain the word "sum" is the better one :). |
312f221
to
19ff3cb
Compare
What about |
assert(sum2.array == [1, 3, 6, 10, 15]); | ||
|
||
// Compute the maximum of all elements | ||
auto largest = scan!(max)(arr); |
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.
Examples should use single-token template argument list instantiation shortcut: scan!max(arr)
edit:
Oh, this isn't actually an example unit test... was that intentional? It's full of the kind of redundancies I'd expect from an example and not a traditional unit test.
The implementation should propagate forward range capability and the tests should test more kinds of ranges than just slices; see std.internal.test.dummyrange for helpers. |
|
||
) | ||
|
||
$(BUGSTITLE Library Changes, | ||
|
||
$(LI $(LNAME2 std-algorithm-iteration-scan, $(XREF algorithm.iterator, 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.
XREF
doesn't work like this. Please use $(REF scan, std, algorithm, iteration)
I think the documentation would be better if the overloads were consolidated in one place with |
f205f96
to
942aecb
Compare
@quickfur: considering that the function is called on each iteration, I think that a "verb" name is more appropriate. Moreover |
5cc297a
to
883d093
Compare
I suggest we call this something with fold in the name (assuming we're committed to renaming |
I vote for |
@greenify I like that name. Thanks! |
|
67ca912
to
b1c564a
Compare
That works too. |
|
72dcb3c
to
d6ca72e
Compare
146dfe3
to
453ea69
Compare
@andralex are you ok with |
Needs the @andralex tag for name review! |
453ea69
to
dd2f60c
Compare
Ping @andralex |
dd2f60c
to
35e6a83
Compare
35e6a83
to
1030e87
Compare
I just accidentally ended up implementing this myself, because I forgot about the PR and obviously there were no docs yet :/ Btw in Scala this is called |
Actually the original name of this function was |
Please don't, there's hope: |
I prefer that, it's like STL's |
it returns the first element unchanged and uses it as seed for the next | ||
elements. | ||
This function is also known as `partial_sum`, `accumulate`, `prefix_sum`, | ||
`scan`, or `cumulative_sum`. |
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.
Making some or all of these names hot links would be great.
Thanks for this solid piece of work. I approve the addition, please pull once the nits are looked at. |
1030e87
to
74fbbac
Compare
Thank you for the review! All comments were addressed. |
74fbbac
to
984fbb4
Compare
So we are good to go here? :) |
Auto-merge toggled on |
This PR implements
std.algorithm.iteration.scan
.http://forum.dlang.org/post/n8gini$1ibc$1@digitalmars.com
http://en.cppreference.com/w/cpp/algorithm/partial_sum