Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-02-17 11:10:27

On Wednesday 15 February 2006 14:38, Riccardo Rossi wrote:
> Dear Gunther,
> first of all thanks for your quick answer, i have however a doubt
> concerning your proposal:

finally, the long reply.

First: I fixed the example nested.cpp to create a (nearly) working block
matrix. Please run and read the comments along the source lines. (I compiled
it using the CVS_HEAD)

> first of all let's consider the code

> Matrix A(3,3);
> Vector b(3);
> Vector c(3);
> c = A * b;
> using boost 1.32.0 ( i still didn't upgrade to 1.33.1) i get an error
> message due to the existance of two candidates for the overloaded operator
> * ... the error message reads

There have been big changes from 1.32 to 1.33. Please try a current version,

The error results from the fact, that there is _no_ overload of the operator*
for matrix vector products. You have to use prod() everywhere or define your

Vector operator*(const Matrix m, const Vector v)
{ return prod<Vector>(m, v); }

this needs a temporary vector - as you already mentioned.

The second way is to change the result type to the result type of prod (which
is a model of vector_expression: matrix_vector_binary1, see

Something like this should work:

typename matrix_vector_binary1_traits<Matrix::value_type, Matrix,
                                      Vector::value_type, Vector
operator*(const Matrix & m, const Vector& v)
  return prod(m,v);


PS: I made bounded_matrix::matrix_type public
Index: matrix.hpp
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/matrix.hpp,v
retrieving revision 1.67
diff -u -p -r1.67 matrix.hpp
--- matrix.hpp 2 Feb 2006 18:33:59 -0000 1.67
+++ matrix.hpp 17 Feb 2006 15:48:49 -0000
@@ -951,8 +951,8 @@ namespace boost { namespace numeric { na
     class bounded_matrix:
         public matrix<T, L, bounded_array<T, M * N> > {
- typedef matrix<T, L, bounded_array<T, M * N> > matrix_type;
+ typedef matrix<T, L, bounded_array<T, M * N> > matrix_type;
         typedef typename matrix_type::size_type size_type;
         static const size_type max_size1 = M;
         static const size_type max_size2 = N;