This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Retrieve InnerIterator?

Tags: None
(comma "," separated)
jbauer
Registered Member
Posts
25
Karma
0

Retrieve InnerIterator?

Mon Aug 04, 2014 8:09 pm
I have a templated function that takes a sparse matrix:

Code: Select all
template<typename Derived>
void codeThatTakesAMatrix( const Eigen::SparseMatrixBase<Derived>& A )
{
    for( typename Derived::Index k = 0; k < A.outerSize(); ++k )
    {
      for( typename Derived::InnerIterator it( A, col ); it; ++it )
      {
          ...
      }
    }
}


When I run the code under valgrind, however, I get errors at the line "for( typename Derived::InnerIterator it( A, col ); it; ++it )." If I instead replace typename Derived::InnerIterator with the actual type, Eigen::SparseMatrix<double,Eigen::ColMajor>::InnerIterator, there is no problem under valgrind.

Should I obtain the InnerIterator type in some other fashion?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Retrieve InnerIterator?

Sun Aug 10, 2014 12:22 pm
Using Derived::InnerIterator is fine, however, you have to pass A.derived() to its constructor, not directly a SparseMatrixBase.
jbauer
Registered Member
Posts
25
Karma
0

Re: Retrieve InnerIterator?

Sun Aug 17, 2014 10:08 pm
That fixed my problem, thank you! Is there a way to generate a compiler warning for these sorts of bugs?


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]