Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2005-06-03 05:05:25


On Thursday 02 June 2005 22:11, christopher diggins wrote:
> Looking briefly at the following code:
>
> template<class AE>
> BOOST_UBLAS_INLINE
> vector &operator += (const vector_expression<AE> &ae) {
> // return assign (self_type (*this + ae));
> self_type temporary (*this + ae);
> return assign_temporary (temporary);
> }
>

We can not change this because the assignment of vector expressions is the
core idea of ublas.

> template<class AE>
> BOOST_UBLAS_INLINE
> vector &operator += (const self_type& a) {
> for (int i=size()-1; i >= 0; --i) {
> data_[i] += a.data_[i]
> }
> }

Better (read: more general) code would be:
         template<class AE>
         BOOST_UBLAS_INLINE
         vector &operator += (const self_type& a) {
            plus_assign(a);
         }

but applying this to all ublas types is quite a lot of work (any volunteers?)
so its far down at the list of important changes and there is a very simple
workaround:
  Use plus_assign() or noalias() directly in your code.

mfg
Gunter