Boost logo

Ublas :

From: Georg Baum (Georg.Baum_at_[hidden])
Date: 2007-06-06 16:45:17


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);

Georg