c++ - Using fftw with column major square matrices (armadillo library) -


i find armadillo c++ library convenient matrix computations. how 1 perform 2 dimensional fft on armadillo matrices using fftw library?

i understand armadillo matrix class stores data in column major order. how pass fftw? fftw 3.3.3 documentation says

if have array stored in column-major order , wish transform using fftw, quite easy do. when creating plan, pass dimensions of array planner in reverse order. example, if array rank 3 n x m x l matrix in column-major order, should pass dimensions of array if l x m x n matrix (which is, perspective of fftw)

i cannot understand means, given syntax creating plan follows.

fftw_plan fftw_plan_dft_2d(int n0, int n1,                             fftw_complex *in, fftw_complex *out,                             int sign, unsigned flags); 

could explain this?

it means can try both

  fftw_plan plan=fftw_plan_dft_2d(4, 2,(double(*)[2])&aaa(0,0), (double(*)[2])&bbb(0,0), fftw_forward, fftw_estimate); 

and

 fftw_plan plan=fftw_plan_dft_2d(2, 4,(double(*)[2])&aaa(0,0), (double(*)[2])&bbb(0,0), fftw_forward, fftw_estimate); 

and keep correct order.

normally, in , out allocated fftw_malloc() keep aligned memory. little tests show case cx_mat matrix armadillo (no horrible segmentation fault or wrong values...).

here test code (and correct order...) :

    #include <iostream> #include <fftw3.h> #include "armadillo"  using namespace arma; using namespace std;   int main(int argc, char** argv) {     cout << "armadillo version: " << arma_version::as_string() << endl;       cx_mat aaa = eye<cx_mat>(2,4);     aaa(0,0)=0;     aaa(0,1)=1;     aaa(0,2)=2;     aaa(0,3)=3;      aaa(1,0)=0;     aaa(1,1)=1;     aaa(1,2)=2;     aaa(1,3)=3;       cx_mat bbb = eye<cx_mat>(2,4);      fftw_plan plan=fftw_plan_dft_2d(4, 2,(double(*)[2])&aaa(0,0), (double(*)[2])&bbb(0,0), fftw_forward, fftw_estimate);      fftw_execute(plan);      bbb.print("bbb:");     return 0; } 

compile g++ -o2 -o example1 example1.cpp -larmadillo -llapack -lblas -lfftw3 !

bye,

francis


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -