Make SparseMatrix::coeff() returns a const reference and add a non const version of SparseMatrix::diagonal()

This commit is contained in:
Gael Guennebaud
2014-12-01 14:41:39 +01:00
parent b1f9f603a0
commit b26e697182
3 changed files with 42 additions and 7 deletions

View File

@@ -472,6 +472,12 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
SparseMatrixType m2(rows, cols);
initSparse<Scalar>(density, refMat2, m2);
VERIFY_IS_APPROX(m2.diagonal(), refMat2.diagonal().eval());
VERIFY_IS_APPROX(const_cast<const SparseMatrixType&>(m2).diagonal(), refMat2.diagonal().eval());
initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag);
m2.diagonal() += refMat2.diagonal();
refMat2.diagonal() += refMat2.diagonal();
VERIFY_IS_APPROX(m2, refMat2);
}
// test conservative resize