Boost logo

Ublas :

Subject: [ublas] Sparse matrices can contain zeroes
From: Alex Hagen-Zanker (ahh34_at_[hidden])
Date: 2011-02-18 12:08:58


Dear all,

 From the documentation it seems that sparse matrices only contain
non-zero values and that iterators can be used to iterate over all
non-zero values.

I found however that assigning the value 0 to an element puts it into
the matrix and causes iterators to iterate over it.

Am I doing / seeing something wrong?

Thanks, Alex

>>

void test_ublas()
{
   typedef boost::numeric::ublas::mapped_matrix<double> M;
   typedef M::iterator1 I1;
   typedef M::iterator2 I2;

   M m(2, 2, 0);

   m(0,0) = 0;
   m(0,1) = 1;
   m(1,1) = 0;

   for(I1 i1 = m.begin1() ; i1 != m.end1(); ++i1)
     for(I2 i2 = i1.begin() ; i2 != i1.end(); ++i2)
       std::cout << "(" << i2.index1() << "," << i2.index2() << ")=" <<
*i2 << std::endl;
}

<<

(0,0)=0
(0,1)=1
(1,1)=0