Skip to content
Snippets Groups Projects
RemoveFlatten.cpp 1.5 KiB
Newer Older
Cyril Moineau's avatar
Cyril Moineau committed
/********************************************************************************
 * Copyright (c) 2023 CEA-List
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 ********************************************************************************/

#include <memory>

#include "aidge/graph/Node.hpp"
#include "aidge/graph/GraphView.hpp"
Olivier BICHLER's avatar
Olivier BICHLER committed
#include "aidge/recipes/Recipes.hpp"
Cyril Moineau's avatar
Cyril Moineau committed

//Graph Regex
#include "aidge/graphRegex/GraphRegex.hpp"
Cyril Moineau's avatar
Cyril Moineau committed
namespace Aidge {
    void removeFlatten(std::shared_ptr<Node> flatten) {
        GraphView::replace({flatten}, {});
Cyril Moineau's avatar
Cyril Moineau committed
    }
    void removeFlatten(std::shared_ptr<MatchSolution> solution){

        assert(solution->at("FC").size() == 1 && "Wrong number of nodes FC to replace\n");
        assert(solution->at("Flatten").size() == 1 && "Wrong number of nodes Flatten to replace\n");

        for (const auto& flatten : solution->at("Flatten")) {
            removeFlatten(flatten);
        }
    }



    void removeFlatten(std::shared_ptr<GraphView> graphView){

        std::shared_ptr<GraphRegex> regex = std::make_shared<GraphRegex>();
        regex->setNodeKey("Flatten","getType($) =='Flatten'");
        regex->setNodeKey("FC","getType($) =='FC'");
        regex->addQuery("Flatten->FC");

        for (const auto& solution : regex->match(graphView)) {
            removeFlatten(solution);