diff options
author | Gael Guennebaud <g.gael@free.fr> | 2011-12-04 21:49:21 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2011-12-04 21:49:21 +0100 |
commit | 82f9aa194d0b516b3041e04fde808c3404ba0473 (patch) | |
tree | 01c8162f82a5777dbcf705f9955082d4b67c7176 /Eigen/src | |
parent | 69966e90e12c0c9eef4f370945e23fcc943ee8a6 (diff) |
fix bug #294: add a diagonal() method to SparseMatrix (const)
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/SparseCholesky/SimplicialCholesky.h | 2 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrix.h | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky.h b/Eigen/src/SparseCholesky/SimplicialCholesky.h index edc83a018..4aa366343 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky.h @@ -398,7 +398,7 @@ public: /** \returns the determinant of the underlying matrix from the current factorization */ Scalar determinant() const { - Scalar detL = Diagonal<const CholMatrixType>(Base::m_matrix).prod(); + Scalar detL = Base::m_matrix.diagonal().prod(); return internal::abs2(detL); } }; diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index d4530e4ce..f5c5a5be3 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -70,6 +70,28 @@ struct traits<SparseMatrix<_Scalar, _Options, _Index> > }; }; +template<typename _Scalar, int _Options, typename _Index, int DiagIndex> +struct traits<Diagonal<const SparseMatrix<_Scalar, _Options, _Index>, DiagIndex> > +{ + typedef SparseMatrix<_Scalar, _Options, _Index> MatrixType; + typedef typename nested<MatrixType>::type MatrixTypeNested; + typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested; + + typedef _Scalar Scalar; + typedef Dense StorageKind; + typedef _Index Index; + typedef MatrixXpr XprKind; + + enum { + RowsAtCompileTime = Dynamic, + ColsAtCompileTime = 1, + MaxRowsAtCompileTime = Dynamic, + MaxColsAtCompileTime = 1, + Flags = 0, + CoeffReadCost = _MatrixTypeNested::CoeffReadCost*10 + }; +}; + } // end namespace internal template<typename _Scalar, int _Options, typename _Index> @@ -514,6 +536,9 @@ class SparseMatrix m_data.resize(size); } + /** \returns a const expression of the diagonal coefficients */ + const Diagonal<const SparseMatrix> diagonal() const { return *this; } + /** Default constructor yielding an empty \c 0 \c x \c 0 matrix */ inline SparseMatrix() : m_outerSize(-1), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) |