1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library 2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra. 3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// 4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2009 Mark Borgerding mark a borgerding net 5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// 6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla 7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed 8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include "main.h" 11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include <unsupported/Eigen/FFT> 12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename T> 14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstd::complex<T> RandomCpx() { return std::complex<T>( (T)(rand()/(T)RAND_MAX - .5), (T)(rand()/(T)RAND_MAX - .5) ); } 15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathusing namespace std; 17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathusing namespace Eigen; 18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate < typename T> 212b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wangcomplex<long double> promote(complex<T> x) { return complex<long double>((long double)x.real(),(long double)x.imag()); } 22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 232b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wangcomplex<long double> promote(float x) { return complex<long double>((long double)x); } 242b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wangcomplex<long double> promote(double x) { return complex<long double>((long double)x); } 252b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wangcomplex<long double> promote(long double x) { return complex<long double>((long double)x); } 26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath template <typename VT1,typename VT2> 29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double fft_rmse( const VT1 & fftbuf,const VT2 & timebuf) 30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double totalpower=0; 32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double difpower=0; 33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double pi = acos((long double)-1 ); 34c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (size_t k0=0;k0<(size_t)fftbuf.size();++k0) { 35c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath complex<long double> acc = 0; 362b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang long double phinc = (long double)(-2.)*k0* pi / timebuf.size(); 37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (size_t k1=0;k1<(size_t)timebuf.size();++k1) { 38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath acc += promote( timebuf[k1] ) * exp( complex<long double>(0,k1*phinc) ); 39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 407faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez totalpower += numext::abs2(acc); 41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath complex<long double> x = promote(fftbuf[k0]); 42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath complex<long double> dif = acc - x; 437faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez difpower += numext::abs2(dif); 447faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez //cerr << k0 << "\t" << acc << "\t" << x << "\t" << sqrt(numext::abs2(dif)) << endl; 45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath cerr << "rmse:" << sqrt(difpower/totalpower) << endl; 47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath return sqrt(difpower/totalpower); 48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 49c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 50c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath template <typename VT1,typename VT2> 51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double dif_rmse( const VT1 buf1,const VT2 buf2) 52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double totalpower=0; 54c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath long double difpower=0; 55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath size_t n = (min)( buf1.size(),buf2.size() ); 56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (size_t k=0;k<n;++k) { 572b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang totalpower += (long double)((numext::abs2( buf1[k] ) + numext::abs2(buf2[k]) )/2); 582b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang difpower += (long double)(numext::abs2(buf1[k] - buf2[k])); 59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath return sqrt(difpower/totalpower); 61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathenum { StdVectorContainer, EigenVectorContainer }; 64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<int Container, typename Scalar> struct VectorType; 66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar> struct VectorType<StdVectorContainer,Scalar> 68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef vector<Scalar> type; 70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}; 71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar> struct VectorType<EigenVectorContainer,Scalar> 73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef Matrix<Scalar,Dynamic,1> type; 75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}; 76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <int Container, typename T> 78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_scalar_generic(int nfft) 79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename FFT<T>::Complex Complex; 81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename FFT<T>::Scalar Scalar; 82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename VectorType<Container,Scalar>::type ScalarVector; 83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename VectorType<Container,Complex>::type ComplexVector; 84c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath FFT<T> fft; 86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ScalarVector tbuf(nfft); 87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ComplexVector freqBuf; 88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<nfft;++k) 89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath tbuf[k]= (T)( rand()/(double)RAND_MAX - .5); 90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // make sure it DOESN'T give the right full spectrum answer 92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // if we've asked for half-spectrum 93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.SetFlag(fft.HalfSpectrum ); 94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd( freqBuf,tbuf); 95c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY((size_t)freqBuf.size() == (size_t)( (nfft>>1)+1) ); 962b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(fft_rmse(freqBuf,tbuf)) < test_precision<T>() );// gross check 97c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 98c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.ClearFlag(fft.HalfSpectrum ); 99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd( freqBuf,tbuf); 100c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (size_t)freqBuf.size() == (size_t)nfft); 1012b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(fft_rmse(freqBuf,tbuf)) < test_precision<T>() );// gross check 102c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 103c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath if (nfft&1) 104c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath return; // odd FFTs get the wrong size inverse FFT 105c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 106c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ScalarVector tbuf2; 107c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( tbuf2 , freqBuf); 1082b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(tbuf,tbuf2)) < test_precision<T>() );// gross check 109c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 110c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 111c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // verify that the Unscaled flag takes effect 112c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ScalarVector tbuf3; 113c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.SetFlag(fft.Unscaled); 114c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 115c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( tbuf3 , freqBuf); 116c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 117c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<nfft;++k) 118c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath tbuf3[k] *= T(1./nfft); 119c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 120c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 121c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath //for (size_t i=0;i<(size_t) tbuf.size();++i) 122c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // cout << "freqBuf=" << freqBuf[i] << " in2=" << tbuf3[i] << " - in=" << tbuf[i] << " => " << (tbuf3[i] - tbuf[i] ) << endl; 123c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1242b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(tbuf,tbuf3)) < test_precision<T>() );// gross check 125c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 126c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // verify that ClearFlag works 127c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.ClearFlag(fft.Unscaled); 128c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( tbuf2 , freqBuf); 1292b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(tbuf,tbuf2)) < test_precision<T>() );// gross check 130c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 131c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 132c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename T> 133c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_scalar(int nfft) 134c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 135c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath test_scalar_generic<StdVectorContainer,T>(nfft); 136c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath //test_scalar_generic<EigenVectorContainer,T>(nfft); 137c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 138c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 139c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 140c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <int Container, typename T> 141c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_complex_generic(int nfft) 142c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 143c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename FFT<T>::Complex Complex; 144c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename VectorType<Container,Complex>::type ComplexVector; 145c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 146c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath FFT<T> fft; 147c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 148c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ComplexVector inbuf(nfft); 149c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ComplexVector outbuf; 150c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ComplexVector buf3; 151c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<nfft;++k) 152c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath inbuf[k]= Complex( (T)(rand()/(double)RAND_MAX - .5), (T)(rand()/(double)RAND_MAX - .5) ); 153c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd( outbuf , inbuf); 154c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1552b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(fft_rmse(outbuf,inbuf)) < test_precision<T>() );// gross check 156c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( buf3 , outbuf); 157c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1582b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(inbuf,buf3)) < test_precision<T>() );// gross check 159c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 160c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // verify that the Unscaled flag takes effect 161c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ComplexVector buf4; 162c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.SetFlag(fft.Unscaled); 163c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( buf4 , outbuf); 164c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<nfft;++k) 165c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath buf4[k] *= T(1./nfft); 1662b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(inbuf,buf4)) < test_precision<T>() );// gross check 167c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 168c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // verify that ClearFlag works 169c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.ClearFlag(fft.Unscaled); 170c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv( buf3 , outbuf); 1712b8756b6f1de65d3f8bffab45be6c44ceb7411fcMiao Wang VERIFY( T(dif_rmse(inbuf,buf3)) < test_precision<T>() );// gross check 172c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 173c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 174c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename T> 175c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_complex(int nfft) 176c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 177c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath test_complex_generic<StdVectorContainer,T>(nfft); 178c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath test_complex_generic<EigenVectorContainer,T>(nfft); 179c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 180c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/* 181c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename T,int nrows,int ncols> 182c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_complex2d() 183c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 184c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef typename Eigen::FFT<T>::Complex Complex; 185c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath FFT<T> fft; 186c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Eigen::Matrix<Complex,nrows,ncols> src,src2,dst,dst2; 187c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 188c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath src = Eigen::Matrix<Complex,nrows,ncols>::Random(); 189c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath //src = Eigen::Matrix<Complex,nrows,ncols>::Identity(); 190c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 191c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<ncols;k++) { 192c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Eigen::Matrix<Complex,nrows,1> tmpOut; 193c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd( tmpOut,src.col(k) ); 194c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath dst2.col(k) = tmpOut; 195c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 196c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 197c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int k=0;k<nrows;k++) { 198c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Eigen::Matrix<Complex,1,ncols> tmpOut; 199c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd( tmpOut, dst2.row(k) ); 200c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath dst2.row(k) = tmpOut; 201c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 202c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 203c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd2(dst.data(),src.data(),ncols,nrows); 204c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.inv2(src2.data(),dst.data(),ncols,nrows); 205c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (src-src2).norm() < test_precision<T>() ); 206c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (dst-dst2).norm() < test_precision<T>() ); 207c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 208c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath*/ 209c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 210c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 211c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_return_by_value(int len) 212c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 213c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VectorXf in; 214c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VectorXf in1; 215c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath in.setRandom( len ); 216c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VectorXcf out1,out2; 217c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath FFT<float> fft; 218c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 219c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.SetFlag(fft.HalfSpectrum ); 220c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 221c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath fft.fwd(out1,in); 222c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath out2 = fft.fwd(in); 223c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (out1-out2).norm() < test_precision<float>() ); 224c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath in1 = fft.inv(out1); 225c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (in1-in).norm() < test_precision<float>() ); 226c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 227c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 228c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_FFTW() 229c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 230c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_return_by_value(32) ); 231c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath //CALL_SUBTEST( ( test_complex2d<float,4,8> () ) ); CALL_SUBTEST( ( test_complex2d<double,4,8> () ) ); 232c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath //CALL_SUBTEST( ( test_complex2d<long double,4,8> () ) ); 233c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(32) ); CALL_SUBTEST( test_complex<double>(32) ); 234c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(256) ); CALL_SUBTEST( test_complex<double>(256) ); 235c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(3*8) ); CALL_SUBTEST( test_complex<double>(3*8) ); 236c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(5*32) ); CALL_SUBTEST( test_complex<double>(5*32) ); 237c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(2*3*4) ); CALL_SUBTEST( test_complex<double>(2*3*4) ); 238c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(2*3*4*5) ); CALL_SUBTEST( test_complex<double>(2*3*4*5) ); 239c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<float>(2*3*4*5*7) ); CALL_SUBTEST( test_complex<double>(2*3*4*5*7) ); 240c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 241c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<float>(32) ); CALL_SUBTEST( test_scalar<double>(32) ); 242c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<float>(45) ); CALL_SUBTEST( test_scalar<double>(45) ); 243c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<float>(50) ); CALL_SUBTEST( test_scalar<double>(50) ); 244c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<float>(256) ); CALL_SUBTEST( test_scalar<double>(256) ); 245c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<float>(2*3*4*5*7) ); CALL_SUBTEST( test_scalar<double>(2*3*4*5*7) ); 246c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 247c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath #ifdef EIGEN_HAS_FFTWL 248c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(32) ); 249c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(256) ); 250c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(3*8) ); 251c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(5*32) ); 252c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(2*3*4) ); 253c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(2*3*4*5) ); 254c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_complex<long double>(2*3*4*5*7) ); 255c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 256c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<long double>(32) ); 257c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<long double>(45) ); 258c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<long double>(50) ); 259c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<long double>(256) ); 260c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( test_scalar<long double>(2*3*4*5*7) ); 261c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath #endif 262c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 263