Can I promote complex number to float number arrays?

You’re looking for reinterpret:

julia> reinterpret(Float64, [1.0+2im, 33])
4-element reinterpret(Float64, ::Vector{ComplexF64}):
  1.0
  2.0
 33.0
  0.0

julia> reinterpret(reshape, Float64, [1.0+2im, 3-4im, 5])
2×3 reinterpret(reshape, Float64, ::Vector{ComplexF64}) with eltype Float64:
 1.0   3.0  5.0
 2.0  -4.0  0.0

If you use ForwardDiff with NLSolve, you will need to do something like reinterpret(complex(eltype(x)), x) rather than specify the exact type.

6 Likes