any_of.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 AnyOf 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  /// The graph value is added to the matched values list. If the predicate is true for
29  /// the
30  /// graph node, a submatch is performed on the input of AnyOf and each input of the
31  /// graph node. The first match that succeeds results in a successful match. Otherwise
32  /// the match fails.
33  ///
34  /// AnyOf may be given a type and shape for use in strict mode.
35  class NGRAPH_API AnyOf : public Pattern
36  {
37  public:
38  static constexpr NodeTypeInfo type_info{"patternAnyOf", 0};
39  const NodeTypeInfo& get_type_info() const override;
40  /// \brief creates a AnyOf node containing a sub-pattern described by \sa type and
41  /// \sa shape.
42  AnyOf(const element::Type& type,
43  const PartialShape& s,
44  ValuePredicate pred,
45  const OutputVector& wrapped_values)
46  : Pattern(wrapped_values, pred)
47  {
48  if (wrapped_values.size() != 1)
49  {
50  throw ngraph_error("AnyOf expects exactly one argument");
51  }
52  set_output_type(0, type, s);
53  }
54  AnyOf(const element::Type& type,
55  const PartialShape& s,
56  NodePredicate pred,
57  const NodeVector& wrapped_values)
58  : AnyOf(type,
59  s,
60  [pred](const Output<Node>& value) {
61  return pred(value.get_node_shared_ptr());
62  },
63  as_output_vector(wrapped_values))
64  {
65  }
66 
67  /// \brief creates a AnyOf node containing a sub-pattern described by the type and
68  /// shape of \sa node.
69  AnyOf(const Output<Node>& node,
70  ValuePredicate pred,
71  const OutputVector& wrapped_values)
72  : AnyOf(node.get_element_type(), node.get_partial_shape(), pred, wrapped_values)
73  {
74  }
75  AnyOf(std::shared_ptr<Node> node,
76  NodePredicate pred,
77  const NodeVector& wrapped_values)
78  : AnyOf(node, as_value_predicate(pred), as_output_vector(wrapped_values))
79  {
80  }
81  bool match_value(Matcher* matcher,
82  const Output<Node>& pattern_value,
83  const Output<Node>& graph_value) override;
84  };
85  }
86  }
87 }
Definition: node.hpp:132
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Definition: node_output.hpp:36
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
Definition: element_type.hpp:61
Base error for ngraph runtime errors.
Definition: except.hpp:28
Definition: matcher.hpp:75
Definition: any_of.hpp:36
const NodeTypeInfo & get_type_info() const override
AnyOf(const Output< Node > &node, ValuePredicate pred, const OutputVector &wrapped_values)
creates a AnyOf node containing a sub-pattern described by the type and shape of
Definition: any_of.hpp:69
AnyOf(const element::Type &type, const PartialShape &s, ValuePredicate pred, const OutputVector &wrapped_values)
creates a AnyOf node containing a sub-pattern described by
Definition: any_of.hpp:42
Definition: pattern.hpp:82
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39