// This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // // Copyright (C) 2009 Mark Borgerding mark a borgerding net // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #include "main.h" #include using namespace std; float norm(float x) {return x*x;} double norm(double x) {return x*x;} long double norm(long double x) {return x*x;} template < typename T> complex promote(complex x) { return complex(x.real(),x.imag()); } complex promote(float x) { return complex( x); } complex promote(double x) { return complex( x); } complex promote(long double x) { return complex( x); } template long double fft_rmse( const VectorType1 & fftbuf,const VectorType2 & timebuf) { long double totalpower=0; long double difpower=0; cerr <<"idx\ttruth\t\tvalue\t|dif|=\n"; long double pi = acos((long double)-1); for (int k0=0;k0 acc = 0; long double phinc = -2.*k0* pi / timebuf.size(); for (int k1=0;k1(0,k1*phinc) ); } totalpower += norm(acc); complex x = promote(fftbuf[k0]); complex dif = acc - x; difpower += norm(dif); cerr << k0 << "\t" << acc << "\t" << x << "\t" << sqrt(norm(dif)) << endl; } cerr << "rmse:" << sqrt(difpower/totalpower) << endl; return sqrt(difpower/totalpower); } template long double dif_rmse( const VectorType1& buf1,const VectorType2& buf2) { long double totalpower=0; long double difpower=0; int n = min( buf1.size(),buf2.size() ); for (int k=0;k struct VectorType; template struct VectorType { typedef vector type; }; template struct VectorType { typedef Matrix type; }; template void test_scalar_generic(int nfft) { typedef typename FFT::Complex Complex; typedef typename FFT::Scalar Scalar; typedef typename VectorType::type ScalarVector; typedef typename VectorType::type ComplexVector; FFT fft; ScalarVector inbuf(nfft); ComplexVector outbuf; for (int k=0;k>1)+1) ); VERIFY( fft_rmse(outbuf,inbuf) < test_precision() );// gross check fft.ClearFlag(fft.HalfSpectrum ); fft.fwd( outbuf,inbuf); VERIFY( fft_rmse(outbuf,inbuf) < test_precision() );// gross check ScalarVector buf3; fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision() );// gross check // verify that the Unscaled flag takes effect ComplexVector buf4; fft.SetFlag(fft.Unscaled); fft.inv( buf4 , outbuf); for (int k=0;k() );// gross check // verify that ClearFlag works fft.ClearFlag(fft.Unscaled); fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision() );// gross check } template void test_scalar(int nfft) { test_scalar_generic(nfft); test_scalar_generic(nfft); } template void test_complex_generic(int nfft) { typedef typename FFT::Complex Complex; typedef typename VectorType::type ComplexVector; FFT fft; ComplexVector inbuf(nfft); ComplexVector outbuf; ComplexVector buf3; for (int k=0;k() );// gross check fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision() );// gross check // verify that the Unscaled flag takes effect ComplexVector buf4; fft.SetFlag(fft.Unscaled); fft.inv( buf4 , outbuf); for (int k=0;k() );// gross check // verify that ClearFlag works fft.ClearFlag(fft.Unscaled); fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision() );// gross check } template void test_complex(int nfft) { test_complex_generic(nfft); test_complex_generic(nfft); } void test_FFT() { CALL_SUBTEST( test_complex(32) ); CALL_SUBTEST( test_complex(32) ); CALL_SUBTEST( test_complex(32) ); CALL_SUBTEST( test_complex(256) ); CALL_SUBTEST( test_complex(256) ); CALL_SUBTEST( test_complex(256) ); CALL_SUBTEST( test_complex(3*8) ); CALL_SUBTEST( test_complex(3*8) ); CALL_SUBTEST( test_complex(3*8) ); CALL_SUBTEST( test_complex(5*32) ); CALL_SUBTEST( test_complex(5*32) ); CALL_SUBTEST( test_complex(5*32) ); CALL_SUBTEST( test_complex(2*3*4) ); CALL_SUBTEST( test_complex(2*3*4) ); CALL_SUBTEST( test_complex(2*3*4) ); CALL_SUBTEST( test_complex(2*3*4*5) ); CALL_SUBTEST( test_complex(2*3*4*5) ); CALL_SUBTEST( test_complex(2*3*4*5) ); CALL_SUBTEST( test_complex(2*3*4*5*7) ); CALL_SUBTEST( test_complex(2*3*4*5*7) ); CALL_SUBTEST( test_complex(2*3*4*5*7) ); CALL_SUBTEST( test_scalar(32) ); CALL_SUBTEST( test_scalar(32) ); CALL_SUBTEST( test_scalar(32) ); CALL_SUBTEST( test_scalar(45) ); CALL_SUBTEST( test_scalar(45) ); CALL_SUBTEST( test_scalar(45) ); CALL_SUBTEST( test_scalar(50) ); CALL_SUBTEST( test_scalar(50) ); CALL_SUBTEST( test_scalar(50) ); CALL_SUBTEST( test_scalar(256) ); CALL_SUBTEST( test_scalar(256) ); CALL_SUBTEST( test_scalar(256) ); CALL_SUBTEST( test_scalar(2*3*4*5*7) ); CALL_SUBTEST( test_scalar(2*3*4*5*7) ); CALL_SUBTEST( test_scalar(2*3*4*5*7) ); }