Skip to content

Commit

Permalink
Refactor base node creation in RegularNetwork class for improved clar…
Browse files Browse the repository at this point in the history
…ity 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.
  • Loading branch information
yingjerkao committed Dec 12, 2024
1 parent 2d5f760 commit f39a137
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/RegularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
node->name = this->names[i];
this->CtTree.base_nodes.push_back(node);
}

// checking if all TN are set in ORDER.
if (isORDER_exist) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f39a137

Please sign in to comment.