Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote vs to a Union{Bool, ...} whenever a Boolean value is present #2237

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ function promote_to_concrete(vs; tofloat = true, use_union = false)
I = Int8
has_int = false
has_array = false
has_bool = false
array_T = nothing
for v in vs
if v isa AbstractArray
Expand All @@ -692,16 +693,22 @@ function promote_to_concrete(vs; tofloat = true, use_union = false)
has_int = true
I = promote_type(I, E)
end
if E <: Bool
has_bool = true
end
end
if tofloat && !has_array
if tofloat && !has_array && !has_bool
C = float(C)
elseif has_array || (use_union && has_int && C !== I)
elseif has_array || (use_union && has_int && C !== I) || has_bool
if has_array
C = Union{C, array_T}
end
if has_int
C = Union{C, I}
end
if has_bool
C = Union{C, Bool}
end
return copyto!(similar(vs, C), vs)
end
convert.(C, vs)
Expand Down