-
-
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
sum(f, itr; init)
slower than sum(f, itr)
#47216
Comments
the fast path f(n) = Base._mapreduce_dim(i->4/(4i-2n-3), Base.add_sum, Base._InitialValue(), 1:n, :)
## so totally different path
_mapreduce_dim(f, op, ::_InitialValue, A::AbstractArrayOrBroadcasted, ::Colon) =
_mapreduce(f, op, IndexStyle(A), A)
for array longer than 16, eventually calls: mapreduce_impl(f, op, A, first(inds), last(finds))
mapreduce_impl(f, op, A::AbstractArrayOrBroadcasted, ifirst::Integer, ilast::Integer, blksize=1024)
the slow path: g(n) = Base.mapfoldl_impl(i->4/(4i-2n-3), Base.add_sum, Base._InitialValue(), 1:n) |
Our g_fast(n) = @fastmath mapfoldl(i -> 4/(4i-2n-3), +, 1:n) In fact |
Let me repeat my suggestion from #49763:
In order to extend this to
For example, the function
vectorizes, but it doesn't always return
|
In https://github.com/niklas-heer/speed-comparison we noticed that
sum(f, itr; init)
is slower thansum(f, itr)
which is a pity because
sum(f, itr; init)
can be statically compiled, whilesum(f, itr)
cannot (because of some internal function throwing).The text was updated successfully, but these errors were encountered: