Skip to content

Commit 253a393

Browse files
committed
Use convert in reducedim_init
Thanks @nalimilan for the suggestion. This is simpler, more extensible and should handle larger unions.
1 parent dd5dcc8 commit 253a393

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

base/reducedim.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ for (f1, f2, initval) in ((:min, :max, :Inf), (:max, :min, :(-Inf)))
147147
T = _realtype(f, promote_union(eltype(A)))
148148

149149
# but NaNs and missing need to be avoided as initial values
150-
if (v0 != v0) === true
151-
v0 = typeof(v0)($initval)
152-
elseif ismissing(v0)
153-
# If it's a union type, pick the initval from the other type.
154-
if typeof(T) == Union
155-
v0 = (T.a == Missing ? T.b : T.a)($initval)
156-
end
150+
if is_poisoning(v0)
151+
# Convert handles unions containing Missing nicely.
152+
v0 = convert(T, $initval)
157153
end
158154

159155
Tr = v0 isa T ? T : typeof(v0)

0 commit comments

Comments
 (0)