This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 1340

Summary: Add operator + to sparse matrix iterator
Product: Eigen Reporter: Valentin Roussellet <val.roussellet>
Component: Core - matrix productsAssignee: Valentin Roussellet <val.roussellet>
Status: RESOLVED FIXED    
Severity: Feature Request CC: chtz, gael.guennebaud, val.roussellet
Priority: Normal Keywords: JuniorJob
Version: 3.3 (current stable)   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 814    

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

https://bitbucket.org/eigen/eigen/pull-requests/284/proposed-patch-for-bug-1340/diff
Comment 4 Gael Guennebaud 2017-01-03 09:36:41 UTC
https://bitbucket.org/eigen/eigen/commits/21315953153c/
Comment 5 Nobody 2019-12-04 16:29:49 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com'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: https://gitlab.com/libeigen/eigen/issues/1340.