New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 1340 - Add operator + to sparse matrix iterator
Summary: Add operator + to sparse matrix iterator
Status: RESOLVED FIXED
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
URL:
Whiteboard:
Keywords: JuniorJob
Depends on:
Blocks: 3.4
  Show dependency treegraph
 
Reported: 2016-11-11 14:45 UTC by Valentin Roussellet
Modified: 2017-01-03 09:36 UTC (History)
3 users (show)



Attachments

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/

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