partial_sum

paddle.fluid.contrib.layers.nn. partial_sum ( input, start_index=0, length=- 1 ) [source]

PartialSum This Op can sum the vars by specifying the initial position(start_index) and length(length). This Op exists in contrib, which means that it is not shown to the public. Only 2-D Tensor or LodTensor input is supported. Slice and concat can only be performed along the second dimension. .. code-block:: text

Given:
x = [[0, 1, 2],

[3, 4, 5]]

y = [[6, 7 ,8],

[9, 10, 11]]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.partial_sum, line 13)

Definition list ends without a blank line; unexpected unindent.

output = partial_sum([x, y], start_index=0, length=2)

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.partial_sum, line 14)

Block quote ends without a blank line; unexpected unindent.

we get:

output = [[6, 8],

[12, 14]]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.partial_sum, line 18)

Block quote ends without a blank line; unexpected unindent.

Parameters

input (list) – List of input Tensors with data type float32, float64, int32, int64.

Returns

A Tensor with the same data type as input’s.

Return type

Variable

Examples


System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.partial_sum, line 28)

Explicit markup ends without a blank line; unexpected unindent.

import paddle.fluid.layers as layers import paddle.fluid as fluid import numpy as np x = fluid.data(name=”x”, shape=[None, 3], dtype=”float32”) y = fluid.data(name=”y”, shape=[None, 3], dtype=”float32”) sum = layers.partial_sum([x,y], start_index=0, length=2) place = fluid.CPUPlace() exe = fluid.Executor(place) xx = np.array([1,2,3,4,5,6]).reshape((2,3)).astype(“float32”) yy = np.array([6,5,4,4,5,6]).reshape((2,3)).astype(“float32”) out = exe.run(feed={“x”:xx, “y”:yy}, fetch_list=[sum])