@@ -151,6 +151,23 @@ function reducedim_init(f::F, op::Union{typeof(min),typeof(max)}, A::AbstractArr
151
151
return map! (f, reducedim_initarray (A,region,_InitialValue (),Tr), A1)
152
152
end
153
153
154
+ function reducedim_init (f:: ExtremaMap , op:: typeof (_extrema_rf), A:: AbstractArray , region)
155
+ ri = reduced_indices (A, region)
156
+ any (i -> isempty (axes (A, i)), region) && _empty_reduce_error ()
157
+ A1 = view (A, ri... )
158
+ T = _return_type (f. f, Tuple{eltype (A)})
159
+ if isempty (A) || (isconcretetype (nonmissingtype (T)) &&
160
+ T === _return_type (min, Tuple{T,T}) &&
161
+ T === _return_type (max, Tuple{T,T}) )
162
+ Tr = T isa Union ? Union{NTuple{2 ,T. a},NTuple{2 ,T. b}} : NTuple{2 ,T}
163
+ return map! (f, reducedim_initarray (A,region,_InitialValue (),Tr), A1)
164
+ end
165
+ v0 = mapreduce (f, op, A1) # Try to reduce A1
166
+ T = _realtype (f. f, promote_union (eltype (A))) # A possible wrong guess.
167
+ Tr = v0 isa NTuple{2 ,T} ? NTuple{2 ,T} : typeof (v0) # If NTuple{2,T} is wrong. Use typeof(v0) instead.
168
+ return map! (f, reducedim_initarray (A,region,_InitialValue (),Tr), A1)
169
+ end
170
+
154
171
reducedim_init (f:: Union{typeof(abs),typeof(abs2)} , op:: typeof (max), A:: AbstractArray{T} , region) where {T} =
155
172
reducedim_initarray (A, region, zero (f (zero (T))), _realtype (f, T))
156
173
0 commit comments