Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-11-27 03:37:19

Am Samstag, 25. November 2006 11:55 schrieb Giuseppe Bilotta:

> Neither range nor slice can give me this, although I could use four
> ranges and assemble the submatrix this way. However, this is overkill
> (and slow) when all I need it for is a comfortable (templatable via
> matrix_expression) way to access "all but" certain rows/columns of a
> matrix.

There is no matrix proxy with such a functionality in ublas. I suggest
the following procedure:

// untested, should work with ublas::range, ublas::slice,
// std::set<int> (or any sorted list of integers)
template < class MATRIX, class RANGE >
void foo(const MATRIX & A, RANGE & r)
  typename MATRIX::const_iterator1 it = A.begin1();
  typename MATRIX::const_iterator1 it_end = A.end1();
  typename RANGE::const_iterator ex = r.begin();
  typename RANGE::const_iterator ex_end = r.end();
  for ( ; it != it_end ; ++it) {
    while ( it != it_end && ex != ex_end && it.index1() >= (*ex)) {
     if (it.index1() == (*ex)) { ++it; }
    // do something with it.begin() ... it.end()

> Essentially, what I need is a "range complement" proxy, although I
> would only use it with single rows and columns. Would it be hard to
> implement? I'm a little daunted by the complexity of the uBLAS
> internals ...

Implementing this would mean to copy the matrix_range class and rewrite
the iterators (and some other functions that return size and similar
data). You can even try to unify matrix_range and matrix_slice into a
general submatrix proxy that accepts arbitrary lists of rows and cols.
The main work is to do a good iterator implementation.