binary_elementwise_arithmetic.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 arithmetic operations, i.e.,
30  /// operations where the same scalar binary arithmetic operation is applied to
31  /// each corresponding pair of elements in the 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 arithmetic operation (determined by the subclass) is
36  /// \f$\mathit{op}(x,y)\f$, the input tensors
37  /// \f$[[x_0,y_0],[z_0,w_0]]\f$ and \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$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape. The element type \f$N\f$ may be any numeric type. |
45  /// | `arg1` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same element type as `arg0`. |
46  /// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
47  ///
48  /// ## Output
49  ///
50  /// | Type | Description |
51  /// | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52  /// | \f$N[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 and element type as the input tensors (after auto broadcasting). |
53  // clang-format on
54  class NGRAPH_API BinaryElementwiseArithmetic : public Op
55  {
56  protected:
57  NGRAPH_RTTI_DECLARATION;
58 
60 
61  /// \brief Constructs a binary elementwise arithmetic operation.
62  ///
63  /// \param arg0 Output that produces the first input tensor.
64  /// \param arg1 Output that produces the second input tensor.
65  BinaryElementwiseArithmetic(const Output<Node>& arg0,
66  const Output<Node>& arg1,
67  const AutoBroadcastSpec& autob);
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  void validate_and_infer_elementwise_arithmetic(const op::AutoBroadcastSpec& autob);
79  };
80  }
81  }
82 }
ngraph::op::util::BinaryElementwiseArithmetic::get_autob
const AutoBroadcastSpec & get_autob() const override
Definition: binary_elementwise_arithmetic.hpp:72
ngraph::op::util::BinaryElementwiseArithmetic::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::AutoBroadcastSpec
Implicit broadcast specification.
Definition: attr_types.hpp:321
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic
BinaryElementwiseArithmetic(const Output< Node > &arg0, const Output< Node > &arg1, const AutoBroadcastSpec &autob)
Constructs a binary elementwise arithmetic operation.
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::util::BinaryElementwiseArithmetic
Abstract base class for elementwise binary arithmetic operations, i.e., operations where the same sca...
Definition: binary_elementwise_arithmetic.hpp:55
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29