Promoting a broadcasted array

Linking related old post.

FWIW, the following promote_array() function, inspired by the code above, seems to run a bit faster:

promote_array(v) = convert(Array{eltype(promote(map(zero, unique(typeof(v) for v in v))...))}, v)

v = rand((1, 4.5), 100_000)
promote_array(v)
@btime promote_array($v)  # 3.6 ms (99526 allocs: 2.28 MiB)
1 Like