Did some one use Eigen or Armadillo library to do calculation?
-
Now ,i have one question. I use library to define a matrix B, for example, as follows, how can i convert B.real() to a double[] array? thanks very much.
MatrixXcd B(n,3);
for( int i=0; iI did not have used it so far but it should be possible to copy the values to your array this way:
// A one-dimensional array
double *da = new double[n * 3];
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
da[i*3 + j] = B(i, j).real(); -
I did not have used it so far but it should be possible to copy the values to your array this way:
// A one-dimensional array
double *da = new double[n * 3];
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
da[i*3 + j] = B(i, j).real(); -
Thank you very much. My code is in Loop many times, so i want a efficient code. your code can reach my function,but efficient i think it's not good.
It is difficult to answer without knowing how the data are used. But a short web reserach found this: [EIGEN] How to get in and out data from Eigen matrix | Vlad's Blog[^]. So it seems that you can use
Map
to get a pointer to the complex values. That should be sufficient because the real part is stored first and therefore already at the specified index (when *p is a pointer to a complex array, p[n] and p[n].real() have the same address).