1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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 //*****************************************************************************
19 #include "ngraph/axis_set.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/arithmetic_reduction.hpp"
30 /// \brief Tensor sum operation.
32 /// Element-wise sums the input tensor, eliminating the specified reduction axes.
36 /// \mathit{sum}\left(\{0\},
37 /// \left[ \begin{array}{ccc}
38 /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
39 /// \left[ (1 + 3 + 5), (2 + 4 + 6) \right] =
40 /// \left[ 9, 12 \right]~~~\text{(dimension 0 (rows) is eliminated)}
44 /// \mathit{sum}\left(\{1\},
45 /// \left[ \begin{array}{ccc}
46 /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
47 /// \left[ (1 + 2), (3 + 4), (5 + 6) \right] =
48 /// \left[ 3, 7, 11 \right]~~~\text{(dimension 1 (columns) is eliminated)}
52 /// \mathit{sum}\left(\{0,1\},
53 /// \left[ \begin{array}{ccc}
54 /// 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{array} \right]\right) =
55 /// (1 + 2) + (3 + 4) + (5 + 6) =
56 /// 21~~~\text{(both dimensions (rows and columns) are eliminated)}
62 /// | -------------------- | ---------------------------------------- |
63 /// | `reduction_axes` | The axes to eliminate through summation. |
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. |
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. |
77 class NGRAPH_DEPRECATED("This operation is deprecated and will be removed soon. "
78 "Use v1::ReduceSum instead of it.") NGRAPH_API Sum : public util::ArithmeticReduction
80 NGRAPH_SUPPRESS_DEPRECATED_START
82 static constexpr NodeTypeInfo type_info{ "Sum", 0 };
83 const NodeTypeInfo& get_type_info() const override { return type_info; }
84 /// \brief Constructs a summation operation.
86 /// \brief Constructs a summation operation.
88 /// \param arg The tensor to be summed.
89 /// \param reduction_axes The axis positions (0-based) to be eliminated.
90 Sum(const Output<Node>& arg, const AxisSet& reduction_axes);
91 /// \brief Constructs a summation operation.
93 /// \param arg The tensor to be summed.
94 /// \param reduction_axes The axis positions (0-based) to be eliminated.
95 Sum(const Output<Node>& arg, const Output<Node>& reduction_axes);
97 virtual std::shared_ptr<Node>
98 clone_with_new_inputs(const OutputVector& new_args) const override;
100 /// \return The default value for Sum.
101 virtual std::shared_ptr<Node> get_default_value() const override;
103 bool evaluate(const HostTensorVector& outputs,
104 const HostTensorVector& inputs) const override;
105 NGRAPH_SUPPRESS_DEPRECATED_END
108 // default opset version
109 NGRAPH_SUPPRESS_DEPRECATED_START
111 NGRAPH_SUPPRESS_DEPRECATED_END