+1 vote
asked by (260 points)
edited by

Hi guys,

I have a problem of syntax after I moved from Itensor 1 to Itensor 2. I had a piece of code which allows to create a set of sites, some of them spins the others bosons. I cannot construct anymore the bosons sites with a vector of 'IndexQN'. I have the feeling this is related to the new storage type of the library, but I am not sure :)

Thanks for your help!

inline void SpinBoson::
    constructSites()
    {
    std::vector<IndexQN> I;
    for(int j = 1; j <= N_; ++j)
    {
        if (std::binary_search(Is_.begin(),Is_.end(),j))
        {
                site_.at(j) = IQIndex(nameint("S=1/2 site=",j),
                                Index(nameint("Up for site",j),1,Site),QN(+1,0),
                                Index(nameint("Dn for site",j),1,Site),QN(-1,0));
        }
        else
        {
                for (int r = 0;r<d_;r++)
                {
                        std::string str = format("%d for site %d",r,j); 
                        I.push_back(IndexQN(Index(str,1,Site),QN(0,r)));
                }
                site_.at(j) = IQIndex(nameint("boson site=",j),I);
        }
    }
    }

Note, the error is

no matching constructor for initialization of
  'itensor::IQIndex'
        site_.at(j) = IQIndex(nameint("boson site=",j),I);
                      ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~
itensor2/itensor/iqindex.h:55:5: note: candidate constructor not viable: no known conversion from
      'std::vector<IndexQN>' to 'storage &&' (aka 'vector<itensor::IndexQN> &&') for 2nd argument

2 Answers

0 votes
answered by (70.1k points)

Hi, thanks for the question.

At a glance, the line

site_.at(j) = IQIndex(nameint("boson site=",j),I);

seems to be what's causing the problem. I think all you need to do to fix it is change the line to

site_.at(j) = IQIndex(nameint("boson site=",j),std::move(I));

The 2.0 version of this constructor still accepts a vector but for efficiency reasons requires it to be "moved" into the IQIndex to avoid making a copy. Be aware that afterward the vector I will be empty.

Please give it a try and let me know if it works or not!

0 votes
answered by (260 points)

It seems to work. Thanks a lot!

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

...