matcher.hpp 2.09 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2020 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15
//
// 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.
//*****************************************************************************
16

17
// this is for more nuanced testing
18 19 20
class TestMatcher : public ngraph::pattern::Matcher
{
    using ngraph::pattern::Matcher::Matcher;
21 22

public:
23
    TestMatcher() {}
24 25
    bool virtual match_value(const ngraph::Output<ngraph::Node>& pattern_value,
                             const ngraph::Output<ngraph::Node>& graph_value) override
26
    {
27
        if (ngraph::is_type<::ngraph::op::Parameter>(pattern_value.get_node_shared_ptr()))
28
        {
29
            bool result = pattern_value == graph_value;
30 31
            if (result)
            {
32
                m_matched_list.push_back(graph_value.get_node_shared_ptr());
33 34 35 36
            }
            return result;
        }

37
        return this->ngraph::pattern::Matcher::match_value(pattern_value, graph_value);
38 39 40 41 42 43
    }

public:
    bool match(const std::shared_ptr<ngraph::Node>& pattern_node,
               const std::shared_ptr<ngraph::Node>& graph_node)
    {
44 45
        NGRAPH_CHECK(pattern_node && graph_node); // the same condition throws an exception in the
                                                  // non-test version of `match`
46 47 48
        NGRAPH_DEBUG << "Starting match pattern = " << pattern_node->get_name()
                     << " , graph_node = " << graph_node->get_name();

49 50
        m_pattern_node = pattern_node;
        return ngraph::pattern::Matcher::match(graph_node, ngraph::pattern::PatternValueMap{});
51 52
    }
};