diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 5d4df27a045142833074b892a688f1fbab47dea7..91cc0f889b8d01402b7c2e1369eb24acc63ff252 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -1256,6 +1256,7 @@ bool Aidge::GraphView::replace(const std::shared_ptr<GraphView>& oldGraph, const for (const auto& nodePtr : newNodes) { nodePtr->removeView(newGraph); } + Log::warn("Discrepancy between the number of input/output of the graph to replace.\n\t- OLD NB INPUTS: {} - NEW NB INPUTS {}\n\t- OLD NB OUTPUTS: {} - NEW NB OUTPUTS {}", oldOIn.size(), newOIn.size(), oldOOut.size(), newOOut.size()); return false; } @@ -1325,14 +1326,27 @@ bool Aidge::GraphView::replace(const std::shared_ptr<GraphView>& oldGraph, const newOOut[o].first -> addChild(child.first, newOOut[o].second, child.second); } } - } - else { + } else if ( // for folding case + ((newOIn.size() == 0)) && + ((oldOOut.size() == newOOut.size()) && (newOOut.size() == 1)) + ) { + // Case 4 + // Replace any nodes by a Producer + // No need to remove old inputs it is removed later on ... + for (std::size_t o = 0; o < oldOOut.size(); ++o) { + for (const auto& child : outputChildren[o]) { + newOOut[o].first -> addChild(child.first, newOOut[o].second, child.second); + } + } + + } else { for (const auto& nodePtr : oldNodes) { nodePtr->removeView(oldGraph); } for (const auto& nodePtr : newNodes) { nodePtr->removeView(newGraph); } + Log::warn("Could not replace"); return false; } }