+1 vote
asked by (220 points)

Hi folks,

I think I just missed it in the docs, but I do not see an easy way to do "fancy" indexing in ITensor. Lets us consider the following example

i = Index(10,"i")
j = Index(20,"j")
k = Index(30,"k")
A = randomITensor(i,j,k)
U,Σ,V = svd(A,(i,j));
u = commonind(U,Σ)
# Now I would like to select all rows where Σ is larger than 15
cn = (Σ.store .> 15)
dim_cn = sum(cn)
c = Index(dim_cn,"c")
selector = zeros(dim_cn,dim(u))
selector[:,cn].= I(dim_cn)
selector = ITensor(selector,c,u)
U_new = selector * U

You see what is my goal: I would like to select specific rows of U. With standard Julia syntax I could just use

U_new = U[:,Σ.> 15]

Thanks a lot.

Best,

v.

commented by (48.1k points)
Hi, good question: the answer is that we haven't implemented this for ITensor yet. But we do have plans to do so. I haven't put an official answer below because Matt Fishman, who is the lead developer for the Julia version, may have more details to offer but we are still in the design and planning phase of how this feature will work. (It's not quite as obvious as it may seem but partly the interface will work in a very similar way to how you are envisioning.)

Best,
Miles

1 Answer

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

The answer Miles gave above in the comments is correct. Unfortunately right now this feature is a work in progress (something we think about periodically but haven't taken the time to implement). To explain some of the complications, the design is fairly straightforward for slicing dense ITensors, but for block sparse ITensors the slicing becomes a bit more subtle (i.e., do you only only allow slicing entire blocks, or also subblocks, of a block sparse ITensor). In addition, the design we were thinking of would involve the indices themselves also getting sliced (i.e. in your example, the U_new tensor would have indices (u, v => 1:dim_cn) where v = commonind(V,Σ), instead of an entirely new index c). Sorry for the inconvenience, the strategy you take above seems fine for now. If you find that it is not fast enough for any reason, or need something more sophisticated that is not available right now, we may be able to help by pointing out certain functions or providing helper functions for certain operations.

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

...