22
33# GPUArrays' mapreduce methods build on `Base.mapreducedim!`, but with an additional
44# argument `init` value to avoid eager initialization of `R` (if set to something).
5- mapreducedim! (f, op, R:: AbstractGPUArray , A :: AbstractArray , init= nothing ) = error (" Not implemented" ) # COV_EXCL_LINE
5+ mapreducedim! (f, op, R:: AbstractGPUArray , As :: AbstractArray... ; init= nothing ) = error (" Not implemented" ) # COV_EXCL_LINE
66Base. mapreducedim! (f, op, R:: AbstractGPUArray , A:: AbstractArray ) = mapreducedim! (f, op, R, A)
77
88neutral_element (op, T) =
@@ -18,11 +18,11 @@ neutral_element(::typeof(Base.mul_prod), T) = one(T)
1818neutral_element (:: typeof (Base. min), T) = typemax (T)
1919neutral_element (:: typeof (Base. max), T) = typemin (T)
2020
21- function Base. mapreduce (f, op, A :: AbstractGPUArray ; dims= :, init= nothing )
21+ function Base. mapreduce (f, op, As :: AbstractGPUArray... ; dims= :, init= nothing )
2222 # figure out the destination container type by looking at the initializer element,
2323 # or by relying on inference to reason through the map and reduce functions.
2424 if init === nothing
25- ET = Base. promote_op (f, eltype (A) )
25+ ET = Base. promote_op (f, map (eltype, As) ... )
2626 ET = Base. promote_op (op, ET, ET)
2727 (ET === Union{} || ET === Any) &&
2828 error (" mapreduce cannot figure the output element type, please pass an explicit init value" )
@@ -32,10 +32,14 @@ function Base.mapreduce(f, op, A::AbstractGPUArray; dims=:, init=nothing)
3232 ET = typeof (init)
3333 end
3434
35+ # TODO : Broadcast-semantics after JuliaLang-julia#31020
36+ A = first (As)
37+ all (B -> size (A) == size (B), As) || throw (DimensionMismatch (" dimensions of containers must be identical" ))
38+
3539 sz = size (A)
3640 red = ntuple (i-> (dims== Colon () || i in dims) ? 1 : sz[i], ndims (A))
3741 R = similar (A, ET, red)
38- mapreducedim! (f, op, R, A, init)
42+ mapreducedim! (f, op, R, As ... ; init = init)
3943
4044 if dims== Colon ()
4145 @allowscalar R[]
0 commit comments