From 5b2c8b77df14001b29b507b97a00c1194655bf5e Mon Sep 17 00:00:00 2001 From: Mark Borgerding Date: Sun, 7 Mar 2010 21:31:06 -0500 Subject: [PATCH] created FFT::fwd and FFT::inv with ReturnByValue --- unsupported/Eigen/FFT | 63 +++++++++++++++++++++++++++++++++++++-- unsupported/test/FFTW.cpp | 20 +++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/unsupported/Eigen/FFT b/unsupported/Eigen/FFT index 3c4d85d3b..7108c20c5 100644 --- a/unsupported/Eigen/FFT +++ b/unsupported/Eigen/FFT @@ -110,12 +110,42 @@ namespace Eigen { -template > + + +// +template +struct fft_result_proxy; + +template +struct ei_traits< fft_result_proxy > +{ + typedef typename T_SrcMat::PlainObject ReturnType; +}; + +template +struct fft_result_proxy + : public ReturnByValue > +{ + fft_result_proxy(const T_SrcMat& src,T_FftIfc & fft,int nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {} + + template void evalTo(T_DestMat& dst) const; + + int rows() const { return m_src.rows(); } + int cols() const { return m_src.cols(); } + protected: + const T_SrcMat & m_src; + T_FftIfc & m_ifc; + int m_nfft; +}; + + + +template > class FFT { public: - typedef _Impl impl_type; + typedef T_Impl impl_type; typedef typename impl_type::Scalar Scalar; typedef typename impl_type::Complex Complex; @@ -204,6 +234,22 @@ class FFT fwd( &dst[0],&src[0],nfft ); } } + + template + inline + fft_result_proxy< MatrixBase, FFT ,true> + fwd( const MatrixBase & src,int nfft=-1) + { + return fft_result_proxy< MatrixBase ,FFT,true>( src, *this,nfft ); + } + + template + inline + fft_result_proxy< MatrixBase, FFT ,false> + inv( const MatrixBase & src,int nfft=-1) + { + return fft_result_proxy< MatrixBase ,FFT,false>( src, *this,nfft ); + } inline void inv( Complex * dst, const Complex * src, int nfft) @@ -335,6 +381,17 @@ class FFT impl_type m_impl; int m_flag; }; + +template +template inline +void fft_result_proxy::evalTo(T_DestMat& dst) const +{ + if (T_ForwardTransform) + m_ifc.fwd( dst, m_src, m_nfft); + else + m_ifc.inv( dst, m_src, m_nfft); +} + } #endif /* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/unsupported/test/FFTW.cpp b/unsupported/test/FFTW.cpp index 838ddb238..66ffbae38 100644 --- a/unsupported/test/FFTW.cpp +++ b/unsupported/test/FFTW.cpp @@ -225,8 +225,28 @@ void test_complex2d() } */ + +template +void test_return_by_value() +{ + Matrix,nrows,ncols> in; + Matrix,nrows,ncols> in1; + in.Random(); + Matrix,nrows,ncols> out1; + Matrix,nrows,ncols> out2; + FFT fft; + fft.fwd(out1,in); + out2 = fft.fwd(in); + VERIFY( (out1-out2).norm() < test_precision() ); + in1 = fft.inv(out1); + VERIFY( (in1-in).norm() < test_precision() ); +} + void test_FFTW() { + test_return_by_value(); + test_return_by_value(); + //test_return_by_value(); //CALL_SUBTEST( ( test_complex2d () ) ); CALL_SUBTEST( ( test_complex2d () ) ); //CALL_SUBTEST( ( test_complex2d () ) ); CALL_SUBTEST( test_complex(32) ); CALL_SUBTEST( test_complex(32) ); CALL_SUBTEST( test_complex(32) );