1D FFT of Eigen matrix along rows not working
I was asked (from stackoverflow) to report this to the Eigen project as a possible issue or bug.
I have seen few examples on Eigen FFT library that I wanted to implement before moving on FFTW library. For some reason I am unable to get the correct 1D FFT along each row of an Eigen matrix. I get the 1D FFT along each column correctly, but not rows. I am comparing a very very simple C++ code with MATLAB for clarity.
In MATLAB:
Nx=8;
Ny=8;
u = eye(Ny+1,Nx); %very simple choice for now
%take FFT along columns
ucol = fft(u,[],1);
urow = fft(u,[],2);`
In C++ with Eigen:
#include <unsupported/Eigen/FFT>
#include <iostream>
static const int nx=8;
static const int ny=8;
using namespace std;
using namespace Eigen;
int main() {
Eigen::FFT<double> fft;
Eigen::MatrixXcd u(ny+1,nx);
u.setIdentity();
//1D FFT along cols
Eigen::MatrixXcd ucol(ny+1,nx);
for (int k=0; k<u.cols(); k++){
ucol.col(k) = fft.fwd(u.col(k));
}
std::cout<<ucol<<endl; //correct compared to MATLAB: ucol = fft(u,[],1);
//1D FFT along rows
Eigen::MatrixXcd urow(ny+1,nx);
for (int k=0; k<u.rows(); k++){
urow.row(k) = fft.fwd(u.row(k));
}
std::cout<<urow<<endl; //**Incorrect** compared to MATLAB: urow = fft(u,[],2);
return 0;
}
Results of urow from C++ are strange and do not match MATLAB's output. All values of each row are zero except the first one, as if it's writing only the first value of the result back into the array. Could this be a bug? Thanks.
Edited by Antonio Sánchez