Eigne Matrix Class Library

Dependents:   MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more

Committer:
ykuroda
Date:
Thu Oct 13 04:07:23 2016 +0000
Revision:
0:13a5d365ba16
First commint, Eigne Matrix Class Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ykuroda 0:13a5d365ba16 1 // This file is part of Eigen, a lightweight C++ template library
ykuroda 0:13a5d365ba16 2 // for linear algebra.
ykuroda 0:13a5d365ba16 3 //
ykuroda 0:13a5d365ba16 4 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
ykuroda 0:13a5d365ba16 5 //
ykuroda 0:13a5d365ba16 6 // This Source Code Form is subject to the terms of the Mozilla
ykuroda 0:13a5d365ba16 7 // Public License v. 2.0. If a copy of the MPL was not distributed
ykuroda 0:13a5d365ba16 8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
ykuroda 0:13a5d365ba16 9
ykuroda 0:13a5d365ba16 10 #ifndef EIGEN_BANDMATRIX_H
ykuroda 0:13a5d365ba16 11 #define EIGEN_BANDMATRIX_H
ykuroda 0:13a5d365ba16 12
ykuroda 0:13a5d365ba16 13 namespace Eigen {
ykuroda 0:13a5d365ba16 14
ykuroda 0:13a5d365ba16 15 namespace internal {
ykuroda 0:13a5d365ba16 16
ykuroda 0:13a5d365ba16 17 template<typename Derived>
ykuroda 0:13a5d365ba16 18 class BandMatrixBase : public EigenBase<Derived>
ykuroda 0:13a5d365ba16 19 {
ykuroda 0:13a5d365ba16 20 public:
ykuroda 0:13a5d365ba16 21
ykuroda 0:13a5d365ba16 22 enum {
ykuroda 0:13a5d365ba16 23 Flags = internal::traits<Derived>::Flags,
ykuroda 0:13a5d365ba16 24 CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
ykuroda 0:13a5d365ba16 25 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
ykuroda 0:13a5d365ba16 26 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
ykuroda 0:13a5d365ba16 27 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
ykuroda 0:13a5d365ba16 28 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
ykuroda 0:13a5d365ba16 29 Supers = internal::traits<Derived>::Supers,
ykuroda 0:13a5d365ba16 30 Subs = internal::traits<Derived>::Subs,
ykuroda 0:13a5d365ba16 31 Options = internal::traits<Derived>::Options
ykuroda 0:13a5d365ba16 32 };
ykuroda 0:13a5d365ba16 33 typedef typename internal::traits<Derived>::Scalar Scalar;
ykuroda 0:13a5d365ba16 34 typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType;
ykuroda 0:13a5d365ba16 35 typedef typename DenseMatrixType::Index Index;
ykuroda 0:13a5d365ba16 36 typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType;
ykuroda 0:13a5d365ba16 37 typedef EigenBase<Derived> Base;
ykuroda 0:13a5d365ba16 38
ykuroda 0:13a5d365ba16 39 protected:
ykuroda 0:13a5d365ba16 40 enum {
ykuroda 0:13a5d365ba16 41 DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic))
ykuroda 0:13a5d365ba16 42 ? 1 + Supers + Subs
ykuroda 0:13a5d365ba16 43 : Dynamic,
ykuroda 0:13a5d365ba16 44 SizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime)
ykuroda 0:13a5d365ba16 45 };
ykuroda 0:13a5d365ba16 46
ykuroda 0:13a5d365ba16 47 public:
ykuroda 0:13a5d365ba16 48
ykuroda 0:13a5d365ba16 49 using Base::derived;
ykuroda 0:13a5d365ba16 50 using Base::rows;
ykuroda 0:13a5d365ba16 51 using Base::cols;
ykuroda 0:13a5d365ba16 52
ykuroda 0:13a5d365ba16 53 /** \returns the number of super diagonals */
ykuroda 0:13a5d365ba16 54 inline Index supers() const { return derived().supers(); }
ykuroda 0:13a5d365ba16 55
ykuroda 0:13a5d365ba16 56 /** \returns the number of sub diagonals */
ykuroda 0:13a5d365ba16 57 inline Index subs() const { return derived().subs(); }
ykuroda 0:13a5d365ba16 58
ykuroda 0:13a5d365ba16 59 /** \returns an expression of the underlying coefficient matrix */
ykuroda 0:13a5d365ba16 60 inline const CoefficientsType& coeffs() const { return derived().coeffs(); }
ykuroda 0:13a5d365ba16 61
ykuroda 0:13a5d365ba16 62 /** \returns an expression of the underlying coefficient matrix */
ykuroda 0:13a5d365ba16 63 inline CoefficientsType& coeffs() { return derived().coeffs(); }
ykuroda 0:13a5d365ba16 64
ykuroda 0:13a5d365ba16 65 /** \returns a vector expression of the \a i -th column,
ykuroda 0:13a5d365ba16 66 * only the meaningful part is returned.
ykuroda 0:13a5d365ba16 67 * \warning the internal storage must be column major. */
ykuroda 0:13a5d365ba16 68 inline Block<CoefficientsType,Dynamic,1> col(Index i)
ykuroda 0:13a5d365ba16 69 {
ykuroda 0:13a5d365ba16 70 EIGEN_STATIC_ASSERT((Options&RowMajor)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
ykuroda 0:13a5d365ba16 71 Index start = 0;
ykuroda 0:13a5d365ba16 72 Index len = coeffs().rows();
ykuroda 0:13a5d365ba16 73 if (i<=supers())
ykuroda 0:13a5d365ba16 74 {
ykuroda 0:13a5d365ba16 75 start = supers()-i;
ykuroda 0:13a5d365ba16 76 len = (std::min)(rows(),std::max<Index>(0,coeffs().rows() - (supers()-i)));
ykuroda 0:13a5d365ba16 77 }
ykuroda 0:13a5d365ba16 78 else if (i>=rows()-subs())
ykuroda 0:13a5d365ba16 79 len = std::max<Index>(0,coeffs().rows() - (i + 1 - rows() + subs()));
ykuroda 0:13a5d365ba16 80 return Block<CoefficientsType,Dynamic,1>(coeffs(), start, i, len, 1);
ykuroda 0:13a5d365ba16 81 }
ykuroda 0:13a5d365ba16 82
ykuroda 0:13a5d365ba16 83 /** \returns a vector expression of the main diagonal */
ykuroda 0:13a5d365ba16 84 inline Block<CoefficientsType,1,SizeAtCompileTime> diagonal()
ykuroda 0:13a5d365ba16 85 { return Block<CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
ykuroda 0:13a5d365ba16 86
ykuroda 0:13a5d365ba16 87 /** \returns a vector expression of the main diagonal (const version) */
ykuroda 0:13a5d365ba16 88 inline const Block<const CoefficientsType,1,SizeAtCompileTime> diagonal() const
ykuroda 0:13a5d365ba16 89 { return Block<const CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
ykuroda 0:13a5d365ba16 90
ykuroda 0:13a5d365ba16 91 template<int Index> struct DiagonalIntReturnType {
ykuroda 0:13a5d365ba16 92 enum {
ykuroda 0:13a5d365ba16 93 ReturnOpposite = (Options&SelfAdjoint) && (((Index)>0 && Supers==0) || ((Index)<0 && Subs==0)),
ykuroda 0:13a5d365ba16 94 Conjugate = ReturnOpposite && NumTraits<Scalar>::IsComplex,
ykuroda 0:13a5d365ba16 95 ActualIndex = ReturnOpposite ? -Index : Index,
ykuroda 0:13a5d365ba16 96 DiagonalSize = (RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic)
ykuroda 0:13a5d365ba16 97 ? Dynamic
ykuroda 0:13a5d365ba16 98 : (ActualIndex<0
ykuroda 0:13a5d365ba16 99 ? EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime, RowsAtCompileTime + ActualIndex)
ykuroda 0:13a5d365ba16 100 : EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime - ActualIndex))
ykuroda 0:13a5d365ba16 101 };
ykuroda 0:13a5d365ba16 102 typedef Block<CoefficientsType,1, DiagonalSize> BuildType;
ykuroda 0:13a5d365ba16 103 typedef typename internal::conditional<Conjugate,
ykuroda 0:13a5d365ba16 104 CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>,BuildType >,
ykuroda 0:13a5d365ba16 105 BuildType>::type Type;
ykuroda 0:13a5d365ba16 106 };
ykuroda 0:13a5d365ba16 107
ykuroda 0:13a5d365ba16 108 /** \returns a vector expression of the \a N -th sub or super diagonal */
ykuroda 0:13a5d365ba16 109 template<int N> inline typename DiagonalIntReturnType<N>::Type diagonal()
ykuroda 0:13a5d365ba16 110 {
ykuroda 0:13a5d365ba16 111 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
ykuroda 0:13a5d365ba16 112 }
ykuroda 0:13a5d365ba16 113
ykuroda 0:13a5d365ba16 114 /** \returns a vector expression of the \a N -th sub or super diagonal */
ykuroda 0:13a5d365ba16 115 template<int N> inline const typename DiagonalIntReturnType<N>::Type diagonal() const
ykuroda 0:13a5d365ba16 116 {
ykuroda 0:13a5d365ba16 117 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
ykuroda 0:13a5d365ba16 118 }
ykuroda 0:13a5d365ba16 119
ykuroda 0:13a5d365ba16 120 /** \returns a vector expression of the \a i -th sub or super diagonal */
ykuroda 0:13a5d365ba16 121 inline Block<CoefficientsType,1,Dynamic> diagonal(Index i)
ykuroda 0:13a5d365ba16 122 {
ykuroda 0:13a5d365ba16 123 eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
ykuroda 0:13a5d365ba16 124 return Block<CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
ykuroda 0:13a5d365ba16 125 }
ykuroda 0:13a5d365ba16 126
ykuroda 0:13a5d365ba16 127 /** \returns a vector expression of the \a i -th sub or super diagonal */
ykuroda 0:13a5d365ba16 128 inline const Block<const CoefficientsType,1,Dynamic> diagonal(Index i) const
ykuroda 0:13a5d365ba16 129 {
ykuroda 0:13a5d365ba16 130 eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
ykuroda 0:13a5d365ba16 131 return Block<const CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
ykuroda 0:13a5d365ba16 132 }
ykuroda 0:13a5d365ba16 133
ykuroda 0:13a5d365ba16 134 template<typename Dest> inline void evalTo(Dest& dst) const
ykuroda 0:13a5d365ba16 135 {
ykuroda 0:13a5d365ba16 136 dst.resize(rows(),cols());
ykuroda 0:13a5d365ba16 137 dst.setZero();
ykuroda 0:13a5d365ba16 138 dst.diagonal() = diagonal();
ykuroda 0:13a5d365ba16 139 for (Index i=1; i<=supers();++i)
ykuroda 0:13a5d365ba16 140 dst.diagonal(i) = diagonal(i);
ykuroda 0:13a5d365ba16 141 for (Index i=1; i<=subs();++i)
ykuroda 0:13a5d365ba16 142 dst.diagonal(-i) = diagonal(-i);
ykuroda 0:13a5d365ba16 143 }
ykuroda 0:13a5d365ba16 144
ykuroda 0:13a5d365ba16 145 DenseMatrixType toDenseMatrix() const
ykuroda 0:13a5d365ba16 146 {
ykuroda 0:13a5d365ba16 147 DenseMatrixType res(rows(),cols());
ykuroda 0:13a5d365ba16 148 evalTo(res);
ykuroda 0:13a5d365ba16 149 return res;
ykuroda 0:13a5d365ba16 150 }
ykuroda 0:13a5d365ba16 151
ykuroda 0:13a5d365ba16 152 protected:
ykuroda 0:13a5d365ba16 153
ykuroda 0:13a5d365ba16 154 inline Index diagonalLength(Index i) const
ykuroda 0:13a5d365ba16 155 { return i<0 ? (std::min)(cols(),rows()+i) : (std::min)(rows(),cols()-i); }
ykuroda 0:13a5d365ba16 156 };
ykuroda 0:13a5d365ba16 157
ykuroda 0:13a5d365ba16 158 /**
ykuroda 0:13a5d365ba16 159 * \class BandMatrix
ykuroda 0:13a5d365ba16 160 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 161 *
ykuroda 0:13a5d365ba16 162 * \brief Represents a rectangular matrix with a banded storage
ykuroda 0:13a5d365ba16 163 *
ykuroda 0:13a5d365ba16 164 * \param _Scalar Numeric type, i.e. float, double, int
ykuroda 0:13a5d365ba16 165 * \param Rows Number of rows, or \b Dynamic
ykuroda 0:13a5d365ba16 166 * \param Cols Number of columns, or \b Dynamic
ykuroda 0:13a5d365ba16 167 * \param Supers Number of super diagonal
ykuroda 0:13a5d365ba16 168 * \param Subs Number of sub diagonal
ykuroda 0:13a5d365ba16 169 * \param _Options A combination of either \b #RowMajor or \b #ColMajor, and of \b #SelfAdjoint
ykuroda 0:13a5d365ba16 170 * The former controls \ref TopicStorageOrders "storage order", and defaults to
ykuroda 0:13a5d365ba16 171 * column-major. The latter controls whether the matrix represents a selfadjoint
ykuroda 0:13a5d365ba16 172 * matrix in which case either Supers of Subs have to be null.
ykuroda 0:13a5d365ba16 173 *
ykuroda 0:13a5d365ba16 174 * \sa class TridiagonalMatrix
ykuroda 0:13a5d365ba16 175 */
ykuroda 0:13a5d365ba16 176
ykuroda 0:13a5d365ba16 177 template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options>
ykuroda 0:13a5d365ba16 178 struct traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
ykuroda 0:13a5d365ba16 179 {
ykuroda 0:13a5d365ba16 180 typedef _Scalar Scalar;
ykuroda 0:13a5d365ba16 181 typedef Dense StorageKind;
ykuroda 0:13a5d365ba16 182 typedef DenseIndex Index;
ykuroda 0:13a5d365ba16 183 enum {
ykuroda 0:13a5d365ba16 184 CoeffReadCost = NumTraits<Scalar>::ReadCost,
ykuroda 0:13a5d365ba16 185 RowsAtCompileTime = _Rows,
ykuroda 0:13a5d365ba16 186 ColsAtCompileTime = _Cols,
ykuroda 0:13a5d365ba16 187 MaxRowsAtCompileTime = _Rows,
ykuroda 0:13a5d365ba16 188 MaxColsAtCompileTime = _Cols,
ykuroda 0:13a5d365ba16 189 Flags = LvalueBit,
ykuroda 0:13a5d365ba16 190 Supers = _Supers,
ykuroda 0:13a5d365ba16 191 Subs = _Subs,
ykuroda 0:13a5d365ba16 192 Options = _Options,
ykuroda 0:13a5d365ba16 193 DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
ykuroda 0:13a5d365ba16 194 };
ykuroda 0:13a5d365ba16 195 typedef Matrix<Scalar,DataRowsAtCompileTime,ColsAtCompileTime,Options&RowMajor?RowMajor:ColMajor> CoefficientsType;
ykuroda 0:13a5d365ba16 196 };
ykuroda 0:13a5d365ba16 197
ykuroda 0:13a5d365ba16 198 template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options>
ykuroda 0:13a5d365ba16 199 class BandMatrix : public BandMatrixBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
ykuroda 0:13a5d365ba16 200 {
ykuroda 0:13a5d365ba16 201 public:
ykuroda 0:13a5d365ba16 202
ykuroda 0:13a5d365ba16 203 typedef typename internal::traits<BandMatrix>::Scalar Scalar;
ykuroda 0:13a5d365ba16 204 typedef typename internal::traits<BandMatrix>::Index Index;
ykuroda 0:13a5d365ba16 205 typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType;
ykuroda 0:13a5d365ba16 206
ykuroda 0:13a5d365ba16 207 inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs)
ykuroda 0:13a5d365ba16 208 : m_coeffs(1+supers+subs,cols),
ykuroda 0:13a5d365ba16 209 m_rows(rows), m_supers(supers), m_subs(subs)
ykuroda 0:13a5d365ba16 210 {
ykuroda 0:13a5d365ba16 211 }
ykuroda 0:13a5d365ba16 212
ykuroda 0:13a5d365ba16 213 /** \returns the number of columns */
ykuroda 0:13a5d365ba16 214 inline Index rows() const { return m_rows.value(); }
ykuroda 0:13a5d365ba16 215
ykuroda 0:13a5d365ba16 216 /** \returns the number of rows */
ykuroda 0:13a5d365ba16 217 inline Index cols() const { return m_coeffs.cols(); }
ykuroda 0:13a5d365ba16 218
ykuroda 0:13a5d365ba16 219 /** \returns the number of super diagonals */
ykuroda 0:13a5d365ba16 220 inline Index supers() const { return m_supers.value(); }
ykuroda 0:13a5d365ba16 221
ykuroda 0:13a5d365ba16 222 /** \returns the number of sub diagonals */
ykuroda 0:13a5d365ba16 223 inline Index subs() const { return m_subs.value(); }
ykuroda 0:13a5d365ba16 224
ykuroda 0:13a5d365ba16 225 inline const CoefficientsType& coeffs() const { return m_coeffs; }
ykuroda 0:13a5d365ba16 226 inline CoefficientsType& coeffs() { return m_coeffs; }
ykuroda 0:13a5d365ba16 227
ykuroda 0:13a5d365ba16 228 protected:
ykuroda 0:13a5d365ba16 229
ykuroda 0:13a5d365ba16 230 CoefficientsType m_coeffs;
ykuroda 0:13a5d365ba16 231 internal::variable_if_dynamic<Index, Rows> m_rows;
ykuroda 0:13a5d365ba16 232 internal::variable_if_dynamic<Index, Supers> m_supers;
ykuroda 0:13a5d365ba16 233 internal::variable_if_dynamic<Index, Subs> m_subs;
ykuroda 0:13a5d365ba16 234 };
ykuroda 0:13a5d365ba16 235
ykuroda 0:13a5d365ba16 236 template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
ykuroda 0:13a5d365ba16 237 class BandMatrixWrapper;
ykuroda 0:13a5d365ba16 238
ykuroda 0:13a5d365ba16 239 template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
ykuroda 0:13a5d365ba16 240 struct traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
ykuroda 0:13a5d365ba16 241 {
ykuroda 0:13a5d365ba16 242 typedef typename _CoefficientsType::Scalar Scalar;
ykuroda 0:13a5d365ba16 243 typedef typename _CoefficientsType::StorageKind StorageKind;
ykuroda 0:13a5d365ba16 244 typedef typename _CoefficientsType::Index Index;
ykuroda 0:13a5d365ba16 245 enum {
ykuroda 0:13a5d365ba16 246 CoeffReadCost = internal::traits<_CoefficientsType>::CoeffReadCost,
ykuroda 0:13a5d365ba16 247 RowsAtCompileTime = _Rows,
ykuroda 0:13a5d365ba16 248 ColsAtCompileTime = _Cols,
ykuroda 0:13a5d365ba16 249 MaxRowsAtCompileTime = _Rows,
ykuroda 0:13a5d365ba16 250 MaxColsAtCompileTime = _Cols,
ykuroda 0:13a5d365ba16 251 Flags = LvalueBit,
ykuroda 0:13a5d365ba16 252 Supers = _Supers,
ykuroda 0:13a5d365ba16 253 Subs = _Subs,
ykuroda 0:13a5d365ba16 254 Options = _Options,
ykuroda 0:13a5d365ba16 255 DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
ykuroda 0:13a5d365ba16 256 };
ykuroda 0:13a5d365ba16 257 typedef _CoefficientsType CoefficientsType;
ykuroda 0:13a5d365ba16 258 };
ykuroda 0:13a5d365ba16 259
ykuroda 0:13a5d365ba16 260 template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
ykuroda 0:13a5d365ba16 261 class BandMatrixWrapper : public BandMatrixBase<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
ykuroda 0:13a5d365ba16 262 {
ykuroda 0:13a5d365ba16 263 public:
ykuroda 0:13a5d365ba16 264
ykuroda 0:13a5d365ba16 265 typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar;
ykuroda 0:13a5d365ba16 266 typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType;
ykuroda 0:13a5d365ba16 267 typedef typename internal::traits<BandMatrixWrapper>::Index Index;
ykuroda 0:13a5d365ba16 268
ykuroda 0:13a5d365ba16 269 inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs)
ykuroda 0:13a5d365ba16 270 : m_coeffs(coeffs),
ykuroda 0:13a5d365ba16 271 m_rows(rows), m_supers(supers), m_subs(subs)
ykuroda 0:13a5d365ba16 272 {
ykuroda 0:13a5d365ba16 273 EIGEN_UNUSED_VARIABLE(cols);
ykuroda 0:13a5d365ba16 274 //internal::assert(coeffs.cols()==cols() && (supers()+subs()+1)==coeffs.rows());
ykuroda 0:13a5d365ba16 275 }
ykuroda 0:13a5d365ba16 276
ykuroda 0:13a5d365ba16 277 /** \returns the number of columns */
ykuroda 0:13a5d365ba16 278 inline Index rows() const { return m_rows.value(); }
ykuroda 0:13a5d365ba16 279
ykuroda 0:13a5d365ba16 280 /** \returns the number of rows */
ykuroda 0:13a5d365ba16 281 inline Index cols() const { return m_coeffs.cols(); }
ykuroda 0:13a5d365ba16 282
ykuroda 0:13a5d365ba16 283 /** \returns the number of super diagonals */
ykuroda 0:13a5d365ba16 284 inline Index supers() const { return m_supers.value(); }
ykuroda 0:13a5d365ba16 285
ykuroda 0:13a5d365ba16 286 /** \returns the number of sub diagonals */
ykuroda 0:13a5d365ba16 287 inline Index subs() const { return m_subs.value(); }
ykuroda 0:13a5d365ba16 288
ykuroda 0:13a5d365ba16 289 inline const CoefficientsType& coeffs() const { return m_coeffs; }
ykuroda 0:13a5d365ba16 290
ykuroda 0:13a5d365ba16 291 protected:
ykuroda 0:13a5d365ba16 292
ykuroda 0:13a5d365ba16 293 const CoefficientsType& m_coeffs;
ykuroda 0:13a5d365ba16 294 internal::variable_if_dynamic<Index, _Rows> m_rows;
ykuroda 0:13a5d365ba16 295 internal::variable_if_dynamic<Index, _Supers> m_supers;
ykuroda 0:13a5d365ba16 296 internal::variable_if_dynamic<Index, _Subs> m_subs;
ykuroda 0:13a5d365ba16 297 };
ykuroda 0:13a5d365ba16 298
ykuroda 0:13a5d365ba16 299 /**
ykuroda 0:13a5d365ba16 300 * \class TridiagonalMatrix
ykuroda 0:13a5d365ba16 301 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 302 *
ykuroda 0:13a5d365ba16 303 * \brief Represents a tridiagonal matrix with a compact banded storage
ykuroda 0:13a5d365ba16 304 *
ykuroda 0:13a5d365ba16 305 * \param _Scalar Numeric type, i.e. float, double, int
ykuroda 0:13a5d365ba16 306 * \param Size Number of rows and cols, or \b Dynamic
ykuroda 0:13a5d365ba16 307 * \param _Options Can be 0 or \b SelfAdjoint
ykuroda 0:13a5d365ba16 308 *
ykuroda 0:13a5d365ba16 309 * \sa class BandMatrix
ykuroda 0:13a5d365ba16 310 */
ykuroda 0:13a5d365ba16 311 template<typename Scalar, int Size, int Options>
ykuroda 0:13a5d365ba16 312 class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor>
ykuroda 0:13a5d365ba16 313 {
ykuroda 0:13a5d365ba16 314 typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base;
ykuroda 0:13a5d365ba16 315 typedef typename Base::Index Index;
ykuroda 0:13a5d365ba16 316 public:
ykuroda 0:13a5d365ba16 317 TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {}
ykuroda 0:13a5d365ba16 318
ykuroda 0:13a5d365ba16 319 inline typename Base::template DiagonalIntReturnType<1>::Type super()
ykuroda 0:13a5d365ba16 320 { return Base::template diagonal<1>(); }
ykuroda 0:13a5d365ba16 321 inline const typename Base::template DiagonalIntReturnType<1>::Type super() const
ykuroda 0:13a5d365ba16 322 { return Base::template diagonal<1>(); }
ykuroda 0:13a5d365ba16 323 inline typename Base::template DiagonalIntReturnType<-1>::Type sub()
ykuroda 0:13a5d365ba16 324 { return Base::template diagonal<-1>(); }
ykuroda 0:13a5d365ba16 325 inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const
ykuroda 0:13a5d365ba16 326 { return Base::template diagonal<-1>(); }
ykuroda 0:13a5d365ba16 327 protected:
ykuroda 0:13a5d365ba16 328 };
ykuroda 0:13a5d365ba16 329
ykuroda 0:13a5d365ba16 330 } // end namespace internal
ykuroda 0:13a5d365ba16 331
ykuroda 0:13a5d365ba16 332 } // end namespace Eigen
ykuroda 0:13a5d365ba16 333
ykuroda 0:13a5d365ba16 334 #endif // EIGEN_BANDMATRIX_H