yingjerkao / uni10

Official Repo for Uni10
28 stars 9 forks source link

UniTensor::assign change from CTYPE back to RTYPE #18

Closed chengyanlai closed 7 years ago

chengyanlai commented 7 years ago

An uniTensor seems to be transformed back to RTYPE after callingUniTensor::assign(const std::vector<Bond>& _bond) when it was initialized as CTYPE.

The current function reads

UniTensor& UniTensor::assign(const std::vector<Bond>& _bond){
  try{
    UniTensor T(_bond);
    *this = T;
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function UniTensor::assign(std::vector<Bond>&):");
  }
  return *this;
}

which uses UniTensor(const std::vector<Bond>& _bonds, const std::string& _name) and that constructor calls initUniT(RTYPE) by default. This action abandons the original tensor type, and it always turns into an RTYPE uniTensor.

A quick fix can be the following

UniTensor& UniTensor::assign(const std::vector<Bond>& _bond){
  try{
    if ( this->typeID() == 1 ){
      UniTensor T("R", _bond);
      *this = T;
    }else if ( this->typeID() == 2 ){
      UniTensor T("C", _bond);
      *this = T;
    }
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function UniTensor::assign(std::vector<Bond>&):");
  }
  return *this;
}

If this is not caused on purpose, it should be fixed.

Yun-Hsuan commented 7 years ago

Hi, very thanks for your report. This is a bug indeed. I will fix it soon.

yingjerkao commented 7 years ago

Fixed by 6a426aead29cb8a20b9d12722e995adb8f41df4e