binary_elementwise_comparison.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/op/op.hpp"
8 #include "ngraph/op/util/attr_types.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace util
15  {
16  // clang-format off
17  /// \brief Abstract base class for elementwise binary comparison operations, i.e.,
18  /// operations where the same scalar binary comparison operation is applied to
19  /// each corresponding pair of elements in two input tensors. Implicit
20  /// broadcast of input tensors is supported through one of the AutoBroadcast
21  /// modes.
22  ///
23  /// For example, if the underlying comparison operation (determined by the subclass) is
24  /// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
25  /// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
26  /// \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$.
27  ///
28  /// ## Inputs
29  ///
30  /// | | Type | Description |
31  /// | ------ | --------------------------------- | ------------------------------------------------------ |
32  /// | `arg0` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape and element type. |
33  /// | `arg1` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
34  /// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
35  ///
36  /// ## Output
37  ///
38  /// | Type | Description |
39  /// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
40  /// | \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`. |
41  // clang-format on
42  class NGRAPH_API BinaryElementwiseComparison : public Op
43  {
44  protected:
45  /// \brief Constructs a binary elementwise comparison operation.
47 
48  /// \brief Constructs a binary elementwise comparison operation.
49  ///
50  /// \param arg0 Output that produces the first input tensor.
51  /// \param arg1 Output that produces the second input tensor.
52  /// \param autob AutoBroadcast mode.
54  const Output<Node>& arg1,
55  const AutoBroadcastSpec& autob = AutoBroadcastSpec());
56 
57  public:
58  void validate_and_infer_types() override;
59 
60  const AutoBroadcastSpec& get_autob() const override { return m_autob; }
61  void set_autob(const AutoBroadcastSpec& autob) { m_autob = autob; }
62  bool visit_attributes(AttributeVisitor& visitor) override;
63 
64  private:
65  AutoBroadcastSpec m_autob;
66  };
67  } // namespace util
68  } // namespace op
69 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Abstract base class for elementwise binary comparison operations, i.e., operations where the same sca...
Definition: binary_elementwise_comparison.hpp:43
BinaryElementwiseComparison(const AutoBroadcastSpec &autob)
Constructs a binary elementwise comparison operation.
const AutoBroadcastSpec & get_autob() const override
Definition: binary_elementwise_comparison.hpp:60
BinaryElementwiseComparison(const Output< Node > &arg0, const Output< Node > &arg1, const AutoBroadcastSpec &autob=AutoBroadcastSpec())
Constructs a binary elementwise comparison operation.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Implicit broadcast specification.
Definition: attr_types.hpp:311