From 8313e6b40524cb6eee81aae2453af8552cfb88b9 Mon Sep 17 00:00:00 2001 From: j9263178 Date: Tue, 5 Dec 2023 23:48:52 +0800 Subject: [PATCH 1/2] change tout default rowrank --- src/RegularNetwork.cpp | 84 +++++++++++++++++++++++++----------------- tests/Network_test.cpp | 2 +- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/RegularNetwork.cpp b/src/RegularNetwork.cpp index fd556773..c7f55115 100644 --- a/src/RegularNetwork.cpp +++ b/src/RegularNetwork.cpp @@ -43,40 +43,56 @@ namespace cytnx { vector 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 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 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); + std::cout << tmp; + if (tmp.size() == 1) { + // no ; provided + vector 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 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 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"); } } diff --git a/tests/Network_test.cpp b/tests/Network_test.cpp index a306a0b2..a13763c9 100644 --- a/tests/Network_test.cpp +++ b/tests/Network_test.cpp @@ -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); } From 2524799385393592cd9aacc8f49796abd4c02658 Mon Sep 17 00:00:00 2001 From: j9263178 Date: Tue, 5 Dec 2023 23:55:29 +0800 Subject: [PATCH 2/2] remove debug outputs --- src/RegularNetwork.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RegularNetwork.cpp b/src/RegularNetwork.cpp index c7f55115..d681f49e 100644 --- a/src/RegularNetwork.cpp +++ b/src/RegularNetwork.cpp @@ -43,7 +43,6 @@ namespace cytnx { vector tmp = str_split(line, false, ";"); // cytnx_error_msg(tmp.size() != 2, "[ERROR][Network][Fromfile] line:%d %s\n", line_num, // "Invalid TOUT line"); - std::cout << tmp; if (tmp.size() == 1) { // no ; provided vector tout_lbls = str_split(line, false, ",");