0 votes
asked by (190 points)

Hi,

I have seen variants of this question on the forum but unable to find a good solution still. Given a tensor, I want to fix some indices and get the sub-tensor. The present elT function demands all indices be fixed.

A workaround that I could think of was this :
Replace the index that needs to be fixed by another 1-dimensional index (using delta tensor). This does select a sub-tensor but I couldn't find a way to change the default index value ("1") to some other value for the 1-dimensional index (to extract other possibilities).

Any leads to do this efficiently will be appreciated.

Thanks
Aditya

1 Answer

+2 votes
answered by (70.1k points)

Hi Aditya,
Good to meet you in person and discuss, but I'll also post the answer here.

To fix, clamp, or set an index to a particular value, a good solution is to contract the tensor with another tensor produced by the "setElt" function. (See setElt on this page: http://itensor.org/docs.cgi?vers=cppv3&page=classes/itensor). Calling setElt(i=n) makes an ITensor which has the index "i" and has a component 1.0 in the nth entry, and zero otherwise.

Then you can multiply it by your tensor T like: T *= setElt(i=n).

Best regards,
Miles

commented by (190 points)
Hi Miles,

It was indeed great to meet you in person. Thank you for all the valuable inputs. I'll leave a small function here to get a sub-tensor with a subset of indices fixed. The function assumes that the indices and values are ordered (this is the responsibility of the user).

    ITensor
    GetSubTensor(ITensor T,std::vector<Index> const &indices,std::vector<int> values )
    {
        ITensor retT;
        for(unsigned int l=0;l<indices.size();l++)
        {
            if(l==0)
                retT = T*setElt(indices[l]=values[l]);
            else
                retT*=setElt(indices[l]=values[l]);
        }
       return retT;
    }

Thanks
Aditya
commented by (70.1k points)
Great - always nice to have sample code for other people to use!
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

...