Boost logo

Glas :

Re: [glas] dense and sparse vectors

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2005-08-04 09:12:14

Hello All,

Which algorithms are going to use collections? If we answer this
question first, we can also decide which iterators are needed to
implement these algorithms? (We may conclude that iterators are not good
at all).

One example given by Toon is printing a vector.


Theodore Papadopoulo wrote:

>On Wed, 2005-08-03 at 22:20 +0200, Toon Knapen wrote:
>>Thinking about it again, your approach gave me following idea which
>>probably is more generic: The begin and end functions just take a 'tag'
>>as argument that specifies if the iterator iterates over all elements or
>>only all structural non-zero's. So soth like:
>>struct all{} ;
>>struct nz{} ;
>>class some_sparse_vector {
>> iterator<all> begin(all) ;
>> iterator<nz> begin(nz) ;
>> iterator<all> end(all) ;
>> iterator<nz> end(nz) ;
>>} ;
>>// so implementing a function that prints the elements
>>// in a vector might be implemented to print all elements
>>// or only the non-zero's
>>template < class Tag >
>>void print(const some_sparse_vector& v)
>> std::copy( v.begin(Tag()), v.end(Tag()),
>> std::ostream_iterator(std::cout, ',')) ;


>The proposal of templated iterators (combined with my other suggestion)
>is exactly what I'm doing in my various multidimensionnal data
>structures (matrices, meshes or images...).
>for (Image2D::const_iterator<row> i=im.begin();i!=im.end();++i) { ... }
>And you can replace Image2D by Mesh,Matrix,... and row by (column,
>elemt, pixel, ...).

We have not had a discussion about submatrices, subvectors, ranges etc.
I suppose that the best way to do this is by first selecting a row-view
on the matrix and then apply an iterator to that?
Here, we can also consider an iterator<all> or an iterator<nz>.