diff options
author | Gael Guennebaud <g.gael@free.fr> | 2016-08-29 12:06:37 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2016-08-29 12:06:37 +0200 |
commit | 7e029d1d6ec0eba495a31c72a328ee8160338e44 (patch) | |
tree | ebbaae9b73c903102c94ab1ef6ee01882ddcac0c /doc/snippets/SparseMatrix_coeffs.cpp | |
parent | a93e354d9282cc76de899db412c79f730ff58345 (diff) |
bug #1271: add SparseMatrix::coeffs() methods returning a 1D view of the non zero coefficients.
Diffstat (limited to 'doc/snippets/SparseMatrix_coeffs.cpp')
-rw-r--r-- | doc/snippets/SparseMatrix_coeffs.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/snippets/SparseMatrix_coeffs.cpp b/doc/snippets/SparseMatrix_coeffs.cpp new file mode 100644 index 000000000..f71a69b07 --- /dev/null +++ b/doc/snippets/SparseMatrix_coeffs.cpp @@ -0,0 +1,9 @@ +SparseMatrix<double> A(3,3); +A.insert(1,2) = 0; +A.insert(0,1) = 1; +A.insert(2,0) = 2; +A.makeCompressed(); +cout << "The matrix A is:" << endl << MatrixXd(A) << endl; +cout << "it has " << A.nonZeros() << " stored non zero coefficients that are: " << A.coeffs().transpose() << endl; +A.coeffs() += 10; +cout << "After adding 10 to every stored non zero coefficient, the matrix A is:" << endl << MatrixXd(A) << endl; |