00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_DIAGONALCOEFFS_H
00026 #define EIGEN_DIAGONALCOEFFS_H
00027
00042 template<typename MatrixType>
00043 struct ei_traits<DiagonalCoeffs<MatrixType> >
00044 {
00045 typedef typename MatrixType::Scalar Scalar;
00046 typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
00047 typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
00048 enum {
00049 RowsAtCompileTime = int(MatrixType::SizeAtCompileTime) == Dynamic ? Dynamic
00050 : EIGEN_SIZE_MIN(MatrixType::RowsAtCompileTime,
00051 MatrixType::ColsAtCompileTime),
00052 ColsAtCompileTime = 1,
00053 MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
00054 : EIGEN_SIZE_MIN(MatrixType::MaxRowsAtCompileTime,
00055 MatrixType::MaxColsAtCompileTime),
00056 MaxColsAtCompileTime = 1,
00057 Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit),
00058 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
00059 };
00060 };
00061
00062 template<typename MatrixType> class DiagonalCoeffs
00063 : public MatrixBase<DiagonalCoeffs<MatrixType> >
00064 {
00065 public:
00066
00067 EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalCoeffs)
00068
00069 inline DiagonalCoeffs(const MatrixType& matrix) : m_matrix(matrix) {}
00070
00071 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs)
00072
00073 inline int rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); }
00074 inline int cols() const { return 1; }
00075
00076 inline Scalar& coeffRef(int row, int)
00077 {
00078 return m_matrix.const_cast_derived().coeffRef(row, row);
00079 }
00080
00081 inline const Scalar coeff(int row, int) const
00082 {
00083 return m_matrix.coeff(row, row);
00084 }
00085
00086 inline Scalar& coeffRef(int index)
00087 {
00088 return m_matrix.const_cast_derived().coeffRef(index, index);
00089 }
00090
00091 inline const Scalar coeff(int index) const
00092 {
00093 return m_matrix.coeff(index, index);
00094 }
00095
00096 protected:
00097
00098 const typename MatrixType::Nested m_matrix;
00099 };
00100
00109 template<typename Derived>
00110 inline DiagonalCoeffs<Derived>
00111 MatrixBase<Derived>::diagonal()
00112 {
00113 return DiagonalCoeffs<Derived>(derived());
00114 }
00115
00117 template<typename Derived>
00118 inline const DiagonalCoeffs<Derived>
00119 MatrixBase<Derived>::diagonal() const
00120 {
00121 return DiagonalCoeffs<Derived>(derived());
00122 }
00123
00124 #endif // EIGEN_DIAGONALCOEFFS_H