@@ -360,8 +360,8 @@ mapreduce_empty(::typeof(identity), op, T) = reduce_empty(op, T)
360
360
mapreduce_empty (:: typeof (abs), op, T) = abs (reduce_empty (op, T))
361
361
mapreduce_empty (:: typeof (abs2), op, T) = abs2 (reduce_empty (op, T))
362
362
363
- mapreduce_empty (f :: typeof (abs), :: typeof (max), T) = abs (zero (T))
364
- mapreduce_empty (f :: typeof (abs2), :: typeof (max), T) = abs2 (zero (T))
363
+ mapreduce_empty (:: typeof (abs), :: typeof (max), T) = abs (zero (T))
364
+ mapreduce_empty (:: typeof (abs2), :: typeof (max), T) = abs2 (zero (T))
365
365
366
366
# For backward compatibility:
367
367
mapreduce_empty_iter (f, op, itr, ItrEltype) =
@@ -412,6 +412,10 @@ mapreduce_first(f, op, x) = reduce_first(op, f(x))
412
412
413
413
_mapreduce (f, op, A:: AbstractArrayOrBroadcasted ) = _mapreduce (f, op, IndexStyle (A), A)
414
414
415
+ _mapreduce (f, op, A:: AbstractVector ) = _mapreduce (f, op, IndexLinear (), A)
416
+
417
+ _mapreduce (f, op, A:: AbstractZeroDimArray ) = mapreduce_first (f, op, A[])
418
+
415
419
function _mapreduce (f, op, :: IndexLinear , A:: AbstractArrayOrBroadcasted )
416
420
inds = LinearIndices (A)
417
421
n = length (inds)
437
441
438
442
mapreduce (f, op, a:: Number ) = mapreduce_first (f, op, a)
439
443
440
- _mapreduce (f, op, :: IndexCartesian , A:: AbstractArrayOrBroadcasted ) = mapfoldl (f, op, A)
444
+ function _mapreduce (f, op, :: IndexCartesian , A:: AbstractArrayOrBroadcasted )
445
+ (isempty (A) || length (axes1 (A)) < 16 ) && return mapfoldl (f, op, A)
446
+ mapfoldl (op, CartesianIndices (tail (axes (A)))) do IA
447
+ @inline elf (i) = @inbounds f (A[i, IA])
448
+ ax1 = axes1 (A)
449
+ mapreduce_impl (elf, op, ax1, firstindex (ax1), lastindex (ax1))
450
+ end
451
+ end
441
452
442
453
"""
443
454
reduce(op, itr; [init])
0 commit comments