11 #include <unsupported/Eigen/FFT> 14 std::complex<T>
RandomCpx() {
return std::complex<T>( (
T)(rand()/(
T)RAND_MAX - .5), (
T)(rand()/(
T)RAND_MAX - .5) ); }
17 using namespace Eigen;
20 template <
typename T>
28 template <
typename VT1,
typename VT2>
29 long double fft_rmse(
const VT1 & fftbuf,
const VT2 & timebuf)
31 long double totalpower=0;
32 long double difpower=0;
33 long double pi =
acos((
long double)-1 );
34 for (
size_t k0=0;k0<(
size_t)fftbuf.size();++k0) {
36 long double phinc = (
long double)(-2.)*k0* pi / timebuf.size();
37 for (
size_t k1=0;k1<(
size_t)timebuf.size();++k1) {
46 cerr <<
"rmse:" <<
sqrt(difpower/totalpower) << endl;
47 return sqrt(difpower/totalpower);
50 template <
typename VT1,
typename VT2>
51 long double dif_rmse(
const VT1 buf1,
const VT2 buf2)
53 long double totalpower=0;
54 long double difpower=0;
55 size_t n = (
min)( buf1.size(),buf2.size() );
56 for (
size_t k=0;k<
n;++k) {
58 difpower += (
long double)(
numext::abs2(buf1[k] - buf2[k]));
60 return sqrt(difpower/totalpower);
65 template<
int Container,
typename Scalar>
struct VectorType;
69 typedef vector<Scalar>
type;
77 template <
int Container,
typename T>
86 ScalarVector tbuf(nfft);
87 ComplexVector freqBuf;
88 for (
int k=0;k<nfft;++k)
89 tbuf[k]= (
T)( rand()/(double)RAND_MAX - .5);
93 fft.SetFlag(fft.HalfSpectrum );
94 fft.fwd( freqBuf,tbuf);
95 VERIFY((
size_t)freqBuf.size() == (
size_t)( (nfft>>1)+1) );
98 fft.ClearFlag(fft.HalfSpectrum );
99 fft.fwd( freqBuf,tbuf);
107 fft.inv( tbuf2 , freqBuf);
113 fft.SetFlag(fft.Unscaled);
115 fft.inv( tbuf3 , freqBuf);
117 for (
int k=0;k<nfft;++k)
118 tbuf3[k] *=
T(1./nfft);
127 fft.ClearFlag(fft.Unscaled);
128 fft.inv( tbuf2 , freqBuf);
132 template <
typename T>
135 test_scalar_generic<StdVectorContainer,T>(nfft);
140 template <
int Container,
typename T>
148 ComplexVector inbuf(nfft);
149 ComplexVector outbuf;
151 for (
int k=0;k<nfft;++k)
152 inbuf[k]=
Complex( (
T)(rand()/(
double)RAND_MAX - .5), (
T)(rand()/(
double)RAND_MAX - .5) );
153 fft.fwd( outbuf , inbuf);
156 fft.inv( buf3 , outbuf);
162 fft.SetFlag(fft.Unscaled);
163 fft.inv( buf4 , outbuf);
164 for (
int k=0;k<nfft;++k)
165 buf4[k] *=
T(1./nfft);
169 fft.ClearFlag(fft.Unscaled);
170 fft.inv( buf3 , outbuf);
174 template <
typename T>
177 test_complex_generic<StdVectorContainer,T>(nfft);
178 test_complex_generic<EigenVectorContainer,T>(nfft);
219 fft.SetFlag(fft.HalfSpectrum );
247 #ifdef EIGEN_HAS_FFTWL
void test_complex(int nfft)
void test_complex_generic(int nfft)
Jet< T, N > acos(const Jet< T, N > &f)
Namespace containing all symbols from the Eigen library.
float test_precision< float >()
void test_scalar(int nfft)
std::complex< RealScalar > Complex
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
long double dif_rmse(const VT1 buf1, const VT2 buf2)
void test_return_by_value(int len)
Eigen::Triplet< double > T
#define CALL_SUBTEST(FUNC)
complex< long double > promote(complex< T > x)
Jet< T, N > sqrt(const Jet< T, N > &f)
Matrix< Scalar, Dynamic, 1 > type
size_t len(handle h)
Get the length of a Python object.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
void test_scalar_generic(int nfft)
std::complex< T > RandomCpx()
long double fft_rmse(const VT1 &fftbuf, const VT2 &timebuf)