0 votes
asked by (140 points)

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

Please log in or register to answer this question.

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...