Commit 0b4c8ec3 authored by Michael Goette's avatar Michael Goette

fixed sanitize function

parent 6841e6d4
Pipeline #1033 failed with stages
in 9 minutes and 55 seconds
......@@ -256,7 +256,8 @@ namespace xerus {
void TensorNetwork::sanitize() {
std::vector<size_t> idMap(nodes.size());
std::vector<size_t> idMap(nodes.size());
std::vector<size_t> oldNodes;
// Move nodes
size_t newId = 0, oldId = 0;
......@@ -265,20 +266,36 @@ namespace xerus {
idMap[oldId] = newId;
if (newId != oldId) { std::swap(nodes[newId], nodes[oldId]); }
newId++;
} else {
oldNodes.emplace_back(oldId);
}
}
// Update external links
for (TensorNetwork::Link &l : externalLinks) {
l.other = idMap[l.other];
}
// Update links
nodes.resize(newId);
size_t external_index_pos = externalLinks.size();
size_t count_nodes = 0;
for (TensorNode &n : nodes) {
size_t count_links = 0;
for (TensorNetwork::Link &l : n.neighbors) {
if (!l.external) { l.other = idMap[l.other]; }
bool new_external = std::find(oldNodes.begin(), oldNodes.end(), l.other) != oldNodes.end();
if (!l.external && !new_external) { l.other = idMap[l.other]; }
if (!l.external && new_external) {
l.other = -1;
l.indexPosition = external_index_pos;
external_index_pos++;
l.external = true;
externalLinks.emplace_back(count_nodes,count_links,l.dimension,false);
dimensions.emplace_back(l.dimension);
}
count_links++;
}
}
// Update external links
for (TensorNetwork::Link &l : externalLinks) {
l.other = idMap[l.other];
count_nodes++;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment