From f39a1373bcae24d4524f95318e331e5ff9bc8e9b Mon Sep 17 00:00:00 2001 From: yjkao Date: Thu, 12 Dec 2024 20:05:25 +0800 Subject: [PATCH] Refactor base node creation in RegularNetwork class for improved clarity and functionality - Clear previous base nodes before creating new ones to ensure a fresh state. - Implemented a loop to properly create and assign names to base nodes using smart pointers. - Enhanced the structure of the FromString method for better readability. These changes aim to streamline the initialization of base nodes in the contraction tree, improving maintainability and clarity in the network setup process. --- src/RegularNetwork.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/RegularNetwork.cpp b/src/RegularNetwork.cpp index d76806d1..4a922217 100644 --- a/src/RegularNetwork.cpp +++ b/src/RegularNetwork.cpp @@ -536,6 +536,14 @@ namespace cytnx { this->tensors.resize(this->names.size()); this->CtTree.base_nodes.resize(this->names.size()); + this->CtTree.base_nodes.clear(); + + // Create base nodes properly + for(size_t i = 0; i < this->names.size(); i++) { + auto node = std::make_shared(); + node->name = this->names[i]; + this->CtTree.base_nodes.push_back(node); + } // checking if all TN are set in ORDER. if (isORDER_exist) { @@ -640,7 +648,7 @@ namespace cytnx { CtTree.build_default_contraction_tree(); } this->einsum_path = CtTree_to_eisumpath(CtTree, names); - } + } // end of FromString void RegularNetwork::Fromfile(const string &fname) { const cytnx_uint64 MAXLINES = 1024;