unary_elementwise_arithmetic.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 unary arithmetic operations, i.e.,
17  /// operations where the same scalar arithmetic operation is applied to each
18  /// element.
19  ///
20  /// For example, if the underlying operation (determined by the subclass) is
21  /// \f$\mathit{op}(x)\f$, the input tensor \f$[[x,y],[z,w]]\f$ will be mapped to
22  /// \f$[[\mathit{op}(x),\mathit{op}(y)],[\mathit{op}(z),\mathit{op}(w)]]\f$.
23  ///
24  /// ## Inputs
25  ///
26  /// | | Type | Description |
27  /// | ----- | --------------------------------- | ------------------------------------------------------------------------ |
28  /// | `arg` | \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. |
29  ///
30  /// ## Output
31  ///
32  /// | Type | Description |
33  /// | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
34  /// | \f$N[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg}[i_1,\dots,i_n])\f$. This will always have the same shape and element type as the input tensor. |
35  // clang-format on
36  class NGRAPH_API UnaryElementwiseArithmetic : public Op
37  {
38  protected:
39  /// \brief Constructs a unary elementwise arithmetic operation.
41  /// \brief Constructs a unary elementwise arithmetic operation.
42  ///
43  /// \param arg Output that produces the input tensor.
45 
46  public:
47  NGRAPH_RTTI_DECLARATION;
48 
49  void validate_and_infer_types() override;
50  bool visit_attributes(AttributeVisitor& visitor) override;
51 
52  private:
53  void validate_and_infer_elementwise_arithmetic();
54  };
55  } // namespace util
56  } // namespace op
57 } // 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 unary arithmetic operations, i.e., operations where the same scal...
Definition: unary_elementwise_arithmetic.hpp:37
UnaryElementwiseArithmetic()
Constructs a unary elementwise arithmetic operation.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
UnaryElementwiseArithmetic(const Output< Node > &arg)
Constructs a unary elementwise arithmetic operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16