Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-09-05 04:00:55


On Monday 04 September 2006 10:41, Abdel-Aziz NDIAYE wrote:
> Hi,
> I'm a developper at inria and I work on Siconos project. I'd like to know
> how can I build ublas vectors which are contiguous in the memory. For
> instance, let suppose that I want to have a std::vector of pointers on
> ublas vector and I want the ublas vectors pointed to be contiguous in the
> memory, how can I do that ? Thanks.

This is quite difficult, because preallocated storage does not work in
connection with aliasing and hidden temporaries.

Although there are some things to try.

* Use local (stack, inline) storage: bounded_vector, bounded_array
* use a (constant) view of external data, see example 3 at
  http://www.bauv.unibw-muenchen.de/~winkler/ublas/examples/index.html
* use a big vector and a list of vector_range(s)
* have a look at the other storage adaptors (and improve the implementation)

The main difficulties are:
* whenever the right hand side of an expression may alias data of the left
hand side, the result is computed in a temporary vector. Then
assign_temporary() swaps only the pointers to the storage (if possible).
* the semantics of the copy constructor is to create an exact copy with
distinct storage. This does not work with external storage because you have
no way to (externally) allocate storage.

mfg
Gunter