binary_elementwise_comparison.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/op/op.hpp"
20 #include "ngraph/op/util/attr_types.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace util
27  {
28  // clang-format off
29  /// \brief Abstract base class for elementwise binary comparison operations, i.e.,
30  /// operations where the same scalar binary comparison operation is applied to
31  /// each corresponding pair of elements in two input tensors. Implicit
32  /// broadcast of input tensors is supported through one of the AutoBroadcast
33  /// modes.
34  ///
35  /// For example, if the underlying comparison operation (determined by the subclass) is
36  /// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
37  /// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
38  /// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
39  ///
40  /// ## Inputs
41  ///
42  /// | | Type | Description |
43  /// | ------ | --------------------------------- | ------------------------------------------------------ |
44  /// | `arg0` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape and element type. |
45  /// | `arg1` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
46  /// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
47  ///
48  /// ## Output
49  ///
50  /// | Type | Description |
51  /// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
52  /// | \f$\texttt{bool}[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape as the input tensors, and the element type `bool`. |
53  // clang-format on
54  class NGRAPH_API BinaryElementwiseComparison : public Op
55  {
56  protected:
57  /// \brief Constructs a binary elementwise comparison operation.
59 
60  /// \brief Constructs a binary elementwise comparison operation.
61  ///
62  /// \param arg0 Output that produces the first input tensor.
63  /// \param arg1 Output that produces the second input tensor.
64  /// \param autob AutoBroadcast mode.
65  BinaryElementwiseComparison(const Output<Node>& arg0,
66  const Output<Node>& arg1,
67  const AutoBroadcastSpec& autob = AutoBroadcastSpec());
68 
69  public:
70  void validate_and_infer_types() override;
71 
72  const AutoBroadcastSpec& get_autob() const override { return m_autob; }
73  void set_autob(const AutoBroadcastSpec& autob) { m_autob = autob; }
74  bool visit_attributes(AttributeVisitor& visitor) override;
75 
76  private:
77  AutoBroadcastSpec m_autob;
78  };
79  }
80  }
81 }
ngraph::op::util::BinaryElementwiseComparison::BinaryElementwiseComparison
BinaryElementwiseComparison(const AutoBroadcastSpec &autob)
Constructs a binary elementwise comparison operation.
ngraph::op::util::BinaryElementwiseComparison
Abstract base class for elementwise binary comparison operations, i.e., operations where the same sca...
Definition: binary_elementwise_comparison.hpp:55
ngraph::op::AutoBroadcastSpec
Implicit broadcast specification.
Definition: attr_types.hpp:321
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::util::BinaryElementwiseComparison::get_autob
const AutoBroadcastSpec & get_autob() const override
Definition: binary_elementwise_comparison.hpp:72
ngraph::op::util::BinaryElementwiseComparison::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::op::util::BinaryElementwiseComparison::BinaryElementwiseComparison
BinaryElementwiseComparison(const Output< Node > &arg0, const Output< Node > &arg1, const AutoBroadcastSpec &autob=AutoBroadcastSpec())
Constructs a binary elementwise comparison operation.
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29