Consider:
julia> ifelse.([true, false], [1,2], [3.0,4.5])
2-element Vector{Real}:
1
4.5
This isn’t ideal; in this case clearly a concrete eltype would be better. I know I can write it as float.(ifelse.(...))
to solve this particular problem, but I’m curious to know if there’s a general solution through the broadcasting machinery. We have a macro that uses @.
over user-written expressions that contain ifelse
, and the goal is to end up with a concretely typed output without asking the user to change their code.
Alternatively, is there an efficient Base function that promotes all values in an Array to a concrete type? promote_to_same_type(Any[1,2,9.4])
that yields [1.0,2.0,9.4]
?