Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TOUT default rowrank #401

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 49 additions & 34 deletions src/RegularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,55 @@ namespace cytnx {
vector<string> tmp = str_split(line, false, ";");
// cytnx_error_msg(tmp.size() != 2, "[ERROR][Network][Fromfile] line:%d %s\n", line_num,
// "Invalid TOUT line");
if (tmp.size() != 2) {
// tmp.push_back("");
tmp.insert(tmp.begin(), "");
}

// handle col-space label
vector<string> ket_labels = str_split(tmp[0], false, ",");
if (ket_labels.size() == 1)
if (ket_labels[0].length() == 0) ket_labels.clear();
for (cytnx_uint64 i = 0; i < ket_labels.size(); i++) {
string tmp = str_strip(ket_labels[i]);
cytnx_error_msg(tmp.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
// cytnx_error_msg((tmp.find_first_not_of("0123456789-") != string::npos),
// "[ERROR][Network][Fromfile] line:%d %s\n", line_num,
// "Invalid TOUT line. label contain non integer.");
labels.push_back(tmp);
}
TOUT_iBondNum = labels.size();

// handle row-space label
vector<string> bra_labels = str_split(tmp[1], false, ",");
if (bra_labels.size() == 1)
if (bra_labels[0].length() == 0) bra_labels.clear();
for (cytnx_uint64 i = 0; i < bra_labels.size(); i++) {
string tmp = str_strip(bra_labels[i]);
cytnx_error_msg(tmp.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
// cytnx_error_msg((tmp.find_first_not_of("0123456789-") != string::npos),
// "[ERROR][Network][Fromfile] line:%d %s\n", line_num,
// "Invalid TOUT line. label contain non integer.");
labels.push_back(tmp);
if (tmp.size() == 1) {
// no ; provided
vector<string> tout_lbls = str_split(line, false, ",");
cytnx_uint64 default_rowrank = tout_lbls.size() / 2;
// handle col-space label
for (cytnx_uint64 i = 0; i < default_rowrank; i++) {
string tmp_ = str_strip(tout_lbls[i]);
cytnx_error_msg(tmp_.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
labels.push_back(tmp_);
}
TOUT_iBondNum = labels.size();
// handle row-space label
for (cytnx_uint64 i = default_rowrank; i < tout_lbls.size(); i++) {
string tmp_ = str_strip(tout_lbls[i]);
cytnx_error_msg(tmp_.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
labels.push_back(tmp_);
}
} else if (tmp.size() == 2) {
// one ;
// handle col-space label
vector<string> ket_labels = str_split(tmp[0], false, ",");
if (ket_labels.size() == 1)
if (ket_labels[0].length() == 0) ket_labels.clear();
for (cytnx_uint64 i = 0; i < ket_labels.size(); i++) {
string tmp = str_strip(ket_labels[i]);
cytnx_error_msg(tmp.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
labels.push_back(tmp);
}
TOUT_iBondNum = labels.size();
// handle row-space label
vector<string> bra_labels = str_split(tmp[1], false, ",");
if (bra_labels.size() == 1)
if (bra_labels[0].length() == 0) bra_labels.clear();
for (cytnx_uint64 i = 0; i < bra_labels.size(); i++) {
string tmp = str_strip(bra_labels[i]);
cytnx_error_msg(tmp.length() == 0,
"[ERROR][Network][Fromfile] line:%d Invalid labels for TOUT line.%s",
line_num, "\n");
labels.push_back(tmp);
}
} else if (tmp.size() > 2) {
// more than one ;
cytnx_error_msg(true, "[ERROR][Network] line:%d Invalid TOUT line.%s", line_num, "\n");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Network_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ TEST_F(NetworkTest, Network_dense_TOUT_no_colon) {
net.PutUniTensors({"A", "B", "C"}, {utdnA, utdnB, utdnC});
auto res = net.Launch();
EXPECT_TRUE(AreNearlyEqTensor(res.get_block(), utdnAns.get_block(), 1e-12));
EXPECT_EQ(res.rowrank(), 0);
EXPECT_EQ(res.rowrank(), 1);
}
Loading