<commit_before>//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "ngraph/pass/fused_op_decomposition.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/op/get_output_element.hpp"

using namespace std;
using namespace ngraph;

pass::FusedOpDecomposition::FusedOpDecomposition(op_query_t callback)
    : m_has_direct_support{callback}
{
}

bool pass::FusedOpDecomposition::run_on_node(shared_ptr<Node> node)
{
    bool modified = false;

    if (auto fused_op = dynamic_pointer_cast<op::util::FusedOp>(node))
    {
        if (m_has_direct_support && m_has_direct_support(*node))
        {
            // Op supported by backend. Do not decompose
            return modified;
        }

        auto subgraph_outputs = fused_op->decompose_op();
        // Run recursively untill no more fused ops
        auto subgraph = extract_subgraph(subgraph_outputs, fused_op->get_arguments());
        for (auto subgraph_node : subgraph)
        {
            if (auto nested_fused_op = dynamic_pointer_cast<op::util::FusedOp>(subgraph_node))
            {
                if (!(m_has_direct_support && m_has_direct_support(*nested_fused_op)))
                {
                    run_on_node(nested_fused_op);
                }
            }
        }

        size_t i = 0;
        for (auto output_node : subgraph_outputs)
        {
            for (size_t j = 0; j < output_node->get_outputs().size(); j++, i++)
            {
                // TODO: Provenance
                set<descriptor::Input*> fop_users{begin(fused_op->get_outputs().at(i).get_inputs()),
                                                  end(fused_op->get_outputs().at(i).get_inputs())};
                for (auto fop_user : fop_users)
                {
                    if (auto goe =
                            dynamic_cast<op::GetOutputElement*>(fop_user->get_raw_pointer_node()))
                    {
                        if (goe->get_n() == i && !goe->get_output_inputs(0).empty())
                        {
                            // Replace GOE users
                            set<descriptor::Input*> goe_users{<commit_msg>[Fused] Remove redundant conditions. (#3122)<commit_after>//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "ngraph/pass/fused_op_decomposition.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/op/get_output_element.hpp"

using namespace std;
using namespace ngraph;

pass::FusedOpDecomposition::FusedOpDecomposition(op_query_t callback)
    : m_has_direct_support{callback}
{
}

bool pass::FusedOpDecomposition::run_on_node(shared_ptr<Node> node)
{
    bool modified = false;

    if (auto fused_op = dynamic_pointer_cast<op::util::FusedOp>(node))
    {
        if (m_has_direct_support && m_has_direct_support(*node))
        {
            // Op supported by backend. Do not decompose
            return modified;
        }

        auto subgraph_outputs = fused_op->decompose_op();
        // Run recursively untill no more fused ops
        auto subgraph = extract_subgraph(subgraph_outputs, fused_op->get_arguments());
        for (auto subgraph_node : subgraph)
        {
            run_on_node(subgraph_node);
        }

        size_t i = 0;
        for (auto output_node : subgraph_outputs)
        {
            for (size_t j = 0; j < output_node->get_outputs().size(); j++, i++)
            {
                // TODO: Provenance
                set<descriptor::Input*> fop_users{begin(fused_op->get_outputs().at(i).get_inputs()),
                                                  end(fused_op->get_outputs().at(i).get_inputs())};
                for (auto fop_user : fop_users)
                {
                    if (auto goe =
                            dynamic_cast<op::GetOutputElement*>(fop_user->get_raw_pointer_node()))
                    {
                        if (goe->get_n() == i && !goe->get_output_inputs(0).empty())
                        {
                            // Replace GOE users
                            set<descriptor::Input*> goe_users{
{'fraction_non_alphanumeric': 0.1563476024251332, 'fraction_numerical': 0.0062465552085247105, 'mean_word_length': 2.3255956017104458, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031207', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1429, 'n_words': 362}