traversal and update of sparse matrix

View: New views
1 Messages — Rating Filter:   Alert me  

traversal and update of sparse matrix

by Rechnan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

I want to traverse a sparse matrix and update its elements. I have slightly modified the iteration example from the tutorial, and the traversal works fine. But if I add an inserter, the programm terminates with

     Assertion failed: ma.starts[major+1] <= ma.my_nnz, file c:\programme\boost\boost_1_39\boost\numeric\mtl\matrix\compressed2d.hpp, line 209

If I put the inserter in an own subroutine, everything works fine, but the update process is very slow (probably due to the repeated construction of the inserter).
Has someone an idea how to solve this problem?


The source code is as follows:

template <typename Matrix>
void f(Matrix& m)
{
        using traits::range_generator; using traits::range::min;

        // Choose between row and column traversal
    typedef typename min<range_generator<tag::row, Matrix>, range_generator<tag::col, Matrix> >::type range_type;
    range_type                                                      my_range;

    // Type of outer cursor
    typedef typename range_type::type                               c_type;
    // Type of inner cursor
    typedef typename traits::range_generator<tag::nz, c_type>::type ic_type;

    // Define the property maps
    typename traits::row<Matrix>::type                              row(m);
    typename traits::col<Matrix>::type                              col(m);
    typename traits::const_value<Matrix>::type                      value(m);

    // Type of m's elements
    typedef typename Collection<Matrix>::value_type value_type;
        mtl::matrix::inserter<Matrix, update_store<value_type> > ins(m);

        for (c_type cursor(my_range.begin(m)), cend(my_range.end(m)); cursor != cend; ++cursor)
                for (ic_type icursor(begin<tag::nz>(cursor)), icend(end<tag::nz>(cursor)); icursor != icend; ++icursor){
                        int r=row(*icursor);
                        int c=col(*icursor);
                        double insval=6.789; // or something else
                        ins[r][c] << insval;
                }
}


Thanks in advance,

Burkhard