@@ -316,10 +316,11 @@ pairwise_blocksize(::typeof(abs2), ::typeof(+)) = 4096
316
316
317
317
318
318
# handling empty arrays
319
- _empty_reduce_error () = throw (ArgumentError (" reducing over an empty collection is not allowed" ))
320
- _empty_reduce_error (@nospecialize (f), @nospecialize (T:: Type )) = throw (ArgumentError ("""
321
- reducing with $f over an empty collection of element type $T is not allowed.
322
- You may be able to prevent this error by supplying an `init` value to the reducer.""" ))
319
+ _empty_reduce_error () = throw (ArgumentError (" reducing over an empty collection is not allowed; consider supplying `init` to the reducer" ))
320
+ reduce_empty (f, T) = _empty_reduce_error ()
321
+ mapreduce_empty (f, op, T) = _empty_reduce_error ()
322
+ reduce_empty (f, :: Type{Union{}} , splat... ) = _empty_reduce_error ()
323
+ mapreduce_empty (f, op, :: Type{Union{}} , splat... ) = _empty_reduce_error ()
323
324
324
325
"""
325
326
Base.reduce_empty(op, T)
@@ -339,20 +340,16 @@ is generally ambiguous, and especially so when the element type is unknown).
339
340
340
341
As an alternative, consider supplying an `init` value to the reducer.
341
342
"""
342
- reduce_empty (:: typeof (+ ), :: Type{Union{}} ) = _empty_reduce_error (+ , Union{})
343
343
reduce_empty (:: typeof (+ ), :: Type{T} ) where {T} = zero (T)
344
344
reduce_empty (:: typeof (+ ), :: Type{Bool} ) = zero (Int)
345
- reduce_empty (:: typeof (* ), :: Type{Union{}} ) = _empty_reduce_error (* , Union{})
346
345
reduce_empty (:: typeof (* ), :: Type{T} ) where {T} = one (T)
347
346
reduce_empty (:: typeof (* ), :: Type{<:AbstractChar} ) = " "
348
347
reduce_empty (:: typeof (& ), :: Type{Bool} ) = true
349
348
reduce_empty (:: typeof (| ), :: Type{Bool} ) = false
350
349
351
- reduce_empty (:: typeof (add_sum), :: Type{Union{}} ) = _empty_reduce_error (add_sum, Union{})
352
350
reduce_empty (:: typeof (add_sum), :: Type{T} ) where {T} = reduce_empty (+ , T)
353
351
reduce_empty (:: typeof (add_sum), :: Type{T} ) where {T<: SmallSigned } = zero (Int)
354
352
reduce_empty (:: typeof (add_sum), :: Type{T} ) where {T<: SmallUnsigned } = zero (UInt)
355
- reduce_empty (:: typeof (mul_prod), :: Type{Union{}} ) = _empty_reduce_error (mul_prod, Union{})
356
353
reduce_empty (:: typeof (mul_prod), :: Type{T} ) where {T} = reduce_empty (* , T)
357
354
reduce_empty (:: typeof (mul_prod), :: Type{T} ) where {T<: SmallSigned } = one (Int)
358
355
reduce_empty (:: typeof (mul_prod), :: Type{T} ) where {T<: SmallUnsigned } = one (UInt)
@@ -753,7 +750,7 @@ julia> maximum([1,2,3])
753
750
3
754
751
755
752
julia> maximum(())
756
- ERROR: MethodError : reducing over an empty collection is not allowed; consider supplying `init` to the reducer
753
+ ERROR: ArgumentError : reducing over an empty collection is not allowed; consider supplying `init` to the reducer
757
754
Stacktrace:
758
755
[...]
759
756
@@ -785,7 +782,7 @@ julia> minimum([1,2,3])
785
782
1
786
783
787
784
julia> minimum([])
788
- ERROR: MethodError : reducing over an empty collection is not allowed; consider supplying `init` to the reducer
785
+ ERROR: ArgumentError : reducing over an empty collection is not allowed; consider supplying `init` to the reducer
789
786
Stacktrace:
790
787
[...]
791
788
0 commit comments