cum_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/op.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v0
27  {
28  /// \brief Tensor cumulative sum operation.
29  ///
30  /// Compute the cumulative sum of the input tensor along the axis specified.
31  ///
32  /// ## Parameters
33  ///
34  /// | | Description |
35  /// | -------------------- |
36  /// --------------------------------------------------------------------------------------------------|
37  /// | `exclusive` | If set to 1 will return exclusive sum in which the top
38  /// element
39  /// is not included. |
40  /// | | In other terms, if set to 1, the j-th output element
41  /// would be
42  /// the
43  /// sum of the first (j-1) elements.|
44  /// | | Otherwise, it would be the sum of the first j elements.
45  /// |
46  ///
47  /// | | Description |
48  /// | -------------------- | -------------------------------------------------- |
49  /// | `reverse` | if set to 1, performs the sum in reverse direction |
50  ///
51  /// ## Inputs
52  ///
53  /// | | Description |
54  /// | ----- | ------------------------------------------------------ |
55  /// | `arg` | An input tensor of any shape and numeric element type. |
56  ///
57  /// | | Description |
58  /// | ----- |
59  /// ------------------------------------------------------------------------------------------------|
60  /// | `axis`| zero dimension tensor specifying axis position along which cumulative sum
61  /// must
62  /// be performed. |
63  ///
64  /// ## Output
65  ///
66  /// | Description |
67  /// |
68  /// ------------------------------------------------------------------------------------|
69  /// | Output tensor of the same type as `arg` with cumulative sums of the arg's elements
70  /// |
71 
72  class NGRAPH_API CumSum : public Op
73  {
74  public:
75  static constexpr NodeTypeInfo type_info{"CumSum", 0};
76  const NodeTypeInfo& get_type_info() const override { return type_info; }
77  /// \brief Constructs a cumulative summation operation.
78  CumSum() = default;
79 
80  /// \brief Constructs a cumulative summation operation.
81  ///
82  /// \param arg The tensor to be summed.
83  /// \param axis zero dimension tensor specifying axis position along which
84  /// cumulative sum must be performed
85  /// \param exclusive if set to true, the top element is not included
86  /// \param reverse if set to true, will perform the sums in reverse direction
87  CumSum(const Output<Node>& arg,
88  const Output<Node>& axis,
89  const bool exclusive = false,
90  const bool reverse = false);
91 
92  /// \brief Constructs a cumulative summation operation with axis = 0
93  ///
94  /// \param arg The tensor to be summed
95  CumSum(const Output<Node>& arg,
96  const bool exclusive = false,
97  const bool reverse = false);
98 
99  virtual std::shared_ptr<Node>
100  clone_with_new_inputs(const OutputVector& new_args) const override;
101 
102  bool visit_attributes(AttributeVisitor& visitor) override;
103  void validate_and_infer_types() override;
104 
105  /// \return The default value for CumSum.
106  virtual std::shared_ptr<Node> get_default_value() const override;
107  bool is_exclusive() const { return m_exclusive; }
108  bool is_reverse() const { return m_reverse; }
109  private:
110  bool m_exclusive;
111  bool m_reverse;
112  };
113  }
114  using v0::CumSum;
115  }
116 }
ngraph::op::v0::CumSum
Tensor cumulative sum operation.
Definition: cum_sum.hpp:73
ngraph::op::v0::CumSum::CumSum
CumSum(const Output< Node > &arg, const bool exclusive=false, const bool reverse=false)
Constructs a cumulative summation operation with axis = 0.
ngraph::op::v0::CumSum::CumSum
CumSum(const Output< Node > &arg, const Output< Node > &axis, const bool exclusive=false, const bool reverse=false)
Constructs a cumulative summation operation.
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v0::CumSum::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: cum_sum.hpp:76
ngraph::op::v0::CumSum::get_default_value
virtual std::shared_ptr< Node > get_default_value() const override
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v0::CumSum::CumSum
CumSum()=default
Constructs a cumulative summation operation.
ngraph::op::v0::CumSum::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::Op
Root of all actual ops.
Definition: op.hpp:29