From: Vardan Akopian (vakopian_at_[hidden])
Date: 2005-07-11 21:22:34
On 7/10/05, Dima Sorkin <dsorkin_at_[hidden]> wrote:
> Does ublas have some adaptor for data sitting in raw memory ?
> For example, I have some "array" of N doubles, sitting in the
> memory starting from the pointer "(double *)pd",and has
> a stride "d". If I want to multuply ublas NxN sparse matrix
> with this vector, should I first copy the data into
> ublas-vector ?
Yes, there is a way to share your existing array with a ublas contaner.
Here is how:
double * d = new double;
using namespace boost::numeric::ublas;
shallow_array_adaptor<double> shared(3, d);
vector<double, shallow_array_adaptor<double> > shared_vec(3, shared);
// now shared_vec and d use the same storage
(I did not verify the code above by compiling, but I routinely use
this way in a large project).
I'm also interested if there are other ways besides the shallow array adaptor.
> Same about Blitz-array.
Yes again: http://www.oonumerics.org/blitz/manual/blitz02.html#l41