xref: /aosp_15_r20/external/eigen/doc/snippets/SparseMatrix_coeffs.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li SparseMatrix<double> A(3,3);
2*bf2c3715SXin Li A.insert(1,2) = 0;
3*bf2c3715SXin Li A.insert(0,1) = 1;
4*bf2c3715SXin Li A.insert(2,0) = 2;
5*bf2c3715SXin Li A.makeCompressed();
6*bf2c3715SXin Li cout << "The matrix A is:" << endl << MatrixXd(A) << endl;
7*bf2c3715SXin Li cout << "it has " << A.nonZeros() << " stored non zero coefficients that are: " << A.coeffs().transpose() << endl;
8*bf2c3715SXin Li A.coeffs() += 10;
9*bf2c3715SXin Li cout << "After adding 10 to every stored non zero coefficient, the matrix A is:" << endl << MatrixXd(A) << endl;
10