Skip to content
Snippets Groups Projects
Commit 515535eb authored by Cyril Moineau's avatar Cyril Moineau Committed by Maxence Naud
Browse files

Fix aidge_onnx#51, name uniqueness was not checked in the graph that was added.

parent 374b93b9
No related branches found
No related tags found
No related merge requests found
Pipeline #66593 passed
......@@ -30,6 +30,7 @@ void init_GraphView(py::module& m) {
:param path: save location
:type path: str
)mydelimiter")
.def("set_name", &GraphView::setName, py::arg("name"))
.def("inputs", (std::vector<std::pair<NodePtr, IOIndex_t>> (GraphView::*)() const) &GraphView::inputs)
.def("outputs", (std::vector<std::vector<std::pair<NodePtr, IOIndex_t>>> (GraphView::*)() const) &GraphView::outputs)
.def("in_view", (bool (GraphView::*)(const NodePtr&) const) &GraphView::inView)
......
......@@ -808,18 +808,19 @@ bool Aidge::GraphView::add(std::set<std::shared_ptr<Node>> otherNodes, bool incl
}
bool orderUnicity = true;
// List only the nodes that are not already present in current graph
std::set<NodePtr> nodesToAdd;
std::set_difference(otherNodes.begin(), otherNodes.end(), mNodes.begin(), mNodes.end(), std::inserter(nodesToAdd, nodesToAdd.begin()));
// Check no name is common with the name in the current Graph
for (auto node : nodesToAdd) {
if (mNodeRegistry.find(node->name()) != mNodeRegistry.end()){
std::string newName = node->createUniqueName(node->name());
fmt::print("Warning: node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
node->setName(newName);
if (mNodeRegistry.find(node->name()) != mNodeRegistry.end()) {
std::string newName = node->createUniqueName(node->name());
while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
newName = node->createUniqueName(newName + "_1");
}
Log::notice("node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
node->setName(newName);
}
}
// List the nodes to rank, initially all the nodes in the GraphView
......
......@@ -93,6 +93,7 @@ std::string Aidge::Node::createUniqueName(std::string baseName)
nameAlreadyUsed = false;
for (auto graphView : views()) {
if (graphView->inView(newName)) {
Log::info("Node::createUniqueName(): name '{}' already used in graph '{}'", newName, graphView->name());
nameAlreadyUsed = true;
break;
}
......
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