Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-01-18 17:44:18


James Sutherland schrieb:
> Thanks for the suggestions.
>
> The problem is that the containers seem to mandate STL-like semantics
> (ublas::vector wants defined type information like A::size_type and
> A::difference_type), which a raw pointer does not have. If you don't have a
> container, just a pointer to memory (e.g. double*) then it is still not
> clear to me how to get this to work.
>
> My first try was:
> typedef ublas::vector<double,double*> Vec;
> but this gave many compiler errors.
>
This will not work because the second argument has to fulfil the storage
concept. The only solution is to use one of the storage adaptors
mentioned by Sebastian. However you have to be aware that enforcing
external storage causes some problems. Especially the assign_temporary()
optimization does not work in this context. If you only need read only
access or simple assignements then it may work. You can consider all
operations with x.assign(y), x.plus_assign(y), x.minus_assign(y) as
safe. However, x=y, x+=y, x-=y may generate compile errors if the right
hand side expression is more than a simple vector. The reason for these
problems are that ublas internally uses temporaries to avoid aliasing
problems:
x=y is actually X temp(y); x.swap(y);
However the copy constructor is not available when using external
storage (since a deep copy would be required to make this work.)

mfg
Gunter