changed destination argument to reference
This commit is contained in:
parent
141c746fc7
commit
1d342e135c
@ -160,18 +160,18 @@ class FFT
|
|||||||
|
|
||||||
template <typename _Input>
|
template <typename _Input>
|
||||||
inline
|
inline
|
||||||
void fwd( std::vector<Complex> * dst, const std::vector<_Input> & src)
|
void fwd( std::vector<Complex> & dst, const std::vector<_Input> & src)
|
||||||
{
|
{
|
||||||
if ( NumTraits<_Input>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
if ( NumTraits<_Input>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
||||||
dst->resize( (src.size()>>1)+1);
|
dst.resize( (src.size()>>1)+1);
|
||||||
else
|
else
|
||||||
dst->resize(src.size());
|
dst.resize(src.size());
|
||||||
fwd(&(*dst)[0],&src[0],static_cast<int>(src.size()));
|
fwd(&dst[0],&src[0],static_cast<int>(src.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputDerived, typename ComplexDerived>
|
template<typename InputDerived, typename ComplexDerived>
|
||||||
inline
|
inline
|
||||||
void fwd( MatrixBase<ComplexDerived> * dst, const MatrixBase<InputDerived> & src)
|
void fwd( MatrixBase<ComplexDerived> & dst, const MatrixBase<InputDerived> & src)
|
||||||
{
|
{
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputDerived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputDerived)
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
|
||||||
@ -182,15 +182,15 @@ class FFT
|
|||||||
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
|
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
|
||||||
|
|
||||||
if ( NumTraits< typename InputDerived::Scalar >::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
if ( NumTraits< typename InputDerived::Scalar >::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
||||||
dst->derived().resize( (src.size()>>1)+1);
|
dst.derived().resize( (src.size()>>1)+1);
|
||||||
else
|
else
|
||||||
dst->derived().resize(src.size());
|
dst.derived().resize(src.size());
|
||||||
|
|
||||||
if (src.stride() != 1) {
|
if (src.stride() != 1) {
|
||||||
Matrix<typename InputDerived::Scalar,1,Dynamic> tmp = src;
|
Matrix<typename InputDerived::Scalar,1,Dynamic> tmp = src;
|
||||||
fwd( &(*dst)[0],&tmp[0],src.size() );
|
fwd( &dst[0],&tmp[0],src.size() );
|
||||||
}else{
|
}else{
|
||||||
fwd( &(*dst)[0],&src[0],src.size() );
|
fwd( &dst[0],&src[0],src.size() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class FFT
|
|||||||
|
|
||||||
template<typename OutputDerived, typename ComplexDerived>
|
template<typename OutputDerived, typename ComplexDerived>
|
||||||
inline
|
inline
|
||||||
void inv( MatrixBase<OutputDerived> * dst, const MatrixBase<ComplexDerived> & src)
|
void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src)
|
||||||
{
|
{
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived)
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
|
||||||
@ -224,24 +224,24 @@ class FFT
|
|||||||
|
|
||||||
int nfft = src.size();
|
int nfft = src.size();
|
||||||
int nout = HasFlag(HalfSpectrum) ? ((nfft>>1)+1) : nfft;
|
int nout = HasFlag(HalfSpectrum) ? ((nfft>>1)+1) : nfft;
|
||||||
dst->derived().resize( nout );
|
dst.derived().resize( nout );
|
||||||
if (src.stride() != 1) {
|
if (src.stride() != 1) {
|
||||||
Matrix<typename ComplexDerived::Scalar,1,Dynamic> tmp = src;
|
Matrix<typename ComplexDerived::Scalar,1,Dynamic> tmp = src;
|
||||||
inv( &(*dst)[0],&tmp[0], nfft);
|
inv( &dst[0],&tmp[0], nfft);
|
||||||
}else{
|
}else{
|
||||||
inv( &(*dst)[0],&src[0], nfft);
|
inv( &dst[0],&src[0], nfft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename _Output>
|
template <typename _Output>
|
||||||
inline
|
inline
|
||||||
void inv( std::vector<_Output> * dst, const std::vector<Complex> & src)
|
void inv( std::vector<_Output> & dst, const std::vector<Complex> & src)
|
||||||
{
|
{
|
||||||
if ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
if ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
||||||
dst->resize( 2*(src.size()-1) );
|
dst.resize( 2*(src.size()-1) );
|
||||||
else
|
else
|
||||||
dst->resize( src.size() );
|
dst.resize( src.size() );
|
||||||
inv( &(*dst)[0],&src[0],static_cast<int>(dst->size()) );
|
inv( &dst[0],&src[0],static_cast<int>(dst.size()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -106,29 +106,29 @@ void test_scalar_generic(int nfft)
|
|||||||
// 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
|
||||||
fft.SetFlag(fft.HalfSpectrum );
|
fft.SetFlag(fft.HalfSpectrum );
|
||||||
fft.fwd( &outbuf,inbuf);
|
fft.fwd( outbuf,inbuf);
|
||||||
VERIFY(outbuf.size() == (size_t)( (nfft>>1)+1) );
|
VERIFY(outbuf.size() == (size_t)( (nfft>>1)+1) );
|
||||||
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
fft.ClearFlag(fft.HalfSpectrum );
|
fft.ClearFlag(fft.HalfSpectrum );
|
||||||
fft.fwd( &outbuf,inbuf);
|
fft.fwd( outbuf,inbuf);
|
||||||
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
ScalarVector buf3;
|
ScalarVector buf3;
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
// verify that the Unscaled flag takes effect
|
// verify that the Unscaled flag takes effect
|
||||||
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( dif_rmse(inbuf,buf4) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf4) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
// verify that ClearFlag works
|
// verify that ClearFlag works
|
||||||
fft.ClearFlag(fft.Unscaled);
|
fft.ClearFlag(fft.Unscaled);
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,25 +152,25 @@ void test_complex_generic(int nfft)
|
|||||||
ComplexVector buf3;
|
ComplexVector buf3;
|
||||||
for (int k=0;k<nfft;++k)
|
for (int k=0;k<nfft;++k)
|
||||||
inbuf[k]= Complex( (T)(rand()/(double)RAND_MAX - .5), (T)(rand()/(double)RAND_MAX - .5) );
|
inbuf[k]= Complex( (T)(rand()/(double)RAND_MAX - .5), (T)(rand()/(double)RAND_MAX - .5) );
|
||||||
fft.fwd( &outbuf , inbuf);
|
fft.fwd( outbuf , inbuf);
|
||||||
|
|
||||||
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
|
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
// verify that the Unscaled flag takes effect
|
// verify that the Unscaled flag takes effect
|
||||||
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( dif_rmse(inbuf,buf4) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf4) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
// verify that ClearFlag works
|
// verify that ClearFlag works
|
||||||
fft.ClearFlag(fft.Unscaled);
|
fft.ClearFlag(fft.Unscaled);
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,11 +91,11 @@ void test_scalar(int nfft)
|
|||||||
vector<Complex> outbuf;
|
vector<Complex> outbuf;
|
||||||
for (int k=0;k<nfft;++k)
|
for (int k=0;k<nfft;++k)
|
||||||
inbuf[k]= (T)(rand()/(double)RAND_MAX - .5);
|
inbuf[k]= (T)(rand()/(double)RAND_MAX - .5);
|
||||||
fft.fwd( &outbuf,inbuf);
|
fft.fwd( outbuf,inbuf);
|
||||||
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
vector<Scalar> buf3;
|
vector<Scalar> buf3;
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +111,11 @@ void test_complex(int nfft)
|
|||||||
vector<Complex> buf3;
|
vector<Complex> buf3;
|
||||||
for (int k=0;k<nfft;++k)
|
for (int k=0;k<nfft;++k)
|
||||||
inbuf[k]= RandomCpx<T>();
|
inbuf[k]= RandomCpx<T>();
|
||||||
fft.fwd( &outbuf , inbuf);
|
fft.fwd( outbuf , inbuf);
|
||||||
|
|
||||||
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
VERIFY( fft_rmse(outbuf,inbuf) < test_precision<T>() );// gross check
|
||||||
|
|
||||||
fft.inv( &buf3 , outbuf);
|
fft.inv( buf3 , outbuf);
|
||||||
|
|
||||||
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
VERIFY( dif_rmse(inbuf,buf3) < test_precision<T>() );// gross check
|
||||||
}
|
}
|
||||||
@ -132,13 +132,13 @@ void test_complex2d()
|
|||||||
|
|
||||||
for (int k=0;k<ncols;k++) {
|
for (int k=0;k<ncols;k++) {
|
||||||
Eigen::Matrix<Complex,nrows,1> tmpOut;
|
Eigen::Matrix<Complex,nrows,1> tmpOut;
|
||||||
fft.fwd( &tmpOut,src.col(k) );
|
fft.fwd( tmpOut,src.col(k) );
|
||||||
dst2.col(k) = tmpOut;
|
dst2.col(k) = tmpOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k=0;k<nrows;k++) {
|
for (int k=0;k<nrows;k++) {
|
||||||
Eigen::Matrix<Complex,1,ncols> tmpOut;
|
Eigen::Matrix<Complex,1,ncols> tmpOut;
|
||||||
fft.fwd( &tmpOut, dst2.row(k) );
|
fft.fwd( tmpOut, dst2.row(k) );
|
||||||
dst2.row(k) = tmpOut;
|
dst2.row(k) = tmpOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user