Question

I would like to map fftw_complex array to Eigen MatrixXcd and back: I found this:

MatrixXcd m1 = MatrixXcd::Map(reinterpret_cast<complex<double>*>(m1f), n1, n2);

but seems to be slow

Was it helpful?

Solution

This should fix the performance problem:

MatrixXcd::Map<MatrixXcd> m1(reinterpret_cast<complex<double>*>(m1f), n1, n2);

The problem is that you assign the Map object to a Matrix object. This forces Eigen to copy the mapped matrix into the memory allocated by the Matrix object.

Additionally, you might want to consider using MatrixXcd::Map<MatrixXcd, Aligned>. This tells Eigen that the memory pointed to by m1f is properly aligned for vectorization. But of course you have to make sure that your memory is indeed properly aligned as required by Eigen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top