Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-06-01 15:54:58

On Wednesday 01 June 2005 18:20, christopher diggins wrote:

> > I have the impression that the ublas::vector has size 0 since you use the
> > default constructor.
> >
> > I also think that vector::operator+=() creates a temporary to store the
> > data from the right-hand side. The right-hand side can be any
> > vector_expression. In order to avoid temporaries you could use
> > tmp.plus_assign( v ) and tmp.minus_assign( v ).
> >
> > If this is the case, this might explain some loss of performance in
> > Christopher's tests.
> >
> > Best,
> >
> > Karl
> That would definitely explain it and would be consistent the differences
> are so great between my old Celeron and Stefan's Pentium 4 which have
> wildly different sized caches.

I don't believe the differences will be explained by you processors. I suspect
there is something in how you are building the code. Is NDEBUG defined?

> However, the question then become why would the operators be implemented so
If this is related to the aliasing issue then sadly the answer is that finding
variable alias at compile time is out of the scope of what C++ can easily do.
If you don't like tmp.plus_assign( v) you can use
        noalias(tmp) += v;

> On a related subject, is the fastest way to multiply two matricies as
> follows:
> X = prod(A,B);

For small matrices this will probably be a good choice. For many larger dense
matrices the 'axpy' variants will probably be better.

All the best,
Michael Stevens Systems Engineering

Navigation Systems, Estimation and
                 Bayesian Filtering