reduce_sum.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/axis_set.hpp"
8 #include "ngraph/op/util/arithmetic_reductions_keep_dims.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v1
15  {
16  // clang-format off
17  /// \brief Tensor sum operation.
18  ///
19  /// Element-wise sums the input tensor, eliminating the specified reduction axes.
20  /// For example:
21  ///
22  /// \f[
23  /// \mathit{sum}\left(\{0\},
24  /// \left[ \begin{array}{ccc}
25  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
26  /// \left[ (1 + 3 + 5), (2 + 4 + 6) \right] =
27  /// \left[ 9, 12 \right]~~~\text{(dimension 0 (rows) is eliminated)}
28  /// \f]
29  ///
30  /// \f[
31  /// \mathit{sum}\left(\{1\},
32  /// \left[ \begin{array}{ccc}
33  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
34  /// \left[ (1 + 2), (3 + 4), (5 + 6) \right] =
35  /// \left[ 3, 7, 11 \right]~~~\text{(dimension 1 (columns) is eliminated)}
36  /// \f]
37  ///
38  /// \f[
39  /// \mathit{sum}\left(\{0,1\},
40  /// \left[ \begin{array}{ccc}
41  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
42  /// (1 + 2) + (3 + 4) + (5 + 6) =
43  /// 21~~~\text{(both dimensions (rows and columns) are eliminated)}
44  /// \f]
45  ///
46  /// ## Parameters
47  ///
48  /// | | Description |
49  /// | -------------------- | ---------------------------------------- |
50  /// | `reduction_axes` | The axes to eliminate through summation. |
51  /// | `keep_dims` | If set to 1 it holds axes that are used for reduction. |
52  ///
53  /// ## Inputs
54  ///
55  /// | | Type | Description |
56  /// | ----- | --------------------------------- | ------------------------------------------------------ |
57  /// | `arg` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | An input tensor of any shape and numeric element type. |
58  ///
59  /// ## Output
60  ///
61  /// | Type | Description |
62  /// | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
63  /// | \f$N[\textit{delete}(A,d_1,\dots,d_n)]\f$ | The tensor \f$T\f$, where \f$T\f$ is the input tensor with the `reduction_axes` \f$A\f$ eliminated by summation. |
64  // clang-format off
65  class NGRAPH_API ReduceSum : public util::ArithmeticReductionKeepDims
66  {
67  public:
68  NGRAPH_RTTI_DECLARATION;
69  /// \brief Constructs a summation operation.
70  ReduceSum() = default;
71  /// \brief Constructs a summation operation.
72  ///
73  /// \param arg The tensor to be summed.
74  /// \param reduction_axes The axis positions (0-based) to be eliminated.
75  /// \param keep_dims If set to 1 it holds axes that are used for reduction.
76  ReduceSum(const Output<Node>& arg,
77  const Output<Node>& reduction_axes,
78  bool keep_dims = false);
79 
80  size_t get_version() const override { return 1; }
81 
82  virtual std::shared_ptr<Node>
83  clone_with_new_inputs(const OutputVector& new_args) const override;
84 
85  /// \return The default value for Sum.
86  virtual std::shared_ptr<Node> get_default_value() const override;
87 
88  bool evaluate(const HostTensorVector& outputs,
89  const HostTensorVector& inputs) const override;
90  bool has_evaluate() const override;
91  };
92  }
93  }
94 }
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Definition: arithmetic_reductions_keep_dims.hpp:17
Tensor sum operation.
Definition: reduce_sum.hpp:66
size_t get_version() const override
Definition: reduce_sum.hpp:80
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
ReduceSum(const Output< Node > &arg, const Output< Node > &reduction_axes, bool keep_dims=false)
Constructs a summation operation.
ReduceSum()=default
Constructs a summation operation.
virtual std::shared_ptr< Node > get_default_value() const override
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16