This bugzilla service is closed. All entries have been migrated to
Bug 1165 - Simplified Standard STL Iterator for SparseMatrix
Summary: Simplified Standard STL Iterator for SparseMatrix
Status: RESOLVED DUPLICATE of bug 1104
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.4 (development)
Hardware: All All
: Normal Feature Request
Assignee: Nobody
Depends on:
Reported: 2016-02-13 04:02 UTC by citibeth
Modified: 2019-12-04 15:25 UTC (History)
3 users (show)


Description citibeth 2016-02-13 04:02:54 UTC
The following in the docs show how to iterate through a SparseMatrix:

SparseMatrix<double> mat(rows,cols);
for (int k=0; k<mat.outerSize(); ++k)
  for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
    it.row();   // row index
    it.col();   // col index (here it is equal to k)
    it.index(); // inner index, here it is equal to it.row()

There needs to be a standard STL way that hides the nested loop inside the iterator.  This is not hard to do.  An example of the simple standard API would be:

SparseMatrix<double> mat(rows,cols);
for (SparseMatrix<double>::iterator it = mat.begin(); it != mat.end(); ++it) {
    it.row();   // row index
    it.col();   // col index (here it is equal to k)

Similarly, there should be a standard STL iterator for SparseVector.
Comment 1 Christoph Hertzberg 2016-02-15 17:16:14 UTC
Ok, why not.
However, I'd suggest that *it returns (a view compatible to) the Triplet class, i.e., you can access the entities via it->value(), it->row(), it->col(). That way you can directly pass iterators to a setFromTriplets() function.
Comment 2 Matthew Woehlke 2016-04-05 17:54:30 UTC

*** This bug has been marked as a duplicate of bug 1104 ***
Comment 3 Nobody 2019-12-04 15:25:52 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.