diff --git a/kissfft.hh b/kissfft.hh index 1e40dcf..2508750 100644 --- a/kissfft.hh +++ b/kissfft.hh @@ -4,14 +4,20 @@ namespace kissfft_utils { - -template +template struct traits { - void fill_twiddles( std::complex * dst ,int nfft,bool inverse); + typedef T_scalar scalar_type; + typedef std::complex cpx_type; + void fill_twiddles( std::complex * dst ,int nfft,bool inverse) + { + T_scalar phinc = (inverse?2:-2)* acos( (T_scalar) -1) / nfft; + for (int i=0;i(0,i*phinc) ); + } void prepare( - std::vector< std::complex > & dst, + std::vector< std::complex > & dst, int nfft,bool inverse, std::vector & stageRadix, std::vector & stageRemainder ) @@ -38,33 +44,20 @@ struct traits stageRemainder.push_back(n); }while(n>1); } + //const std::complex twiddle(int i) { return _twiddle[i]; } }; -template -void traits::fill_twiddles( std::complex * dst ,int nfft,bool inverse) -{ - T_twid phinc = (inverse?2:-2)* acos( (T_twid) -1) / nfft; - for (int i=0;i(0,i*phinc) ); -} -/* -template <> -void traits::fill_twiddles(std::complex * dst ,int nfft,bool inverse) -{ - long double phinc = (inverse?2:-2)*3.14159265358979323846264338327950288419716939937510L / nfft; - for (int i=0;i(cosl(i*phinc),sinl(i*phinc)); -} -*/ } -template > +template + > class kissfft { public: typedef T_traits traits_type; - typedef T_Data scalar_type; - typedef std::complex cpx_type; + typedef typename traits_type::scalar_type scalar_type; + typedef typename traits_type::cpx_type cpx_type; kissfft(int nfft,bool inverse,const traits_type & traits=traits_type() ) :_nfft(nfft),_inverse(inverse),_traits(traits) @@ -118,7 +111,7 @@ class kissfft void C_MUL( cpx_type & c,const cpx_type & a,const cpx_type & b) { c=a*b;} void C_SUB( cpx_type & c,const cpx_type & a,const cpx_type & b) { c=a-b;} void C_ADDTO( cpx_type & c,const cpx_type & a) { c+=a;} - void C_FIXDIV( cpx_type & c,int n) {} // NO-OP for float types + void C_FIXDIV( cpx_type & ,int ) {} // NO-OP for float types scalar_type S_MUL( const scalar_type & a,const scalar_type & b) { return a*b;} scalar_type HALF_OF( const scalar_type & a) { return a*.5;} void C_MULBYSCALAR(cpx_type & c,const scalar_type & a) {c*=a;} @@ -215,7 +208,7 @@ class kissfft void kf_bfly5( cpx_type * Fout, const size_t fstride, const size_t m) { cpx_type *Fout0,*Fout1,*Fout2,*Fout3,*Fout4; - int u; + size_t u; cpx_type scratch[13]; cpx_type * twiddles = &_twiddles[0]; cpx_type *tw; diff --git a/test/Makefile b/test/Makefile index 62fe2d0..5ac928a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -102,4 +102,4 @@ testcpp: testcpp.cc ../kissfft.hh clean: - rm -f *~ bm_* st_* tr_* kf_* tkfc_* ff_* ffr_* *.pyc *.pyo *.dat + rm -f *~ bm_* st_* tr_* kf_* tkfc_* ff_* ffr_* *.pyc *.pyo *.dat testcpp diff --git a/test/testcpp.cc b/test/testcpp.cc index 3fb2576..8dc3731 100644 --- a/test/testcpp.cc +++ b/test/testcpp.cc @@ -20,23 +20,16 @@ void dotest(int nfft) typedef kissfft FFT; typedef std::complex cpx_type; - cout << typeid(T).name() << ":nfft=" << nfft < inbuf(nfft); vector outbuf(nfft); -#if 0 - for (int k=0;k dif = acc - x; difpower += norm(dif); } - cout << "RMSE:" << sqrt(difpower/totalpower) << "\t"; + cout << " RMSE:" << sqrt(difpower/totalpower) << "\t"; double t0 = curtime(); int nits=20e6/nfft; @@ -61,16 +54,20 @@ void dotest(int nfft) fft.transform( &inbuf[0] , &outbuf[0] ); } double t1 = curtime(); - cout << "MSPS:" << ( (nits*nfft)*1e-6/ (t1-t0) ) << endl; + cout << " MSPS:" << ( (nits*nfft)*1e-6/ (t1-t0) ) << endl; } int main(int argc,char ** argv) { - dotest(32); - dotest(32); - dotest(32); - - dotest(1024); dotest(1024); dotest(1024); - dotest(1800); dotest(1800); dotest(1800); + if (argc>1) { + for (int k=1;k(nfft); dotest(nfft); dotest(nfft); + } + }else{ + dotest(32); dotest(32); dotest(32); + dotest(1024); dotest(1024); dotest(1024); + dotest(1800); dotest(1800); dotest(1800); + } return 0; }