Boost logo

Ublas :

From: Thomas Lemaire (thomas.lemaire_at_[hidden])
Date: 2006-05-16 09:11:45


On Tuesday 16 May 2006 10:48, Gunter Winkler wrote:
> Thomas Lemaire schrieb:
> > Dear list,
> >
> > Here is a sample code:
> >
> > void test() {
> > ublas::matrix<double> M(4,4);
> > ublas::matrix_vector_range<ublas::matrix<double> > t(M,
> > ublas::range(0,3), ublas::range(3,4));
> > std::cout << t;
> > };
> >
> > which I compile _whithout_ -DNDEBUG, execution gives:
> >
> > Assertion failed in file
> > /usr/include/boost/numeric/ublas/matrix_proxy.hpp at line 970:
> > size1 == size2
> > ** std::exception: **
> > bad argument
> >
> > looking at the test which triggers this exception:
> >
> > size_type size () const {
> > return BOOST_UBLAS_SAME (r1_.size (), r2_.size ());
> > }
> >
> > r1_ and r2_ are the two ranges, for me (0,3) and (3,4) which are not of
> > the same size. Why must these ranges be the same size ? Maybe I have
> > misunderstood the doc and the matrix_vector_range concept... I want a
> > sub-vector of the 3 first elements of the last column of M.
>
> matrix_vector_range is a very strange part of the matrix:
>
> It is vector of k elements along a diagonal of the matrix, thus the
> ranges have to have equal size. It is not a sub matrix.
>
> You should try
> project( column(M, i), range(0,3) )
> or
> vector_range<matrix_column<matrix> > r( column(M, i), range(0,3) ); //
> not tested
>
> mfg
> Gunter

ok, thanks a lot ! here is the solution which is working for me, I have to use
an intermediate variable, this is not really elegant...

void test() {
      using namespace ublas;
      
      matrix<double> M(4,4);
      matrix_column<matrix<double> > tc(M, 3);
      vector_range<matrix_column<matrix<double> > > t( tc,
ublas::range(0,3) );

      std::cout << t;
};

quote from the doc:

""
Vector Range
Description
The templated class matrix_vector_range<M> allows addressing a sub vector of a
matrix.
""

I would suggest to change it to something more clear:

""
Vector Range
Description
The templated class matrix_vector_range<M> allows addressing a sub vector
along the diagonal of a matrix, the 'x' here:
o o x o o
o o o x o
o o o o x
o o o o o
""

cheers,

-- 
thomas                              http://www.laas.fr/~tlemaire