c++ – Error mapping fftw complex to Eigen matrix
I have the following code where I am using both libraries Eigen and FFTW in C++. I am aware of the unsuported FFT that Eigen has, but I am using the FFTW library for additional features. So, I am trying to take the FFT with a C++ array and then map the output to a complex Eigen matrix (to perform some linear algebra operations on it). I have the code:
struct cplx_buffer
{
fftw_complex* a;
int rows;
int cols;
fftw_complex& operator()(int i, int j) const { return a[i * cols + j]; }
};
struct real_buffer
{
double* a;
int rows;
int cols;
double& operator()(int i, int j) const { return a[i * cols + j]; }
};
int main(){
static const int nx = 10;
static const int ny = 10;
static const int nyk = ny/2 + 1;
static const int mm = nx* 3/2;
cplx_buffer outW = my_fftw_allocate_cplx((ny+1), mm);
real_buffer inW = my_fftw_allocate_real((ny+1), mm);
//initialize the input
for (int i = 0; i < ny+1; i++){
for (int j = 0; j < mm; j++){
inW(i,j) = //expression
}
}
//Take FFT of rows
{ // Transform all the rows
fftw_execute(fftw_plan_many_dft_r2c(1, &nx, inW.rows, inW.a, &inW.cols, 1, inW.cols, outW.a, &inW.cols, 1, outW.cols, FFTW_ESTIMATE));
}
Eigen::Map<Eigen::MatrixXcd, Eigen::Unaligned> invnek(*reinterpret_cast<fftw_complex*>(&outW),(ny+1),mm); //ERROR
}
The error:
no instance of constructor "Eigen::Map<PlainObjectType, MapOptions, StrideType>::Map [with PlainObjectType=Eigen::MatrixXcd, MapOptions=0, StrideType=Eigen::Stride<0, 0>]" matches the argument list
How can I reinterpret_cast
here correctly?
Read more here: Source link