Skip to content

Commit

Permalink
wip: multiple arguments to mapreduce
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Apr 3, 2019
1 parent aee211b commit 052d276
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ mapreduce_impl(f, op, A::AbstractArray, ifirst::Integer, ilast::Integer) =
mapreduce_impl(f, op, A, ifirst, ilast, pairwise_blocksize(f, op))

"""
mapreduce(f, op, itr; [init])
mapreduce(f, op, itrs...; [init])
Apply function `f` to each element in `itr`, and then reduce the result using the binary
Apply function `f` to each element(s) in `itrs`, and then reduce the result using the binary
function `op`. If provided, `init` must be a neutral element for `op` that will be returned
for empty collections. It is unspecified whether `init` is used for non-empty collections.
In general, it will be necessary to provide `init` to work with empty collections.
Expand All @@ -203,6 +203,7 @@ implementations may reuse the return value of `f` for elements that appear multi
guaranteed left or right associativity and invocation of `f` for every value.
"""
mapreduce(f, op, itr; kw...) = mapfoldl(f, op, itr; kw...)
mapreduce(f, op, itrs...; kw...) = reduce(op, Generator(f, itrs...); kw...)

# Note: sum_seq usually uses four or more accumulators after partial
# unrolling, so each accumulator gets at most 256 numbers
Expand Down
1 change: 1 addition & 0 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ julia> mapreduce(isodd, |, a, dims=1)
```
"""
mapreduce(f, op, A::AbstractArray; dims=:, kw...) = _mapreduce_dim(f, op, kw.data, A, dims)
mapreduce(f, op, A::AbstractArray...; kw...) = reduce(op, map(f, A...); kw...)

_mapreduce_dim(f, op, nt::NamedTuple{(:init,)}, A::AbstractArray, ::Colon) = mapfoldl(f, op, A; nt...)

Expand Down

0 comments on commit 052d276

Please sign in to comment.