This bugzilla service is closed. All entries have been migrated to
Bug 1340 - Add operator + to sparse matrix iterator
Summary: Add operator + to sparse matrix iterator
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - matrix products (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Feature Request
Assignee: Valentin Roussellet
Keywords: JuniorJob
Depends on:
Blocks: 3.4
  Show dependency treegraph
Reported: 2016-11-11 14:45 UTC by Valentin Roussellet
Modified: 2019-12-04 16:29 UTC (History)
3 users (show)


Description Valentin Roussellet 2016-11-11 14:45:02 UTC
SparseCompressedBase::InnerIterator has operator++ but no operator += or operator +

There are cases where one may want to advance the operator by N elements. Currently, the only way to do it is with a for loop such as :

for (i = 0; i < N; ++i,++iterator) {}

An addition operator is easy to define within the iterator :

inline InnerIterator& operator+=( _Index i ) { m_id += i; return *this; }
inline InnerIterator operator+( _Index i ) 
    InnerIterator result = *this;
    result += i;
    return result;

Similarly, a substraction operator can be added to ReverseIterator

inline ReverseInnerIterator& operator-=( _Index i ) { m_id -= i; return *this; }
inline ReverseInnerIterator operator-( _Index i ) 
    ReverseInnerIterator result = *this;
    result -= i;
    return result;
Comment 1 Valentin Roussellet 2016-11-11 14:47:35 UTC
with s/_Index/Index or Eigen 3.3, of course.
Comment 2 Gael Guennebaud 2016-11-14 14:37:45 UTC
Why not. Feel free to propose a patch. There are two instances to be updated in Eigen/src/SparseCore/SparseCompressedBase.h and Eigen/src/Core/CoreIterators.h respectively.
Comment 3 Valentin Roussellet 2016-12-28 17:40:23 UTC
I submitted pull request #284 with a proposed patch for this issue
Comment 4 Gael Guennebaud 2017-01-03 09:36:41 UTC
Comment 5 Nobody 2019-12-04 16:29:49 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.