Skip to content
Snippets Groups Projects
Commit f4eb185f authored by Cyril Moineau's avatar Cyril Moineau
Browse files

[RemoveFlatten] Update recipies to remove flatten only if it is before an FC !

parent 81bcd8b2
No related branches found
No related tags found
1 merge request!9Fuse bn
...@@ -22,16 +22,25 @@ ...@@ -22,16 +22,25 @@
namespace Aidge { namespace Aidge {
void removeFlatten(std::set<std::shared_ptr<Node>> nodes) { void removeFlatten(std::set<std::shared_ptr<Node>> nodes) {
assert(nodes.size() == 2 && "Wrong number of nodes to replace\n");
std::shared_ptr<Node> fc;
for (const auto& element : nodes) {
assert((element->type() == "FC" || element->type() == "Flatten") && "Wrong type for the nodes to replace");
if (element->type() == "FC"){
fc = element;
}
}
auto g = std::make_shared<GraphView>(); auto g = std::make_shared<GraphView>();
g->add(std::set<std::shared_ptr<Node>>({nodes})); g->add(std::set<std::shared_ptr<Node>>({nodes}));
g->replaceWith({}); g->replaceWith({fc});
} }
void removeFlatten(std::shared_ptr<GraphView> graphView){ void removeFlatten(std::shared_ptr<GraphView> graphView){
std::map<std::string,NodeRegex*> nodesRegex ; std::map<std::string,NodeRegex*> nodesRegex ;
nodesRegex["Flatten"] = new NodeRegex("Flatten"); nodesRegex["Flatten"] = new NodeRegex("Flatten");
nodesRegex["FC"] = new NodeRegex("FC");
std::vector<std::string> seqRegex; std::vector<std::string> seqRegex;
seqRegex.push_back("Flatten;"); seqRegex.push_back("Flatten->FC;");
GRegex GReg(nodesRegex, seqRegex); GRegex GReg(nodesRegex, seqRegex);
Match matches = GReg.match(graphView); Match matches = GReg.match(graphView);
std::vector<std::set<std::shared_ptr<Node>>> matchNodes = matches.getMatchNodes(); std::vector<std::set<std::shared_ptr<Node>>> matchNodes = matches.getMatchNodes();
......
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