Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2005-11-23 03:56:34

On Tuesday 22 November 2005 14:36, you wrote:
> Dear Gunter,
> i am trying to iterate over the non zeroes of a single
> row...
> in particular i would like to set to a given number all of the nonzeroes of
> the CompresseMatrix i consider BUT JUST FOR ONE ROW at choice, NOT for all
> the matrix
> is there any way to do this?


compressed_matrix<double, row_major> A(10,10);
matrix_row< compressed_matrix<double, row_major> > rA( A, 5 );

iterate from rA.begin() to rA.end().


You have to carefully distinguish const_iterators (which iterate over all
nonzeroes) and mutable iterators (which iterate over all elements). So you
probably have to use the const iterators to find the nonzeroes and use the
operator(i,j) to assign the value. This is clearly not optimal, but the only
way that is currently supported for all matrix types.

If you want a fast specialized routine, you can use
index1_data(), index2_data() and value_data() directly. Please look at the
source in matrix_sparse.hpp and at the axpy_prod in operation.hpp for more