Silence index warnings in triangular unit test.

Silence index warnings in FFT module.
This commit is contained in:
Hauke Heibel 2010-06-20 14:00:14 +02:00
parent 9a6967d9ba
commit 7548708848
2 changed files with 35 additions and 29 deletions

View File

@ -139,6 +139,7 @@ template<typename MatrixType> void triangular_square(const MatrixType& m)
template<typename MatrixType> void triangular_rect(const MatrixType& m) template<typename MatrixType> void triangular_rect(const MatrixType& m)
{ {
typedef const typename MatrixType::Index Index;
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;
enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime }; enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime };
@ -146,8 +147,8 @@ template<typename MatrixType> void triangular_rect(const MatrixType& m)
typedef Matrix<Scalar, Rows, Rows> RMatrixType; typedef Matrix<Scalar, Rows, Rows> RMatrixType;
int rows = m.rows(); Index rows = m.rows();
int cols = m.cols(); Index cols = m.cols();
MatrixType m1 = MatrixType::Random(rows, cols), MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols),

View File

@ -130,16 +130,18 @@ template<typename T_SrcMat,typename T_FftIfc>
struct fft_fwd_proxy struct fft_fwd_proxy
: public ReturnByValue<fft_fwd_proxy<T_SrcMat,T_FftIfc> > : public ReturnByValue<fft_fwd_proxy<T_SrcMat,T_FftIfc> >
{ {
fft_fwd_proxy(const T_SrcMat& src,T_FftIfc & fft,int nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {} typedef DenseIndex Index;
fft_fwd_proxy(const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {}
template<typename T_DestMat> void evalTo(T_DestMat& dst) const; template<typename T_DestMat> void evalTo(T_DestMat& dst) const;
int rows() const { return m_src.rows(); } Index rows() const { return m_src.rows(); }
int cols() const { return m_src.cols(); } Index cols() const { return m_src.cols(); }
protected: protected:
const T_SrcMat & m_src; const T_SrcMat & m_src;
T_FftIfc & m_ifc; T_FftIfc & m_ifc;
int m_nfft; Index m_nfft;
private: private:
fft_fwd_proxy& operator=(const fft_fwd_proxy&); fft_fwd_proxy& operator=(const fft_fwd_proxy&);
}; };
@ -148,16 +150,18 @@ template<typename T_SrcMat,typename T_FftIfc>
struct fft_inv_proxy struct fft_inv_proxy
: public ReturnByValue<fft_inv_proxy<T_SrcMat,T_FftIfc> > : public ReturnByValue<fft_inv_proxy<T_SrcMat,T_FftIfc> >
{ {
fft_inv_proxy(const T_SrcMat& src,T_FftIfc & fft,int nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {} typedef DenseIndex Index;
fft_inv_proxy(const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {}
template<typename T_DestMat> void evalTo(T_DestMat& dst) const; template<typename T_DestMat> void evalTo(T_DestMat& dst) const;
int rows() const { return m_src.rows(); } Index rows() const { return m_src.rows(); }
int cols() const { return m_src.cols(); } Index cols() const { return m_src.cols(); }
protected: protected:
const T_SrcMat & m_src; const T_SrcMat & m_src;
T_FftIfc & m_ifc; T_FftIfc & m_ifc;
int m_nfft; Index m_nfft;
private: private:
fft_inv_proxy& operator=(const fft_inv_proxy&); fft_inv_proxy& operator=(const fft_inv_proxy&);
}; };
@ -169,6 +173,7 @@ class FFT
{ {
public: public:
typedef T_Impl impl_type; typedef T_Impl impl_type;
typedef DenseIndex Index;
typedef typename impl_type::Scalar Scalar; typedef typename impl_type::Scalar Scalar;
typedef typename impl_type::Complex Complex; typedef typename impl_type::Complex Complex;
@ -192,17 +197,17 @@ class FFT
void ClearFlag(Flag f) { m_flag &= (~(int)f);} void ClearFlag(Flag f) { m_flag &= (~(int)f);}
inline inline
void fwd( Complex * dst, const Scalar * src, int nfft) void fwd( Complex * dst, const Scalar * src, Index nfft)
{ {
m_impl.fwd(dst,src,nfft); m_impl.fwd(dst,src,static_cast<int>(nfft));
if ( HasFlag(HalfSpectrum) == false) if ( HasFlag(HalfSpectrum) == false)
ReflectSpectrum(dst,nfft); ReflectSpectrum(dst,nfft);
} }
inline inline
void fwd( Complex * dst, const Complex * src, int nfft) void fwd( Complex * dst, const Complex * src, Index nfft)
{ {
m_impl.fwd(dst,src,nfft); m_impl.fwd(dst,src,static_cast<int>(nfft));
} }
/* /*
@ -221,12 +226,12 @@ class FFT
dst.resize( (src.size()>>1)+1); // half the bins + Nyquist bin dst.resize( (src.size()>>1)+1); // half the bins + Nyquist bin
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],src.size());
} }
template<typename InputDerived, typename ComplexDerived> template<typename InputDerived, typename ComplexDerived>
inline inline
void fwd( MatrixBase<ComplexDerived> & dst, const MatrixBase<InputDerived> & src,int nfft=-1) void fwd( MatrixBase<ComplexDerived> & dst, const MatrixBase<InputDerived> & src, Index nfft=-1)
{ {
typedef typename ComplexDerived::Scalar dst_type; typedef typename ComplexDerived::Scalar dst_type;
typedef typename InputDerived::Scalar src_type; typedef typename InputDerived::Scalar src_type;
@ -263,7 +268,7 @@ class FFT
template<typename InputDerived> template<typename InputDerived>
inline inline
fft_fwd_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> > fft_fwd_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> >
fwd( const MatrixBase<InputDerived> & src,int nfft=-1) fwd( const MatrixBase<InputDerived> & src, Index nfft=-1)
{ {
return fft_fwd_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft ); return fft_fwd_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft );
} }
@ -271,30 +276,30 @@ class FFT
template<typename InputDerived> template<typename InputDerived>
inline inline
fft_inv_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> > fft_inv_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> >
inv( const MatrixBase<InputDerived> & src,int nfft=-1) inv( const MatrixBase<InputDerived> & src, Index nfft=-1)
{ {
return fft_inv_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft ); return fft_inv_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *this,nfft );
} }
inline inline
void inv( Complex * dst, const Complex * src, int nfft) void inv( Complex * dst, const Complex * src, Index nfft)
{ {
m_impl.inv( dst,src,nfft ); m_impl.inv( dst,src,static_cast<int>(nfft) );
if ( HasFlag( Unscaled ) == false) if ( HasFlag( Unscaled ) == false)
scale(dst,Scalar(1./nfft),nfft); // scale the time series scale(dst,Scalar(1./nfft),nfft); // scale the time series
} }
inline inline
void inv( Scalar * dst, const Complex * src, int nfft) void inv( Scalar * dst, const Complex * src, Index nfft)
{ {
m_impl.inv( dst,src,nfft ); m_impl.inv( dst,src,static_cast<int>(nfft) );
if ( HasFlag( Unscaled ) == false) if ( HasFlag( Unscaled ) == false)
scale(dst,Scalar(1./nfft),nfft); // scale the time series scale(dst,Scalar(1./nfft),nfft); // scale the time series
} }
template<typename OutputDerived, typename ComplexDerived> template<typename OutputDerived, typename ComplexDerived>
inline inline
void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src, int nfft=-1) void inv( MatrixBase<OutputDerived> & dst, const MatrixBase<ComplexDerived> & src, Index nfft=-1)
{ {
typedef typename ComplexDerived::Scalar src_type; typedef typename ComplexDerived::Scalar src_type;
typedef typename OutputDerived::Scalar dst_type; typedef typename OutputDerived::Scalar dst_type;
@ -316,7 +321,7 @@ class FFT
dst.derived().resize( nfft ); dst.derived().resize( nfft );
// check for nfft that does not fit the input data size // check for nfft that does not fit the input data size
int resize_input= ( realfft && HasFlag(HalfSpectrum) ) Index resize_input= ( realfft && HasFlag(HalfSpectrum) )
? ( (nfft/2+1) - src.size() ) ? ( (nfft/2+1) - src.size() )
: ( nfft - src.size() ); : ( nfft - src.size() );
@ -354,7 +359,7 @@ class FFT
template <typename _Output> template <typename _Output>
inline inline
void inv( std::vector<_Output> & dst, const std::vector<Complex> & src,int nfft=-1) void inv( std::vector<_Output> & dst, const std::vector<Complex> & src,Index nfft=-1)
{ {
if (nfft<1) if (nfft<1)
nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size(); nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size();
@ -380,7 +385,7 @@ class FFT
template <typename T_Data> template <typename T_Data>
inline inline
void scale(T_Data * x,Scalar s,int nx) void scale(T_Data * x,Scalar s,Index nx)
{ {
#if 1 #if 1
for (int k=0;k<nx;++k) for (int k=0;k<nx;++k)
@ -395,11 +400,11 @@ class FFT
} }
inline inline
void ReflectSpectrum(Complex * freq,int nfft) void ReflectSpectrum(Complex * freq, Index nfft)
{ {
// create the implicit right-half spectrum (conjugate-mirror of the left-half) // create the implicit right-half spectrum (conjugate-mirror of the left-half)
int nhbins=(nfft>>1)+1; Index nhbins=(nfft>>1)+1;
for (int k=nhbins;k < nfft; ++k ) for (Index k=nhbins;k < nfft; ++k )
freq[k] = conj(freq[nfft-k]); freq[k] = conj(freq[nfft-k]);
} }