Skip to content
Snippets Groups Projects
Commit 422ac1ce authored by Maxence Naud's avatar Maxence Naud
Browse files

[Depreciated] replaceWith()

parent 4b3540a3
No related branches found
No related tags found
1 merge request!45[Upd] replace() instead of replaceWith() in GraphView
...@@ -531,68 +531,7 @@ void Aidge::GraphView::insertParent(NodePtr childNode, ...@@ -531,68 +531,7 @@ void Aidge::GraphView::insertParent(NodePtr childNode,
bool Aidge::GraphView::replaceWith(std::set<std::shared_ptr<Node>> newNodes) { bool Aidge::GraphView::replaceWith(std::set<std::shared_ptr<Node>> newNodes) {
// TODO : only supports one input/output node for now return GraphView::replace(mNodes, newNodes);
assert(mNodes.size()>0 && "There must be at least one Node to replace");
bool replacable;
std::shared_ptr<Node> previousInputNode = (*inputNodes().begin());
std::shared_ptr<Node> previousOutputNode = (*outputNodes().begin());
std::shared_ptr<Node> newOutputNode;
auto gNew = std::make_shared<GraphView>();
gNew->add(newNodes, false);
if (newNodes.empty()) {
replacable = (outputNodes().size() == 1) &&
(inputNodes().size() == 1) &&
((*outputNodes().begin())->nbOutputs() == 1) &&
((*inputNodes().begin())->nbDataInputs() == 1);
newOutputNode = previousInputNode->input(0).first;
} else {
newOutputNode = (*gNew->outputNodes().begin());
replacable = (outputNodes().size() == gNew->outputNodes().size()) &&
(outputNodes().size() == 1) &&
(previousOutputNode->nbOutputs() == newOutputNode->nbOutputs());
}
if (replacable) {
auto copyOutputs = previousOutputNode->outputs();
// manage Views for newNodes
// only keep common views to each node for the new set
std::set<std::shared_ptr<GraphView>> commonGraphViews = (*mNodes.begin())->views();
for (const auto& nodePtr : mNodes) {
const auto nodeView = nodePtr->views();
std::set<std::shared_ptr<GraphView>> intersection;
std::set_intersection(commonGraphViews.begin(), commonGraphViews.end(),
nodeView.begin(), nodeView.end(),
std::inserter(intersection, intersection.begin()));
commonGraphViews = intersection;
}
// clean Nodes to replace
std::set<std::shared_ptr<Node>> copyNode = mNodes;
for (auto& nodePtr : copyNode) { nodePtr->resetConnections(true); }
// copy output connections
if (newOutputNode) {
for (IOIndex_t o = 0; o < previousOutputNode->nbOutputs(); ++o) {
auto outputPairs = copyOutputs[o];
for (const auto& onePair : outputPairs) {
newOutputNode->addChild(onePair.first, o, onePair.second);
}
}
}
// insert new Nodes in the right GraphViews
for (auto& graphPtr : commonGraphViews) {
graphPtr->add(newNodes, false);
if (newNodes.empty()) {
graphPtr->updateInputNodes();
graphPtr->updateOutputNodes();
}
}
}
return replacable;
} }
bool Aidge::GraphView::replace(const std::set<Aidge::NodePtr>& oldNodes, const std::set<Aidge::NodePtr>& newNodes) { bool Aidge::GraphView::replace(const std::set<Aidge::NodePtr>& oldNodes, const std::set<Aidge::NodePtr>& newNodes) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment