mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
found out about little-documented FFTW_PRESERVE_INPUT which has effect on c2r transforms
This commit is contained in:
@@ -152,18 +152,20 @@ class FFT
|
||||
m_impl.fwd(dst,src,nfft);
|
||||
}
|
||||
|
||||
/*
|
||||
inline
|
||||
void fwd2(Complex * dst, const Complex * src, int nrows,int ncols)
|
||||
void fwd2(Complex * dst, const Complex * src, int n0,int n1)
|
||||
{
|
||||
m_impl.fwd2(dst,src,nrows,ncols);
|
||||
m_impl.fwd2(dst,src,n0,n1);
|
||||
}
|
||||
*/
|
||||
|
||||
template <typename _Input>
|
||||
inline
|
||||
void fwd( std::vector<Complex> & dst, const std::vector<_Input> & src)
|
||||
{
|
||||
if ( NumTraits<_Input>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
||||
dst.resize( (src.size()>>1)+1);
|
||||
dst.resize( (src.size()>>1)+1); // half the bins + Nyquist bin
|
||||
else
|
||||
dst.resize(src.size());
|
||||
fwd(&dst[0],&src[0],static_cast<int>(src.size()));
|
||||
@@ -197,22 +199,22 @@ class FFT
|
||||
inline
|
||||
void inv( Complex * dst, const Complex * src, int nfft)
|
||||
{
|
||||
m_impl.inv( dst,src,nfft );
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./nfft,nfft);
|
||||
m_impl.inv( dst,src,nfft );
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./nfft,nfft); // scale the time series
|
||||
}
|
||||
|
||||
inline
|
||||
void inv( Scalar * dst, const Complex * src, int nfft)
|
||||
{
|
||||
m_impl.inv( dst,src,nfft );
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./nfft,nfft);
|
||||
m_impl.inv( dst,src,nfft );
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./nfft,nfft); // scale the time series
|
||||
}
|
||||
|
||||
template<typename OutputDerived, typename ComplexDerived>
|
||||
inline
|
||||
void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src)
|
||||
void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src, int nfft=-1)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived)
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
|
||||
@@ -222,10 +224,12 @@ class FFT
|
||||
EIGEN_STATIC_ASSERT(int(OutputDerived::Flags)&int(ComplexDerived::Flags)&DirectAccessBit,
|
||||
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
|
||||
|
||||
int nfft = src.size();
|
||||
int nout = HasFlag(HalfSpectrum) ? ((nfft>>1)+1) : nfft;
|
||||
dst.derived().resize( nout );
|
||||
if (nfft<1) {
|
||||
nfft = ( NumTraits<typename OutputDerived::Scalar>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size();
|
||||
}
|
||||
dst.derived().resize( nfft );
|
||||
if (src.stride() != 1) {
|
||||
// if the vector is strided, then we need to copy it to a packed temporary
|
||||
Matrix<typename ComplexDerived::Scalar,1,Dynamic> tmp = src;
|
||||
inv( &dst[0],&tmp[0], nfft);
|
||||
}else{
|
||||
@@ -235,25 +239,25 @@ class FFT
|
||||
|
||||
template <typename _Output>
|
||||
inline
|
||||
void inv( std::vector<_Output> & dst, const std::vector<Complex> & src)
|
||||
void inv( std::vector<_Output> & dst, const std::vector<Complex> & src,int nfft=-1)
|
||||
{
|
||||
if ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) )
|
||||
dst.resize( 2*(src.size()-1) );
|
||||
else
|
||||
dst.resize( src.size() );
|
||||
inv( &dst[0],&src[0],static_cast<int>(dst.size()) );
|
||||
if (nfft<1)
|
||||
nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size();
|
||||
dst.resize( nfft );
|
||||
inv( &dst[0],&src[0],nfft);
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
void inv2(Complex * dst, const Complex * src, int nrows,int ncols)
|
||||
{
|
||||
m_impl.inv2(dst,src,nrows,ncols);
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./(nrows*ncols),nrows*ncols);
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: multi-dimensional FFTs
|
||||
inline
|
||||
void inv2(Complex * dst, const Complex * src, int n0,int n1)
|
||||
{
|
||||
m_impl.inv2(dst,src,n0,n1);
|
||||
if ( HasFlag( Unscaled ) == false)
|
||||
scale(dst,1./(n0*n1),n0*n1);
|
||||
}
|
||||
*/
|
||||
|
||||
inline
|
||||
impl_type & impl() {return m_impl;}
|
||||
|
||||
@@ -71,34 +71,34 @@
|
||||
|
||||
inline
|
||||
void fwd(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void fwd(complex_type * dst,scalar_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft_r2c( m_plan,src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(scalar_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL)
|
||||
m_plan = fftwf_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
m_plan = fftwf_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft_c2r( m_plan, src,dst);
|
||||
}
|
||||
|
||||
inline
|
||||
void fwd2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(ncols,nrows,src,dst,FFTW_FORWARD,FFTW_ESTIMATE);
|
||||
void fwd2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(ncols,nrows,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE);
|
||||
void inv2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftwf_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwf_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
|
||||
@@ -114,33 +114,33 @@
|
||||
|
||||
inline
|
||||
void fwd(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void fwd(complex_type * dst,scalar_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft_r2c( m_plan,src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(scalar_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL)
|
||||
m_plan = fftw_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
m_plan = fftw_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft_c2r( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void fwd2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_2d(ncols,nrows,src,dst,FFTW_FORWARD,FFTW_ESTIMATE);
|
||||
void fwd2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_2d(ncols,nrows,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE);
|
||||
void inv2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftw_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftw_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
};
|
||||
@@ -155,33 +155,33 @@
|
||||
|
||||
inline
|
||||
void fwd(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(complex_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_1d(nfft,src,dst, FFTW_BACKWARD , FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void fwd(complex_type * dst,scalar_type * src,int nfft) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_r2c_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft_r2c( m_plan,src,dst);
|
||||
}
|
||||
inline
|
||||
void inv(scalar_type * dst,complex_type * src,int nfft) {
|
||||
if (m_plan==NULL)
|
||||
m_plan = fftwl_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE);
|
||||
m_plan = fftwl_plan_dft_c2r_1d(nfft,src,dst,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft_c2r( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void fwd2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(ncols,nrows,src,dst,FFTW_FORWARD,FFTW_ESTIMATE);
|
||||
void fwd2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(n0,n1,src,dst,FFTW_FORWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
inline
|
||||
void inv2( complex_type * dst,complex_type * src,int nrows,int ncols) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(ncols,nrows,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE);
|
||||
void inv2( complex_type * dst,complex_type * src,int n0,int n1) {
|
||||
if (m_plan==NULL) m_plan = fftwl_plan_dft_2d(n0,n1,src,dst,FFTW_BACKWARD,FFTW_ESTIMATE|FFTW_PRESERVE_INPUT);
|
||||
fftwl_execute_dft( m_plan, src,dst);
|
||||
}
|
||||
};
|
||||
@@ -214,9 +214,9 @@
|
||||
|
||||
// 2-d complex-to-complex
|
||||
inline
|
||||
void fwd2(Complex * dst, const Complex * src, int nrows,int ncols)
|
||||
void fwd2(Complex * dst, const Complex * src, int n0,int n1)
|
||||
{
|
||||
get_plan(nrows,ncols,false,dst,src).fwd2(ei_fftw_cast(dst), ei_fftw_cast(src) ,nrows,ncols);
|
||||
get_plan(n0,n1,false,dst,src).fwd2(ei_fftw_cast(dst), ei_fftw_cast(src) ,n0,n1);
|
||||
}
|
||||
|
||||
// inverse complex-to-complex
|
||||
@@ -235,9 +235,9 @@
|
||||
|
||||
// 2-d complex-to-complex
|
||||
inline
|
||||
void inv2(Complex * dst, const Complex * src, int nrows,int ncols)
|
||||
void inv2(Complex * dst, const Complex * src, int n0,int n1)
|
||||
{
|
||||
get_plan(nrows,ncols,true,dst,src).inv2(ei_fftw_cast(dst), ei_fftw_cast(src) ,nrows,ncols);
|
||||
get_plan(n0,n1,true,dst,src).inv2(ei_fftw_cast(dst), ei_fftw_cast(src) ,n0,n1);
|
||||
}
|
||||
|
||||
|
||||
@@ -258,11 +258,11 @@
|
||||
}
|
||||
|
||||
inline
|
||||
PlanData & get_plan(int nrows,int ncols,bool inverse,void * dst,const void * src)
|
||||
PlanData & get_plan(int n0,int n1,bool inverse,void * dst,const void * src)
|
||||
{
|
||||
bool inplace = (dst==src);
|
||||
bool aligned = ( (reinterpret_cast<size_t>(src)&15) | (reinterpret_cast<size_t>(dst)&15) ) == 0;
|
||||
int64_t key = ( ( (((int64_t)ncols) << 30)|(nrows<<3 ) | (inverse<<2) | (inplace<<1) | aligned ) << 1 ) + 1;
|
||||
int64_t key = ( ( (((int64_t)n0) << 30)|(n1<<3 ) | (inverse<<2) | (inplace<<1) | aligned ) << 1 ) + 1;
|
||||
return m_plans[key];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -291,6 +291,16 @@ struct ei_kissfft_impl
|
||||
get_plan(nfft,false).work(0, dst, src, 1,1);
|
||||
}
|
||||
|
||||
inline
|
||||
void fwd2( Complex * dst,const Complex *src,int n0,int n1)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
void inv2( Complex * dst,const Complex *src,int n0,int n1)
|
||||
{
|
||||
}
|
||||
|
||||
// real-to-complex forward FFT
|
||||
// perform two FFTs of src even and src odd
|
||||
// then twiddle to recombine them into the half-spectrum format
|
||||
|
||||
Reference in New Issue
Block a user