0 votes
asked by (760 points)

Hi,

I know that one can use setElt to get a "sub-tensor" for a specific index value in a specific Index by the following code

auto i = Index(4); auto j = Index(3); auto T = randomITensor(i,j); T *= setElt(i=2);

My question is, is there (or will it be implemented) a function to get a more general sub-tensor, for example i from 1 to 2 and j from 2 to 3?

If this task is essentially to copy the corresponding elements or to multiple zeros, I may implement it by myself, but I wonder if there is a more efficient way to do it.

Thanks!
Chia-Min

1 Answer

+1 vote
answered by (70.1k points)
selected by
 
Best answer

Hi Chia-Min,
Thanks for the question. Basically, we don't have that feature right now, because many technicalites of C++ make it quite a lot of work to add. (And there are some design questions about ITensor itself too that we need to think through.) But tensor slicing is high on our list of features we want to add, and plan to add.

So for now, please do an element by element approach. In some cases, such as two-index tensors, you can also construct an ITensor from a matrix using the matrixITensor function. So this could be helpful for you.

If you're really stuck or find this kind of step to be a bottleneck, please let me and Matt know, and we could definitely help you craft some custom code which works on a lower layer of ITensor to help your specific case.

Finally, we think adding tensor slicing support will be much easier and go a lot faster in Julia, so we plan to explore it in the new ITensors.jl first.

Best,
Miles

commented by (14.1k points)
I'll also emphasize that I think slicing Dense ITensors would be fairly straightforward, but slicing BlockSparse ITensors (as you might imagine) may require some more thought about the right way to do it. So that is probably why this hasn't been implemented yet, I think there are at least a few subtle design questions that would take some time to work out.

As Miles said, there are probably some helper functions that would make some of these operations easier, even without the fully featured slicing functionality in place. If something seems more challenging than it should be, give us an example of what you are trying to do and we should be able to help.
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

...