+1 vote
asked by (220 points)

Is it possible to access the elements of tensor whose rank is not known at compile time (but given via the input system):

If the rank of Itensor T is known (and in this case 3), I would use:

auto rt = T.real(i(1),j(1),k(1));

with i, j, k indices of T.

However, if T is dynamically built during the execution of the program and is a rank N tensor (with N an input parameter), how can I access its elements (without a lot if else clauses and hard coding the above expression for every possible value of N) ?

Is there something like

auto rt = T.real( list_of_index_values ) 

with listofindex_values a dynamically built (unpacked) list or tuple of Index values?

Thank you in advance!

Best,
Andreas

1 Answer

0 votes
answered by (14.1k points)

Hey Andreas,

That functionality had not been available, but that is a good suggestion (.set() can currently accept vector<IndexVal>, so it is inconsistent that .real() and .cplx() can't).

I made a pull request for adding .real(vector<IndexVal>) and .cplx(vector<IndexVal>), is that sufficient for your use case?

Cheers,
Matt

commented by (14.1k points)
The methods `.real(vector<IndexVal>)` and `.cplx(vector<IndexVal>)` have been included in ITensor master, by the way.

-Matt
commented by (220 points)
Thank you very much!! This is very helpful!
commented by (240 points)
It would be very helpful if we could do all these operations on tensor slices, by passing partial vectors of IndexVal. This is a common functionality elsewhere that I feel it's missing now.
commented by (14.1k points)
You can currently  take slices of an ITensor using a special single element tensor: http://www.itensor.org/docs.cgi?vers=cppv2&page=classes/single_itensor

Unfortunately, this makes a copy of the ITensor data, so it doesn't help with the problem of setting a block of elements of an ITensor. We plan to add more functionality for taking partial slices of ITensors as "views" into the data. However, it takes some thought to come up with a nice interface for doing that when the ITensors have QN conservation (block sparse storage).
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

...