I have an Vector of complex numbers and want to interpret it as a vector of real numbers with twice the length. Currently I allocate a new vector and then manually fill it, but I wonder if there is a faster way without reallocations since I suspect, that the data is already stored in exactly the desired way.

My current implementation:

function realize(v::AbstractVector{Complex{T}}) where {T}
v_real = Array{T}(undef, 2 *length(v))
@inbounds for i in eachindex(v)
v_real[2i-1], v_real[2i] = real(v[i]), imag(v[i])
end
return v_real
end

Is there a way to get the same v_real by simple typecasting?

Starting with Julia 1.6, you’ll get considerably better performance on certain operations if you use reinterpret(reshape, Float64, x). That’s available to earlier versions via Compat.jl, but it doesn’t help performance, just API compatibility.