# Accessing elements of tensor with variable rank

+1 vote

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?

Best,
Andreas

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 (1.3k points)
The methods .real(vector<IndexVal>) and .cplx(vector<IndexVal>) have been included in ITensor master, by the way.

-Matt
commented by (190 points)
Thank you very much!! This is very helpful!