binary_elementwise_logical.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 
9 namespace ngraph
10 {
11  namespace op
12  {
13  namespace util
14  {
15  // clang-format off
16  /// \brief Abstract base class for elementwise binary logical operations, i.e.,
17  /// operations where the same scalar binary logical operation is applied to
18  /// each corresponding pair of elements in two boolean input tensors. Implicit
19  /// broadcast of input tensors is supported through one of the AutoBroadcast
20  /// modes.
21  ///
22  /// For example, if the underlying operation (determined by the subclass) is
23  /// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
24  /// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
25  /// \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$.
26  ///
27  /// ## Inputs
28  ///
29  /// | | Type | Description |
30  /// | ------ | --------------------------------------------- | ------------------------------------------------------ |
31  /// | `arg0` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape, with element type `bool`. |
32  /// | `arg1` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
33  /// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
34  ///
35  /// ## Output
36  ///
37  /// | Type | Description |
38  /// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
39  /// | \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`. |
40  // clang-format on
41  class NGRAPH_API BinaryElementwiseLogical : public Op
42  {
43  protected:
44  NGRAPH_RTTI_DECLARATION;
45 
47 
48  /// \brief Constructs a binary elementwise logical operation.
49  ///
50  /// \param arg0 Output that produces the first input tensor.
51  /// \param arg1 Output that produces the second input tensor.
53  const Output<Node>& arg1,
54  const AutoBroadcastSpec& autob = AutoBroadcastSpec());
55 
56  public:
57  void validate_and_infer_types() override;
58 
59  const AutoBroadcastSpec& get_autob() const override { return m_autob; }
60  void set_autob(const AutoBroadcastSpec& autob) { m_autob = autob; }
61  bool visit_attributes(AttributeVisitor& visitor) override;
62 
63  private:
64  void validate_and_infer_elementwise_logical(const op::AutoBroadcastSpec& autob);
65  AutoBroadcastSpec m_autob = AutoBroadcastSpec::NUMPY;
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 logical operations, i.e., operations where the same scalar...
Definition: binary_elementwise_logical.hpp:42
const AutoBroadcastSpec & get_autob() const override
Definition: binary_elementwise_logical.hpp:59
BinaryElementwiseLogical(const Output< Node > &arg0, const Output< Node > &arg1, const AutoBroadcastSpec &autob=AutoBroadcastSpec())
Constructs a binary elementwise logical 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