void test_scalar_generic(int nfft) { typedef typename FFT<T>::Complex Complex; typedef typename FFT<T>::Scalar Scalar; typedef typename VectorType<Container, Scalar>::type ScalarVector; typedef typename VectorType<Container, Complex>::type ComplexVector; FFT<T> fft; ScalarVector tbuf(nfft); ComplexVector freqBuf; for (int k = 0; k < nfft; ++k) tbuf[k] = (T)(rand() / (double)RAND_MAX - .5); // make sure it DOESN'T give the right full spectrum answer // if we've asked for half-spectrum fft.SetFlag(fft.HalfSpectrum); fft.fwd(freqBuf, tbuf); VERIFY((size_t)freqBuf.size() == (size_t)((nfft >> 1) + 1)); VERIFY(fft_rmse(freqBuf, tbuf) < test_precision<T>()); // gross check fft.ClearFlag(fft.HalfSpectrum); fft.fwd(freqBuf, tbuf); VERIFY((size_t)freqBuf.size() == (size_t)nfft); VERIFY(fft_rmse(freqBuf, tbuf) < test_precision<T>()); // gross check if (nfft & 1) return; // odd FFTs get the wrong size inverse FFT ScalarVector tbuf2; fft.inv(tbuf2, freqBuf); VERIFY(dif_rmse(tbuf, tbuf2) < test_precision<T>()); // gross check // verify that the Unscaled flag takes effect ScalarVector tbuf3; fft.SetFlag(fft.Unscaled); fft.inv(tbuf3, freqBuf); for (int k = 0; k < nfft; ++k) tbuf3[k] *= T(1. / nfft); // for (size_t i=0;i<(size_t) tbuf.size();++i) // cout << "freqBuf=" << freqBuf[i] << " in2=" << tbuf3[i] << " - in=" << tbuf[i] << " => " << (tbuf3[i] - tbuf[i] ) << endl; VERIFY(dif_rmse(tbuf, tbuf3) < test_precision<T>()); // gross check // verify that ClearFlag works fft.ClearFlag(fft.Unscaled); fft.inv(tbuf2, freqBuf); VERIFY(dif_rmse(tbuf, tbuf2) < test_precision<T>()); // gross check }
void test_complex_generic(int nfft) { typedef typename FFT<T>::Complex Complex; typedef typename VectorType<Container,Complex>::type ComplexVector; FFT<T> fft; ComplexVector inbuf(nfft); ComplexVector outbuf; ComplexVector buf3; for (int k=0;k<nfft;++k) inbuf[k]= Complex( (T)(rand()/(double)RAND_MAX - .5), (T)(rand()/(double)RAND_MAX - .5) ); fft.fwd( outbuf , inbuf); VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check // verify that the Unscaled flag takes effect ComplexVector buf4; fft.SetFlag(fft.Unscaled); fft.inv( buf4 , outbuf); for (int k=0;k<nfft;++k) buf4[k] *= T(1./nfft); VERIFY( dif_rmse(inbuf,buf4) < test_precision<T>() );// gross check // verify that ClearFlag works fft.ClearFlag(fft.Unscaled); fft.inv( buf3 , outbuf); VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check }