title: Interfacing Armadillo with FFTW
body: <p>I am trying to use FFTW in the matrix of Armadillo package. I need to perform N independent FFT on a 2D matrix. Following the manual of FFTW and other resource online, I have the following code:</p>
  
  <pre><code>#include &lt;armadillo&gt;
  #include &lt;iostream&gt;
  #include "fftw3.h"
  
  using namespace std;
  using namespace arma;
  
  fftw_plan fplan;
  
  int main(int argc, char *argv[])
  {
    cx_mat psi;
    int NCOL=2, NROW=4;
    int frank=1;
    int howmany=NCOL;
    int n[]={NROW};         
    int idist=NROW, odist=NROW; 
    int istride=1, ostride=1;
    int *inembed=n, *onembed=n;
  
    psi.resize(NROW, NCOL);
    psi(0,0)=cx_double(1,1); psi(0,1)=cx_double(1,1);
    psi(1,0)=cx_double(2,1); psi(1,1)=cx_double(1,2);
    psi(2,0)=cx_double(3,1); psi(2,1)=cx_double(1,3);
    psi(3,0)=cx_double(4,1); psi(3,1)=cx_double(1,4);
    cout &lt;&lt; psi &lt;&lt; endl; // the output is correct at here
  
    fftw_complex* in = reinterpret_cast&lt;fftw_complex*&gt;(psi.memptr());
  
    fplan = fftw_plan_many_dft(frank, n, howmany,
                               in, inembed, istride, idist,
                               in, onembed, ostride, odist,
                               FFTW_FORWARD, FFTW_MEASURE);
  
    cout &lt;&lt; endl &lt;&lt; "after fftw plan: " &lt;&lt; endl &lt;&lt; psi &lt;&lt; endl; // all zeros
  
    // fftw_execute(fplan); // output zeros again if execute
    cx_double* A_mem=psi.memptr();
    cout &lt;&lt; endl &lt;&lt; "by reference: " &lt;&lt; endl &lt;&lt; *A_mem &lt;&lt; " " &lt;&lt; *(A_mem+1) &lt;&lt; endl;
  
    return 0;
  }
  </code></pre>
  
  <p>The code compiles without any error. But if I run the code, after fftw_plan_many_dft, it outputs all zeroes instead. If I remove fftw_plan_many_dft, the output is correct. I don't even execute the fftw plan so why it clean my data by just setting up the plan? </p>