Cumulative¶
Computes successive reductions across an axis of a tensor. The output always has the same shape as the input.
For multidimensional tensors, the reductions apply across a specified axis. For example, given a 2D input, a forward inclusive cumulative operation across axis 0 generates cumulative sums within each column.
If the reduction operation is summation, then this is also known as prefix-sum or cumulative sum.
The operation has forward vs. reverse variants, and inclusive vs. exclusive variants.
For example, let the input be a vector x of length n and the output be vector y. Then y[j] = sum(x[…]) where … denotes a sequence of indices from this table:
forward |
reverse |
|
---|---|---|
inclusive |
0..j |
j..n-1 |
exclusive |
0..j-1 |
j+1..n-1 |
Attributes¶
operation
Cumulative operation can be one of:
SUM
Prefix-sums the elements.
exclusive
The boolean that specifies whether the layer is an exclusive cumulative or inclusive cumulative layer. Default is false.
reverse
The boolean that specifies whether the cumulative operation should be applied backward. Default is false.
Inputs¶
input: tensor of type T1
axis: tensor of type T2
Outputs¶
output: tensor of type T1
Data Types¶
Operation |
T1 |
T2 |
---|---|---|
|
|
|
Shape Information¶
input and output are tensors with the same shape of \([a_0,...,a_n], n \geq 1\)
axis must be a build-time constant 0D tensor and must be in the range [-rank(input), rank(input)-1]. Negative value means counting dimensions from the back.
E.g. for input shape (D0, D1, D2), axis=2
, output_scale shape is (D0, D1, D2)
.
DLA Support¶
Not supported.
Examples¶
Cumulative
in1 = network.add_input("input1", dtype=trt.float32, shape=(2, 3))
axis_data = np.asarray([1], dtype=np.int32)
in2 = network.add_constant(shape=(), weights=axis_data).get_output(0)
layer = network.add_cumulative(input=in1, axis=in2, op=trt.CumulativeOperation.SUM, exclusive=False, reverse=False)
network.mark_output(layer.get_output(0))
inputs[in1.name] = np.array([[-3.0, -2.0, -1.0], [0.0, 1.0, 2.0]])
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array([[-3.0, -5.0, -6.0], [0.0, 1.0, 3.0]])
C++ API¶
For more information about the C++ ICumulativeLayer operator, refer to the C++ ICumulativeLayer documentation.
Python API¶
For more information about the Python ICumulativeLayer operator, refer to the Python ICumulativeLayer documentation.