|
Ublas : |
Subject: Re: [ublas] matrix_row fails with symmetric matrix
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 2010-06-02 18:56:17
Hi Gunter,
I see your point! And indeed you are right also about the
documentation. I wonder if it is not clearer to define some specific
iterator type for such special container or remove the non-const
version in order to avoid misunderstanding. When dealing with a
matrix, iterators are always not as intuitive as they are for vectors.
As I wrote to someone else during this conversation, enforcing the
usage and refining the range of specialiations of the project/range
functions might help and maybe lead to remove the iterators at all.
Unfortunately, all these functions are not always well documented and
intuitive. My nasty example was tricky, but actually using project and
range it works!
for(int i=0;i<mat.size1();i++){
matrix_row<symm_mat> row_i(mat,i);
vector<double> vect(mat.size2()+1,-1.0);
project(vect, range(0,mat.size2())) = row(mat,i);
vlist.push_back(vect);
std::cout<<vect<<std::endl;
}
I found this version quite expressive, but hardly fitting with the
STL-like desing. Indeed, the matrix class offers 16 different methods
for accessing its iterators...quite a mess, isn't it?
How could uBlas look like with an access policy only based on range
and adaptors?
Cheers,Andrea
On 6/2/10, Gunter Winkler <guwi17_at_[hidden]> wrote:
> 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
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: cassioliandre_at_[hidden]
>
-- Andrea Cassioli