Complex Number Arrays

question
embedding

#1

I can’t seem to find the struct for a complex number representation in Julia Embedding in C API.
Thank you.


#2

Complex is essentially the same as complex numbers in C or C++: it is the real part followed by the imaginary part. So, for example, Complex{Float64} is the same in-memory format as the C99 double complex and the C++ std::complex<double>.


#3

Thank you for your reply. So, it’s the same the STL’s complex number. So, now how do I create Complex{Float64} type using C API? Like for an Array{Float64}, I call jl_apply_array_type(jl_float64_type, ndims) and use that to initialise the variable. I see a jl_complex_type but I don’t know how to specify which type of variable it stores.

EDIT:
I found the way to do it,

jl_value_t *type = (jl_value_t*) jl_apply_type((jl_value_t*)jl_complex_type, jl_svec1(jl_float64_type));
            
jl_value_t *ret = (jl_value_t*)jl_new_struct_uninit(type);
double complex *temp = (double complex*) ret;
*temp = data + (img_data * I);

Thank you.