Boost logo

Ublas :

From: Nico Galoppo (nico_at_[hidden])
Date: 2006-02-22 11:09:42


I've been wondering for a while now what the best way is to return
matrices/matrix_expressions from functions, with the least copying possible.
Until now, I've always gone the way of passing a matrix by reference, resizing
that one to the required size and storing the result in there, like so:

template <typename matrix_type>
void f(matrix_type& m)

Unfortunately the syntax isn't always very clean, and sometimes I have to make
temporaries anyways, before calling f(), like so:

   matrix_type a, b, tmp;
   noalias(a) = b + tmp;

Is there another way to go around this? Something like
template <typename E>
ublas::matrix_container<E> f()
   return ...

   noalias(a) = b + f();

I've looked around for programming guides on how to write your own functions
that deal with ublas matrices, making use of ublas concepts such as template
expressions; I've even followed some of the threads in the ublas mailing list,
but it still is pretty much a mystery to me what goes on under the hood ;)



nico galoppo von borries     @  address: 105 creel st., chapel hill
comp. graphics phd. student  @           north carolina, 27516 USA
UNC, chapel hill             @  phone: +1 (919) 962-1898 (office)
                              @         +1 (919) 942-7609 (home)
                              @  email: nico at cs dot unc dot edu
                              @  homepage:
--- debian linux :: vim powered