How to know modify the index of tensors obtained from SVD

I am trying to write a tensor network renormalization(TNR) code by ITensor. A key step for TNR is the SVD of a tensor. Following the manual of ITensor, I write:

U, S, V = svd(T, (i, j); cutoff = ϵ, maxdim = D_cut)
halfS = sqrt.(S)
U1 = U * halfS
V1 = halfS * V

The next step is to change the indices of the tensor U1 and V1 for next iteration. I am trying to use the delta tensor provided by ITensor. But it becomes a problem that I do not know the index of S. I tried to write

k = Index(size(S,1))
U1 = U1 * δ("Link, v",  k)

but it does not work. I guess that this is because "Link, v" is a tag rather than index. I also try to write

U1 = U1 * δ((dim=3|id=162|"Link,v"),  k)

but it also reports error.

You want to first find the index exactly (the id will change each time), through say commonind and then use replaceind

l1 = commonind(U1,S) # find the linkdim
k = Index(size(S,1)) 
U1 = replaceinds(U1, l1 => k)
4 Likes

Thank you! replaceinds is useful!