@@ -1764,17 +1764,25 @@ function mapreduce_impl(f, ::typeof(_extrema_op), A::AbstractArrayOrBroadcasted,
1764
1764
Eltype = _return_type (elf, Tuple{Int})
1765
1765
Eltype <: NTuple{2,AbstractFloat} ||
1766
1766
return invoke (mapreduce_impl,Tuple{Any,Any,AbstractArrayOrBroadcasted,Int,Int},f,_extrema_op,A,fi,la)
1767
- v1 = v2 = v3 = v4 = Eltype ((Inf ,- Inf ))
1768
- iter = fi: 4 : la- 4
1769
- for i in iter
1770
- v1 = _extrema_op (v1, elf (i))
1771
- v2 = _extrema_op (v2, elf (i+ 1 ))
1772
- v3 = _extrema_op (v3, elf (i+ 2 ))
1773
- v4 = _extrema_op (v4, elf (i+ 3 ))
1767
+ v1 = v2 = v3 = v4 = elf (fi)
1768
+ len = (la - fi) >> 2
1769
+ i = fi
1770
+ for I in Iterators. partition (1 : len, 64 )
1771
+ for _ in I
1772
+ v1 = _extrema_op (v1, elf (i+= 1 ))
1773
+ v2 = _extrema_op (v2, elf (i+= 1 ))
1774
+ v3 = _extrema_op (v3, elf (i+= 1 ))
1775
+ v4 = _extrema_op (v4, elf (i+= 1 ))
1776
+ end
1777
+ # short circuit in case of NaN
1778
+ isnan (v1[1 ]) && return v1
1779
+ isnan (v2[1 ]) && return v2
1780
+ isnan (v3[1 ]) && return v3
1781
+ isnan (v4[1 ]) && return v4
1774
1782
end
1775
1783
v = _extrema_op (_extrema_op (v1, v2), _extrema_op (v3, v4))
1776
- for i in last (iter) + 4 : la
1777
- v = _extrema_op (v, elf (i))
1784
+ while i < la
1785
+ v = _extrema_op (v, elf (i+= 1 ))
1778
1786
end
1779
1787
v
1780
1788
end
0 commit comments