From 079fa81d84fc1efb3df784dc840f09b507db5536 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 15 Jul 2009 19:53:08 +0200 Subject: add a TridiagonalMatrix wrapper arround BandMatrix, and extend this latter --- Eigen/src/Core/BandMatrix.h | 64 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'Eigen/src/Core/BandMatrix.h') diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index aaf907593..8136724dd 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -28,11 +28,19 @@ /** \nonstableyet * \class BandMatrix * - * \brief + * \brief Represents a rectangular matrix with a banded storage * - * \param + * \param _Scalar Numeric type, i.e. float, double, int + * \param Rows Number of rows, or \b Dynamic + * \param Cols Number of columns, or \b Dynamic + * \param Supers Number of super diagonal + * \param Subs Number of sub diagonal + * \param _Options A combination of either \b RowMajor or \b ColMajor, and of \b SelfAdjoint + * The former controls storage order, and defaults to column-major. The latter controls + * whether the matrix represent a selfadjoint matrix in which case either Supers of Subs + * have to be null. * - * \sa + * \sa class TridiagonalMatrix */ template struct ei_traits > @@ -94,7 +102,8 @@ class BandMatrix : public MultiplierBase col(int i) { int j = i - (cols() - supers() + 1); @@ -112,25 +121,31 @@ class BandMatrix : public MultiplierBase struct DiagonalIntReturnType { enum { + ReturnOpposite = (Options&SelfAdjoint) && (Index>0 && Supers==0 || Index<0 && Subs==0), + Conjugate = ReturnOpposite && NumTraits::IsComplex, + ActualIndex = ReturnOpposite ? -Index : Index, DiagonalSize = RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic ? Dynamic - : Index<0 - ? EIGEN_ENUM_MIN(ColsAtCompileTime, RowsAtCompileTime + Index) - : EIGEN_ENUM_MIN(RowsAtCompileTime, ColsAtCompileTime - Index) + : ActualIndex<0 + ? EIGEN_ENUM_MIN(ColsAtCompileTime, RowsAtCompileTime + ActualIndex) + : EIGEN_ENUM_MIN(RowsAtCompileTime, ColsAtCompileTime - ActualIndex) }; - typedef Block Type; + typedef Block BuildType; + typedef typename ei_meta_if,NestByValue >, + BuildType>::ret Type; }; /** \returns a vector expression of the \a Index -th sub or super diagonal */ template inline typename DiagonalIntReturnType::Type diagonal() { - return typename DiagonalIntReturnType::Type(m_data, supers()-Index, std::max(0,Index), 1, diagonalLength(Index)); + return typename DiagonalIntReturnType::BuildType(m_data, supers()-Index, std::max(0,Index), 1, diagonalLength(Index)); } /** \returns a vector expression of the \a Index -th sub or super diagonal */ template inline const typename DiagonalIntReturnType::Type diagonal() const { - return typename DiagonalIntReturnType::Type(m_data, supers()-Index, std::max(0,Index), 1, diagonalLength(Index)); + return typename DiagonalIntReturnType::BuildType(m_data, supers()-Index, std::max(0,Index), 1, diagonalLength(Index)); } /** \returns a vector expression of the \a i -th sub or super diagonal */ @@ -171,4 +186,33 @@ class BandMatrix : public MultiplierBase m_subs; }; +/** \nonstableyet + * \class TridiagonalMatrix + * + * \brief Represents a tridiagonal matrix + * + * \param _Scalar Numeric type, i.e. float, double, int + * \param Size Number of rows and cols, or \b Dynamic + * \param _Options Can be 0 or \b SelfAdjoint + * + * \sa class BandMatrix + */ +template +class TridiagonalMatrix : public BandMatrix +{ + typedef BandMatrix Base; + public: + TridiagonalMatrix(int size = Size) : Base(size,size,1,1) {} + + inline typename Base::template DiagonalIntReturnType<1>::Type super() + { return Base::template diagonal<1>(); } + inline const typename Base::template DiagonalIntReturnType<1>::Type super() const + { return Base::template diagonal<1>(); } + inline typename Base::template DiagonalIntReturnType<-1>::Type sub() + { return Base::template diagonal<-1>(); } + inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const + { return Base::template diagonal<-1>(); } + protected: +}; + #endif // EIGEN_BANDMATRIX_H -- cgit v1.2.3