mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
fix bug #294: add a diagonal() method to SparseMatrix (const)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user