Fix clang-tidy warnings about function definitions in headers.

This commit is contained in:
Antonio Sanchez 2022-06-23 13:47:32 -07:00 committed by Antonio Sánchez
parent 8ed3b9dcd6
commit 0e18714167

View File

@ -11,23 +11,24 @@
#include <unsupported/Eigen/FFT> #include <unsupported/Eigen/FFT>
template <typename T> template <typename T>
std::complex<T> RandomCpx() { return std::complex<T>( (T)(rand()/(T)RAND_MAX - .5), (T)(rand()/(T)RAND_MAX - .5) ); } inline std::complex<T> RandomCpx() {
return std::complex<T>((T)(rand() / (T)RAND_MAX - .5), (T)(rand() / (T)RAND_MAX - .5));
}
using namespace std; using namespace std;
using namespace Eigen; using namespace Eigen;
template <typename T> template <typename T>
complex<long double> promote(complex<T> x) { return complex<long double>((long double)x.real(),(long double)x.imag()); } inline complex<long double> promote(complex<T> x) {
return complex<long double>((long double)x.real(), (long double)x.imag());
complex<long double> promote(float x) { return complex<long double>((long double)x); } }
complex<long double> promote(double x) { return complex<long double>((long double)x); }
complex<long double> promote(long double x) { return complex<long double>((long double)x); }
inline complex<long double> promote(float x) { return complex<long double>((long double)x); }
inline complex<long double> promote(double x) { return complex<long double>((long double)x); }
inline complex<long double> promote(long double x) { return complex<long double>((long double)x); }
template <typename VT1, typename VT2> template <typename VT1, typename VT2>
long double fft_rmse( const VT1 & fftbuf,const VT2 & timebuf) long double fft_rmse(const VT1& fftbuf, const VT2& timebuf) {
{
long double totalpower = 0; long double totalpower = 0;
long double difpower = 0; long double difpower = 0;
long double pi = acos((long double)-1); long double pi = acos((long double)-1);
@ -48,8 +49,7 @@ complex<long double> promote(long double x) { return complex<long double>((long
} }
template <typename VT1, typename VT2> template <typename VT1, typename VT2>
long double dif_rmse( const VT1 buf1,const VT2 buf2) long double dif_rmse(const VT1 buf1, const VT2 buf2) {
{
long double totalpower = 0; long double totalpower = 0;
long double difpower = 0; long double difpower = 0;
size_t n = (min)(buf1.size(), buf2.size()); size_t n = (min)(buf1.size(), buf2.size());
@ -62,21 +62,21 @@ complex<long double> promote(long double x) { return complex<long double>((long
enum { StdVectorContainer, EigenVectorContainer }; enum { StdVectorContainer, EigenVectorContainer };
template<int Container, typename Scalar> struct VectorType; template <int Container, typename Scalar>
struct VectorType;
template<typename Scalar> struct VectorType<StdVectorContainer,Scalar> template <typename Scalar>
{ struct VectorType<StdVectorContainer, Scalar> {
typedef vector<Scalar> type; typedef vector<Scalar> type;
}; };
template<typename Scalar> struct VectorType<EigenVectorContainer,Scalar> template <typename Scalar>
{ struct VectorType<EigenVectorContainer, Scalar> {
typedef Matrix<Scalar, Dynamic, 1> type; typedef Matrix<Scalar, Dynamic, 1> type;
}; };
template <int Container, typename T> template <int Container, typename T>
void test_scalar_generic(int nfft) void test_scalar_generic(int nfft) {
{
typedef typename FFT<T>::Complex Complex; typedef typename FFT<T>::Complex Complex;
typedef typename FFT<T>::Scalar Scalar; typedef typename FFT<T>::Scalar Scalar;
typedef typename VectorType<Container, Scalar>::type ScalarVector; typedef typename VectorType<Container, Scalar>::type ScalarVector;
@ -85,8 +85,7 @@ void test_scalar_generic(int nfft)
FFT<T> fft; FFT<T> fft;
ScalarVector tbuf(nfft); ScalarVector tbuf(nfft);
ComplexVector freqBuf; ComplexVector freqBuf;
for (int k=0;k<nfft;++k) for (int k = 0; k < nfft; ++k) tbuf[k] = (T)(rand() / (double)RAND_MAX - .5);
tbuf[k]= (T)( rand()/(double)RAND_MAX - .5);
// make sure it DOESN'T give the right full spectrum answer // make sure it DOESN'T give the right full spectrum answer
// if we've asked for half-spectrum // if we've asked for half-spectrum
@ -100,26 +99,23 @@ void test_scalar_generic(int nfft)
VERIFY((size_t)freqBuf.size() == (size_t)nfft); VERIFY((size_t)freqBuf.size() == (size_t)nfft);
VERIFY(T(fft_rmse(freqBuf, tbuf)) < test_precision<T>()); // gross check VERIFY(T(fft_rmse(freqBuf, tbuf)) < test_precision<T>()); // gross check
if (nfft&1) if (nfft & 1) return; // odd FFTs get the wrong size inverse FFT
return; // odd FFTs get the wrong size inverse FFT
ScalarVector tbuf2; ScalarVector tbuf2;
fft.inv(tbuf2, freqBuf); fft.inv(tbuf2, freqBuf);
VERIFY(T(dif_rmse(tbuf, tbuf2)) < test_precision<T>()); // gross check VERIFY(T(dif_rmse(tbuf, tbuf2)) < test_precision<T>()); // gross check
// verify that the Unscaled flag takes effect // verify that the Unscaled flag takes effect
ScalarVector tbuf3; ScalarVector tbuf3;
fft.SetFlag(fft.Unscaled); fft.SetFlag(fft.Unscaled);
fft.inv(tbuf3, freqBuf); fft.inv(tbuf3, freqBuf);
for (int k=0;k<nfft;++k) for (int k = 0; k < nfft; ++k) tbuf3[k] *= T(1. / nfft);
tbuf3[k] *= T(1./nfft);
// for (size_t i=0;i<(size_t) tbuf.size();++i) // 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; // cout << "freqBuf=" << freqBuf[i] << " in2=" << tbuf3[i] << " - in=" << tbuf[i] << " => " << (tbuf3[i] -
// tbuf[i] ) << endl;
VERIFY(T(dif_rmse(tbuf, tbuf3)) < test_precision<T>()); // gross check VERIFY(T(dif_rmse(tbuf, tbuf3)) < test_precision<T>()); // gross check
@ -130,16 +126,13 @@ void test_scalar_generic(int nfft)
} }
template <typename T> template <typename T>
void test_scalar(int nfft) void test_scalar(int nfft) {
{
test_scalar_generic<StdVectorContainer, T>(nfft); test_scalar_generic<StdVectorContainer, T>(nfft);
// test_scalar_generic<EigenVectorContainer,T>(nfft); // test_scalar_generic<EigenVectorContainer,T>(nfft);
} }
template <int Container, typename T> template <int Container, typename T>
void test_complex_generic(int nfft) void test_complex_generic(int nfft) {
{
typedef typename FFT<T>::Complex Complex; typedef typename FFT<T>::Complex Complex;
typedef typename VectorType<Container, Complex>::type ComplexVector; typedef typename VectorType<Container, Complex>::type ComplexVector;
@ -161,8 +154,7 @@ void test_complex_generic(int nfft)
ComplexVector buf4; ComplexVector buf4;
fft.SetFlag(fft.Unscaled); fft.SetFlag(fft.Unscaled);
fft.inv(buf4, outbuf); fft.inv(buf4, outbuf);
for (int k=0;k<nfft;++k) for (int k = 0; k < nfft; ++k) buf4[k] *= T(1. / nfft);
buf4[k] *= T(1./nfft);
VERIFY(T(dif_rmse(inbuf, buf4)) < test_precision<T>()); // gross check VERIFY(T(dif_rmse(inbuf, buf4)) < test_precision<T>()); // gross check
// verify that ClearFlag works // verify that ClearFlag works
@ -172,15 +164,13 @@ void test_complex_generic(int nfft)
} }
template <typename T> template <typename T>
void test_complex(int nfft) void test_complex(int nfft) {
{
test_complex_generic<StdVectorContainer, T>(nfft); test_complex_generic<StdVectorContainer, T>(nfft);
test_complex_generic<EigenVectorContainer, T>(nfft); test_complex_generic<EigenVectorContainer, T>(nfft);
} }
template <typename T, int nrows, int ncols> template <typename T, int nrows, int ncols>
void test_complex2d() void test_complex2d() {
{
typedef typename Eigen::FFT<T>::Complex Complex; typedef typename Eigen::FFT<T>::Complex Complex;
FFT<T> fft; FFT<T> fft;
Eigen::Matrix<Complex, nrows, ncols> src, src2, dst, dst2; Eigen::Matrix<Complex, nrows, ncols> src, src2, dst, dst2;
@ -206,8 +196,7 @@ void test_complex2d()
VERIFY((dst - dst2).norm() < test_precision<T>()); VERIFY((dst - dst2).norm() < test_precision<T>());
} }
void test_return_by_value(int len) inline void test_return_by_value(int len) {
{
VectorXf in; VectorXf in;
VectorXf in1; VectorXf in1;
in.setRandom(len); in.setRandom(len);
@ -223,22 +212,33 @@ void test_return_by_value(int len)
VERIFY((in1 - in).norm() < test_precision<float>()); VERIFY((in1 - in).norm() < test_precision<float>());
} }
EIGEN_DECLARE_TEST(FFTW) EIGEN_DECLARE_TEST(FFTW) {
{
CALL_SUBTEST(test_return_by_value(32)); CALL_SUBTEST(test_return_by_value(32));
CALL_SUBTEST( test_complex<float>(32) ); CALL_SUBTEST( test_complex<double>(32) ); CALL_SUBTEST(test_complex<float>(32));
CALL_SUBTEST( test_complex<float>(256) ); CALL_SUBTEST( test_complex<double>(256) ); CALL_SUBTEST(test_complex<double>(32));
CALL_SUBTEST( test_complex<float>(3*8) ); CALL_SUBTEST( test_complex<double>(3*8) ); CALL_SUBTEST(test_complex<float>(256));
CALL_SUBTEST( test_complex<float>(5*32) ); CALL_SUBTEST( test_complex<double>(5*32) ); CALL_SUBTEST(test_complex<double>(256));
CALL_SUBTEST( test_complex<float>(2*3*4) ); CALL_SUBTEST( test_complex<double>(2*3*4) ); CALL_SUBTEST(test_complex<float>(3 * 8));
CALL_SUBTEST( test_complex<float>(2*3*4*5) ); CALL_SUBTEST( test_complex<double>(2*3*4*5) ); CALL_SUBTEST(test_complex<double>(3 * 8));
CALL_SUBTEST( test_complex<float>(2*3*4*5*7) ); CALL_SUBTEST( test_complex<double>(2*3*4*5*7) ); CALL_SUBTEST(test_complex<float>(5 * 32));
CALL_SUBTEST(test_complex<double>(5 * 32));
CALL_SUBTEST(test_complex<float>(2 * 3 * 4));
CALL_SUBTEST(test_complex<double>(2 * 3 * 4));
CALL_SUBTEST(test_complex<float>(2 * 3 * 4 * 5));
CALL_SUBTEST(test_complex<double>(2 * 3 * 4 * 5));
CALL_SUBTEST(test_complex<float>(2 * 3 * 4 * 5 * 7));
CALL_SUBTEST(test_complex<double>(2 * 3 * 4 * 5 * 7));
CALL_SUBTEST( test_scalar<float>(32) ); CALL_SUBTEST( test_scalar<double>(32) ); CALL_SUBTEST(test_scalar<float>(32));
CALL_SUBTEST( test_scalar<float>(45) ); CALL_SUBTEST( test_scalar<double>(45) ); CALL_SUBTEST(test_scalar<double>(32));
CALL_SUBTEST( test_scalar<float>(50) ); CALL_SUBTEST( test_scalar<double>(50) ); CALL_SUBTEST(test_scalar<float>(45));
CALL_SUBTEST( test_scalar<float>(256) ); CALL_SUBTEST( test_scalar<double>(256) ); CALL_SUBTEST(test_scalar<double>(45));
CALL_SUBTEST( test_scalar<float>(2*3*4*5*7) ); CALL_SUBTEST( test_scalar<double>(2*3*4*5*7) ); CALL_SUBTEST(test_scalar<float>(50));
CALL_SUBTEST(test_scalar<double>(50));
CALL_SUBTEST(test_scalar<float>(256));
CALL_SUBTEST(test_scalar<double>(256));
CALL_SUBTEST(test_scalar<float>(2 * 3 * 4 * 5 * 7));
CALL_SUBTEST(test_scalar<double>(2 * 3 * 4 * 5 * 7));
#if defined EIGEN_HAS_FFTWL || defined EIGEN_POCKETFFT_DEFAULT #if defined EIGEN_HAS_FFTWL || defined EIGEN_POCKETFFT_DEFAULT
CALL_SUBTEST(test_complex<long double>(32)); CALL_SUBTEST(test_complex<long double>(32));
@ -274,5 +274,4 @@ EIGEN_DECLARE_TEST(FFTW)
CALL_SUBTEST((test_complex2d<double, 24, 60>())); CALL_SUBTEST((test_complex2d<double, 24, 60>()));
CALL_SUBTEST((test_complex2d<double, 60, 24>())); CALL_SUBTEST((test_complex2d<double, 60, 24>()));
#endif #endif
} }