@@ -125,7 +125,7 @@ function _reducedim_init(f, op, fv, fop, A, region)
125
125
end
126
126
127
127
# initialization when computing minima and maxima requires a little care
128
- for (f1, f2, initval ) in ((:min , :max , :Inf ), (:max , :min , :( - Inf ) ))
128
+ for (f1, f2, typeextreme ) in ((:min , :max , :typemax ), (:max , :min , :typemin ))
129
129
@eval function reducedim_init (f, op:: typeof ($ f1), A:: AbstractArray , region)
130
130
# First compute the reduce indices. This will throw an ArgumentError
131
131
# if any region is invalid
@@ -145,14 +145,18 @@ for (f1, f2, initval) in ((:min, :max, :Inf), (:max, :min, :(-Inf)))
145
145
v0 = mapreduce (f, $ f2, A1)
146
146
147
147
T = _realtype (f, promote_union (eltype (A)))
148
+ Tr = v0 isa T ? T : typeof (v0)
148
149
149
150
# but NaNs and missing need to be avoided as initial values
150
151
if is_poisoning (v0)
151
- # Convert handles unions containing Missing nicely.
152
- v0 = convert (T, $ initval)
152
+ Tnm = nonmissingtype (Tr)
153
+ # TODO : Some types, like BigInt, don't support typemin/typemax.
154
+ # So a Matrix{Union{BigInt, Missing}} can still error here.
155
+ v0 = $ typeextreme (Tnm)
153
156
end
154
-
157
+ # v0 may have changed type.
155
158
Tr = v0 isa T ? T : typeof (v0)
159
+
156
160
return reducedim_initarray (A, region, v0, Tr)
157
161
end
158
162
end
0 commit comments