Boost logo

Ublas :

From: Jesse Manning (manning.jesse_at_[hidden])
Date: 2008-04-28 11:34:57


I don't think the '+' operator is overloaded for vectors and scalar values.

You could do something like this:

typedef boost::numeric::ublas::vector<double> Vector_t;
typedef boost::numeric::ublas::scalar_vector<typename Vector_t::value_type>
ScalarVector_t;

Vector_t a(3);
a(0) = 0; a(1)=1; a(2)=2;

Vector_t b = a * 0.5; //works

Vector_t c(a);
c.plus_assign(ScalarVector_t(c.size(), 0.5));

Hope this helps.

Jesse

On Mon, Apr 28, 2008 at 10:27 AM, Johan Compen <johanc_at_[hidden]> wrote:

> Hi,
>
> I'm using the vector and matrix classes in Boost to convert some
> Matlab code to C++. I'm having troubles with this code:
>
> typedef boost::numeric::ublas::vector<double> Vector_t;
> Vector_t a(3);
> a(0) = 0; a(1)=1; a(2)=2;
>
> Vector_t b = a * 0.5; //works
> Vector_t c = a + 0.5; //compiler error
>
> error C2678: binary '+' : no operator found which takes a left-hand
> operand of type 'Vector_t' (or there is no acceptable conversion)
>
> How can I solve this? How can I add a constant value to each element
> in a vector?
>
> bye, Johan.
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>