Hi,
Is there any way to create an ITensor "in place" from some already allocated memory?
For example
const int nx = 10;
const int ny = 10;
double* arr = new double[nx * ny] ;
Index i(nx);
Index j(ny);
ITensor A(i, j); //the storage is not yet initialized.
Currently I only know how to copy this allocated memory to the data vector of A as following
vector_no_init<double>& dvec = (*((ITWrap<Dense<double>>*) & (*A.store()))).d.store;
dvec.assign(arr, arr + nx*ny);
What I'd like to do is to "steal" the allocated memory from arr
and use that as the internal data vector of A
. Although memcpy
is in general very fast, sometimes we still want to avoid this overhead in case it is a huge for
loop.
There's some instruction on how to steal the memory by overloading the allocator. But the data vector's allocator has already been overloaded as in the definition of vector no init.
Do you have any idea how to combine the two overloaded versions of allocator, s.t. it can work as described above?
Ce