-
-
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
Optimized methods for mapreduce(f, vcat, xs)
and mapreduce(f, hcat, xs)
#31137
Comments
Should be quite trivial to do indeed by dispatching on |
That would not be useful.
Or even say
|
Unfortunately, I'm afraid that allowing any |
Seems fine to me. The following matches the signature used by
|
Looks fine. For |
I just bumped into this. It would definitely be nice to have |
It's not precisely parallel, but many uses of this would be served by #43334. If |
Note that we also didn't optimize julia> v = [rand(1:10, rand(0:10)) for _ in 1:100];
julia> @btime reduce(vcat, $v, init=Int[]);
23.151 μs (101 allocations: 210.23 KiB)
julia> @btime reduce(vcat, $v);
962.444 ns (2 allocations: 5.12 KiB) so clearly we didn't override a low-level enough method. |
The keyword In this case it looks like it's being used to handle the empty case. Possibly #27188 should just allow that, when the type is known: julia> empty(v)
Vector{Int64}[]
julia> reduce(vcat, empty(v), init=Int[])
Int64[]
julia> reduce(vcat, empty(v))
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
[1] reduce_empty(op::Base.MappingRF{typeof(eltype), typeof(promote_type)}, #unused#::Type{Vector{Int64}}) |
given we had #21672
which makes
reduce(vcat
andreduce(hcat
fast.I had assumed it also applied to
mapreduce
of these operations.But it clearly does not.
Right now, if the 2nd arg is
vcat
orhcat
it is faster to callreduce(op, map(f, xs))
thanmapreduce(f, op, xs)
.And maybe that would be a solid first move to fix this.
The text was updated successfully, but these errors were encountered: