
Boost : 
From: Joerg Walter (jhr.walter_at_[hidden])
Date: 20020416 14:18:58
Hi Kresimir,
you wrote:
> Toon Knapen wrote:
>
> > I'm looking for taking a view of a ublas matrix. What I mean is soth
like :
> > matrix< double > a(10,10);
> > size_t row_indices[] = { 0, 3, 4, 9 };
> > size_t column_indices[] = { 2, 3, 7 };
> > matrix_view< matrix< double > > view( a,
> > row_indices, row_indices + 4,
> > column_indices, column_indices +
3 )
> >
> >
> > to give me a 4*3 alias to the original matrix containing rows 0,3,4,9
and
> > columns 2,3,7. Thus view(0,0) == a(0,2)
> >
> > AFAIK soth similar is not possible at the moment (if it is, please let
me
> > know) so I guess I'll give it a shot to implement it in ublas.
>
> I am very interested in this functionality, so, yes, shoot ;o)
>
> Since Joerg didn't reply, I will quote his earlier comment
> on this topic (thread: `slicing and ranges of matrices', Jan. 24th):
>
> ``I believe, that it's difficult to estimate the complexity of
> operations on such a view for sparse matrices (in other words: they
> could be rather inefficient). May be we currently should be more
> interested in some gather and scatter functionality for sparse
> matrices.''
Sorry for the delay, Toon and I discussed the topic offline. In my current
understanding gather and scatter for sparse vectors are defined by the new
BLAS specification along the following line (I'm using some ublas speech):
 Sparse gather: given an sparse vector sv and vector v, gather (sv, v)
doesn't change the index set of sv, but replaces every data value of sv with
the corresponding data value of v. Sample code:
for (it = sv.begin (); it != sv.end (); ++ it)
*it = v (it.index ());
 Sparse gather and zero: given an sparse vector sv and vector v,
gather_and_zero (sv, v) in addition zeroizes the source values. Sample
code:
for (it = sv.begin (); it != sv.end (); ++ it)
*it = v (it.index ()), v (it.index ()) = value_type ();
 Sparse scatter: given an sparse vector sv and vector v, scatter (v, sv)
replaces every data value of v with the corresponding data value of sv for
the index set of sv. Sample code:
for (it = sv.begin (); it != sv.end (); ++ it)
v (it.index ()) = *it;
Interestingly enough, BLAS doesn't define a corresponding matrix
generalization.
With a vector equivalent to Toon's proposed matrix_view one would be able to
implement gather/scatter:
vector v (...);
compressed_vector sv (...);
vector_view vv (sv, sv.index_data ());
vv = v;
should be equivalent to gather and
vector v (...);
compressed_vector sv (...);
vector_view vv (v, sv.index_data ());
vv = sv;
should be equivalent to scatter. So Toon convinced me, that the proposed
extension is sufficent general to be even useful in the BLAS context ;)
The only change to the proposed matrix_view could concern the name: Toon
mentioned, that Blitz++ uses the term 'cartesian product indirection' for
this matrix view (sic!), and we also see some similarity to valarray's
indirect_array. Therefore we agreed for the present to call the beast
matrix_indirect.
Best regards
Joerg
P.S.: Good speed, Toon!
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk