reduce_sum.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/axis_set.hpp"
20 #include "ngraph/op/util/arithmetic_reductions_keep_dims.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v1
27  {
28  // clang-format off
29  /// \brief Tensor sum operation.
30  ///
31  /// Element-wise sums the input tensor, eliminating the specified reduction axes.
32  /// For example:
33  ///
34  /// \f[
35  /// \mathit{sum}\left(\{0\},
36  /// \left[ \begin{array}{ccc}
37  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
38  /// \left[ (1 + 3 + 5), (2 + 4 + 6) \right] =
39  /// \left[ 9, 12 \right]~~~\text{(dimension 0 (rows) is eliminated)}
40  /// \f]
41  ///
42  /// \f[
43  /// \mathit{sum}\left(\{1\},
44  /// \left[ \begin{array}{ccc}
45  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
46  /// \left[ (1 + 2), (3 + 4), (5 + 6) \right] =
47  /// \left[ 3, 7, 11 \right]~~~\text{(dimension 1 (columns) is eliminated)}
48  /// \f]
49  ///
50  /// \f[
51  /// \mathit{sum}\left(\{0,1\},
52  /// \left[ \begin{array}{ccc}
53  /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
54  /// (1 + 2) + (3 + 4) + (5 + 6) =
55  /// 21~~~\text{(both dimensions (rows and columns) are eliminated)}
56  /// \f]
57  ///
58  /// ## Parameters
59  ///
60  /// | | Description |
61  /// | -------------------- | ---------------------------------------- |
62  /// | `reduction_axes` | The axes to eliminate through summation. |
63  /// | `keep_dims` | If set to 1 it holds axes that are used for reduction. |
64  ///
65  /// ## Inputs
66  ///
67  /// | | Type | Description |
68  /// | ----- | --------------------------------- | ------------------------------------------------------ |
69  /// | `arg` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | An input tensor of any shape and numeric element type. |
70  ///
71  /// ## Output
72  ///
73  /// | Type | Description |
74  /// | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
75  /// | \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. |
76  // clang-format off
77  class NGRAPH_API ReduceSum : public util::ArithmeticReductionKeepDims
78  {
79  public:
80  static constexpr NodeTypeInfo type_info{"ReduceSum", 1};
81  const NodeTypeInfo& get_type_info() const override { return type_info; }
82  /// \brief Constructs a summation operation.
83  ReduceSum() = default;
84  /// \brief Constructs a summation operation.
85  ///
86  /// \param arg The tensor to be summed.
87  /// \param reduction_axes The axis positions (0-based) to be eliminated.
88  /// \param keep_dims If set to 1 it holds axes that are used for reduction.
89  ReduceSum(const Output<Node>& arg,
90  const Output<Node>& reduction_axes,
91  bool keep_dims = false);
92 
93  size_t get_version() const override { return 1; }
94 
95  virtual std::shared_ptr<Node>
96  clone_with_new_inputs(const OutputVector& new_args) const override;
97 
98  /// \return The default value for Sum.
99  virtual std::shared_ptr<Node> get_default_value() const override;
100 
101  bool evaluate(const HostTensorVector& outputs,
102  const HostTensorVector& inputs) const override;
103  };
104  }
105  }
106 }
ngraph::op::util::ArithmeticReductionKeepDims
Definition: arithmetic_reductions_keep_dims.hpp:29
ngraph::op::v1::ReduceSum::ReduceSum
ReduceSum()=default
Constructs a summation operation.
ngraph::op::v1::ReduceSum::get_default_value
virtual std::shared_ptr< Node > get_default_value() const override
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v1::ReduceSum::get_version
size_t get_version() const override
Definition: reduce_sum.hpp:93
ngraph::op::v1::ReduceSum
Tensor sum operation.
Definition: reduce_sum.hpp:78
ngraph::op::v1::ReduceSum::ReduceSum
ReduceSum(const Output< Node > &arg, const Output< Node > &reduction_axes, bool keep_dims=false)
Constructs a summation operation.
ngraph::op::v1::ReduceSum::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: reduce_sum.hpp:81