@@ -627,6 +627,13 @@ isgoodzero(::typeof(min), x) = isbadzero(max, x)
627
627
628
628
function mapreduce_impl (f, op:: Union{typeof(max), typeof(min)} ,
629
629
A:: AbstractArrayOrBroadcasted , first:: Int , last:: Int )
630
+ # 1. This optimization gives different result from general fallback, if the inputs `f.(A)`
631
+ # contains both 'missing' and 'Nan'.
632
+ # 2. For Integer cases, general fallback seems faster.
633
+ # Based the above reasons, only use this for AbstractFloat cases.
634
+ Eltype = _return_type (i -> f (A[i]), Tuple{Int})
635
+ Eltype <: AbstractFloat ||
636
+ return invoke (mapreduce_impl,Tuple{Any,Any,AbstractArrayOrBroadcasted,Int,Int},f,op,A,first,last)
630
637
a1 = @inbounds A[first]
631
638
v1 = mapreduce_first (f, op, a1)
632
639
v2 = v3 = v4 = v1
@@ -635,10 +642,10 @@ function mapreduce_impl(f, op::Union{typeof(max), typeof(min)},
635
642
simdstop = start + chunk_len - 4
636
643
while simdstop <= last - 3
637
644
# short circuit in case of NaN or missing
638
- ( v1 == v1) === true || return v1
639
- ( v2 == v2) === true || return v2
640
- ( v3 == v3) === true || return v3
641
- ( v4 == v4) === true || return v4
645
+ v1 == v1 || return v1
646
+ v2 == v2 || return v2
647
+ v3 == v3 || return v3
648
+ v4 == v4 || return v4
642
649
@inbounds for i in start: 4 : simdstop
643
650
v1 = _fast (op, v1, f (A[i+ 0 ]))
644
651
v2 = _fast (op, v2, f (A[i+ 1 ]))
0 commit comments