bug #1271: add SparseMatrix::coeffs() methods returning a 1D view of the non zero coefficients.

This commit is contained in:
Gael Guennebaud
2016-08-29 12:06:37 +02:00
parent a93e354d92
commit 7e029d1d6e
3 changed files with 38 additions and 0 deletions

View File

@@ -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;