-
Notifications
You must be signed in to change notification settings - Fork 23
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
Define metal::accumulate for zero input lists #111
Conversation
@ecrypa would love your feedback on this. |
sigh. |
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.
include/metal/list/accumulate.hpp
Outdated
#include "../list/at.hpp" | ||
#include "../list/indices.hpp" |
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.
In the final version we should check for superfluous includes, right?
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.
(Somehow I missed this comment the first time around).
Absolutely, thanks for catching this one!
include/metal/list/accumulate.hpp
Outdated
template<class state, class vals> | ||
using impl = apply<partial<lbd, state>, vals>; | ||
|
||
using type = lambda<impl>; |
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.
Nice.
include/metal/list/accumulate.hpp
Outdated
template<class state, class... seqs> | ||
using type = | ||
forward<_accumulate_impl<state, seqs...>::template type, expr>; | ||
struct _accumulate<state, list<vals...>> { |
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 exist for performance reasons? I wonder if we can also increase performance for a total number of two, three, and, say, four seqs. I understand that fold_left
plays nicely with a single list, but maybe there is another shortcut if the number of seqs is known.
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.
Yes, by far the most common use case I expect to be accumulating a single list.
I wonder if we can also increase performance for a total number of two, three, and, say, four seqs.
We don't need to, that's the beauty of this version! Notice that it relies on transpose
, which already specializes on 1, 2 and 3 lists. That's probably why accumulate
got faster in your benchmark.
Wow nice, didn't expect that to be honest.
I hate MSVC with passion. |
5cba9f1
to
8a14ae0
Compare
8a14ae0
to
1146dda
Compare
While playing with this I realized |
Woah nice, thanks for checking! |
Speaking of accumulate I decided to have a look at it and realized it could be simplified if implemented in terms of
metal::transform
.