capture.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/node.hpp"
20 #include "ngraph/pattern/op/pattern.hpp"
21 
22 namespace ngraph
23 {
24  namespace pattern
25  {
26  namespace op
27  {
28  /// Experimental for support of recurrent matches.
29  ///
30  /// Capture adds the pattern value map to a list of pattern value maps and resets
31  /// matches for pattern nodes not in the static node list. The match always succeeds.
32  class NGRAPH_API Capture : public Pattern
33  {
34  public:
35  static constexpr NodeTypeInfo type_info{"patternCapture", 0};
36  const NodeTypeInfo& get_type_info() const override;
37  Capture(const Output<Node>& arg)
38  : Pattern({arg})
39  {
40  set_output_type(0, arg.get_element_type(), arg.get_partial_shape());
41  }
42 
43  /// \brief static nodes are retained after a capture. All other nodes are dropped
44  std::set<Node*> get_static_nodes() { return m_static_nodes; }
45  void set_static_nodes(const std::set<Node*>& static_nodes)
46  {
47  m_static_nodes = static_nodes;
48  }
49 
50  virtual bool match_value(pattern::Matcher* matcher,
51  const Output<Node>& pattern_value,
52  const Output<Node>& graph_value) override;
53 
54  protected:
55  std::set<Node*> m_static_nodes;
56  };
57  }
58  }
59 }
ngraph::pattern::Matcher
Definition: matcher.hpp:75
ngraph::pattern::op::Pattern
Definition: pattern.hpp:79
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::pattern::op::Capture::get_type_info
const NodeTypeInfo & get_type_info() const override
ngraph::pattern::op::Capture
Definition: capture.hpp:33
ngraph::pattern::op::Capture::get_static_nodes
std::set< Node * > get_static_nodes()
static nodes are retained after a capture. All other nodes are dropped
Definition: capture.hpp:44