## Glas :## Re: [glas] dense and sparse vectors |

**From:** Karl Meerbergen (*Karl.Meerbergen_at_[hidden]*)

**Date:** 2005-08-04 09:12:14

**Next message:**David Abrahams: "Re: [glas] using (boost)range or STL style interface [was: dense and sparse vectors]"**Previous message:**Theodore Papadopoulo: "Re: [glas] dense and sparse vectors"**In reply to:**Theodore Papadopoulo: "Re: [glas] dense and sparse vectors"**Next in thread:**Toon Knapen: "Re: [glas] dense and sparse vectors"**Reply:**Toon Knapen: "Re: [glas] dense and sparse vectors"

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.

Karl

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:

>>

>><code>

>>struct all{} ;

>>struct nz{} ;

>>

>>class some_sparse_vector {

>>public:

>>

>> 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, ',')) ;

>>}

>></code>

>>

>>

<snip>

>

>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>.

Karl

**Next message:**David Abrahams: "Re: [glas] using (boost)range or STL style interface [was: dense and sparse vectors]"**Previous message:**Theodore Papadopoulo: "Re: [glas] dense and sparse vectors"**In reply to:**Theodore Papadopoulo: "Re: [glas] dense and sparse vectors"**Next in thread:**Toon Knapen: "Re: [glas] dense and sparse vectors"**Reply:**Toon Knapen: "Re: [glas] dense and sparse vectors"