Boost logo

Ublas :

From: Server Levent Yilmaz (leventyilmaz_at_[hidden])
Date: 2007-06-07 00:09:55


Hi,

On 6/6/07, Georg Baum <Georg.Baum_at_[hidden]> wrote:
>
> Am Mittwoch, 6. Juni 2007 22:23 schrieb Server Levent Yilmaz:
>
> > What is a proper way, if any, to adapt a ublas (dense) vector around a
> > legacy pointer to data?
>
> Something like this should work:
>
> #include <boost/version.hpp>
> #if BOOST_VERSION >= 103400
> typedef boost::numeric::ublas::carray_adaptor<double> array_adaptor;
> #else
> typedef boost::numeric::ublas::array_adaptor<double> array_adaptor;
> #endif
> typedef vector<double, rcarray_adaptor> array_vector;
>
>
> Replace double with the datatype you need. Then you can use array_vector
> like this:
>
> int n = 5;
> double *array = new double[5];
>
> array_vector v;
> v.data().resize(n, array);

This is interesting (and obviously works, thank you).. Yet, I can not help
but mention that the interface of array_adaptor is quite counter-intuitive.
For instance the following :

array_vector v(n, array_adaptor(n,array));

ends up NOT using the adapted pointer but allocating its own space... Some
reading of the source code reveals that array_adaptor is curiously trying to
manage its own memory whenever it can (for example at copy construction)...
Isn't that the job of unbounded_array? Isn't the whole purpose of
array_adaptor is to delegate memory management _wholly_ to the user? (this
is no rhetoric, really, what else is array_adaptor used for?)

And curiously asking if I may, why did carray_adaptor removed? (renamed?)

L.

-- 
Server Levent Yilmaz
Mechanical Engineering
University of Pittsburgh