This forum has been archived. All content is frozen. Please use KDE Discuss instead.

how can i convert cx_mat to double[] array?

Tags: None
(comma "," separated)
smallku
Registered Member
Posts
1
Karma
0
I have one cx_mat, "cx_mat X" ,i need convert X.real() to double xr[], and X.imag() to double xi[], how can i do it fastly?
Thank you
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
What is cx_mat? Anyway, assuming it's equivalent to a MatrixXcd, if you want to extract the real and imaginary part as sequential buffers, then you first need to copy them to MatrixXd:

MatrixXcd X;
MatrixXd R, I;
R = X.real();
I = X.imag();
double* xr = R.data();
double* xi = I.data();

If you can deal with interleaved real/imag parts, then:

double* xr = &numext::real_ref(X(0,0));
double* xi = xr+1;

and then:

i-th real part == xr[2*i]
i-th imag part == xi[2*i]


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft