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

SparseMatrix Compilation problem with Templated Scalar Type

Tags: None
(comma "," separated)
dubmarauder
Registered Member
Posts
14
Karma
0
OS
I have a function that takes a MatrixBase and SparseMatrix. The SparseMatrix is templated on Derived::Scalar. The following code fails to compile:

Code: Select all
template <typename Derived>
void test_func( const Eigen::MatrixBase<Derived>& dense_mat, Eigen::SparseMatrix<typename Derived::Scalar,Eigen::ColMajor>& sparse_mat )
{   
    for( int col = 0; col < sparse_mat.outerSize(); ++col )
    {
        // Commented for loop compiles
        // for( Eigen::SparseMatrix<double,Eigen::ColMajor>::InnerIterator it(sparse_mat,col); it; ++it )
       
        // This for loops does *not* compile
        for( Eigen::SparseMatrix<typename Derived::Scalar,Eigen::ColMajor>::InnerIterator it(sparse_mat,col); it; ++it )
        {
            it.value();
        }
    }
}


The compile fails with: error: expected `;' before 'it'

Where is my mistake in this code? Thanks!
jitseniesen
Registered Member
Posts
204
Karma
2
I think you need to indicate that InnerIterator is a type:

Code: Select all
for( typename Eigen::SparseMatrix<...>::InnerIterator it(sparse_mat,col); it; ++it )
//   ^^^^^^^^
See the last sentence in the section "Iterating over the nonzero coefficients" in the sparse matrix tutorial; follow the link in that sentence for more information.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]