Boost logo

Ublas :

Subject: Re: [ublas] matrix_row fails with symmetric matrix
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2010-06-02 15:10:26


Hello Andrea,

Andrea Cassioli schrieb:
> Well uBlas iterators are quite misleading sometimes, but maybe I'm
> confused. In my example, I expect a row_iterator to be usable as any
> other iterator. For instance, a loop like the following should be
> legal:
>
> typedef symmetric_matrix<double> symm_mat;
> symm_mat mat(5);
> for(int i=0;i<mat.size1();i++)
> mat(i,i)=0.0;
> for(int i=0;i<mat.size1();i++)
> for(int j=i+1;j<mat.size2();j++)
> mat(i,j)=i*j+1;
>
> std::list<vector<double> > vlist;
>
> vector<double> vect(mat.size2()+1,-1.0);
> std::cout << mat;
> for(int i=0;i<mat.size1();i++){
>
> matrix_row<symm_mat> row_i(mat,i);
> matrix_row<symm_mat>::iterator it_b(row_i.begin());
>

here you choose the mutable iterator which iterates of the elements
which are writable. Thus it iterates over the triangle. If you change to
const_iterator then you will see all matrix elements. We should
precisely explain this in the iterator documentation!

> int j(0);
> while(it_b!=row_i.end()){
> vect[j]=*it_b;
> j++;it_b++;
> }
>
> vlist.push_back(vect);
> std::cout<<vect<<std::endl;
> }
>
>
> what happens is that the end() is the diagonal! so the row ends
> there....this is not acceptable in my opinion.
>
mfg
Gunter

__________ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 5167 (20100602) __________

E-Mail wurde geprüft mit ESET NOD32 Antivirus.

http://www.eset.com