From b53970ee36a365df859e461300d6c3cb3e1b4125 Mon Sep 17 00:00:00 2001 From: LutaoChu <30695251+LutaoChu@users.noreply.github.com> Date: Sat, 10 Oct 2020 10:16:09 +0800 Subject: [PATCH] Fix cross, cumsum op docs test=document_fix Fix cross, cumsum op docs --- python/paddle/tensor/linalg.py | 18 +++++++----------- python/paddle/tensor/math.py | 20 +++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 2dcdf1603a7..2745464995f 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -687,27 +687,24 @@ def t(input, name=None): def cross(x, y, axis=None, name=None): """ - :alias_main: paddle.cross - :alias: paddle.cross,paddle.tensor.cross,paddle.tensor.linalg.cross - Computes the cross product between two tensors along an axis. + Inputs must have the same shape, and the length of their axes should be equal to 3. If `axis` is not given, it defaults to the first axis found with the length 3. Args: - x (Variable): The first input tensor variable. - y (Variable): The second input tensor variable. + x (Tensor): The first input tensor. + y (Tensor): The second input tensor. axis (int, optional): The axis along which to compute the cross product. It defaults to the first axis found with the length 3. - name (str, optional): The default value is None. Normally there is no need for - user to set this property. For more information, please refer to :ref:`api_guide_Name` + name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Variable: A Tensor with same data type as `x`. + Tensor. A Tensor with same data type as `x`. Examples: .. code-block:: python + import paddle - paddle.disable_static() x = paddle.to_tensor([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], @@ -715,14 +712,13 @@ def cross(x, y, axis=None, name=None): y = paddle.to_tensor([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]) + z1 = paddle.cross(x, y) - print(z1.numpy()) # [[-1. -1. -1.] # [ 2. 2. 2.] # [-1. -1. -1.]] z2 = paddle.cross(x, y, axis=1) - print(z2.numpy()) # [[0. 0. 0.] # [0. 0. 0.] # [0. 0. 0.]] diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 34d15ed0bab..2a370422eed 100755 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -1622,39 +1622,37 @@ ${comment} def cumsum(x, axis=None, dtype=None, name=None): """ - The cumulative sum of the elements along a given axis. The first element of the result is the same of the first element of the input. + The cumulative sum of the elements along a given axis. + + **Note**: + The first element of the result is the same of the first element of the input. Args: - x (Tensor): Input of cumsum operator, the Tensor needed to be cumsumed. + x (Tensor): The input tensor needed to be cumsumed. axis (int, optional): The dimension to accumulate along. -1 means the last dimension. The default (None) is to compute the cumsum over the flattened array. dtype (str, optional): The data type of the output tensor, can be float32, float64, int32, int64. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. The default value is None. name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Tensor, the result of cumsum operator, output of cumsum operator. + Tensor, the result of cumsum operator. Examples: .. code-block:: python import paddle - import numpy as np - - paddle.disable_static() - data_np = np.arange(12).reshape(3, 4) - data = paddle.to_tensor(data_np) + + data = paddle.arange(12) + data = paddle.reshape(data, (3, 4)) y = paddle.cumsum(data) - print(y.numpy()) # [ 0 1 3 6 10 15 21 28 36 45 55 66] y = paddle.cumsum(data, axis=0) - print(y.numpy()) # [[ 0 1 2 3] # [ 4 6 8 10] # [12 15 18 21]] y = paddle.cumsum(data, axis=-1) - print(y.numpy()) # [[ 0 1 3 6] # [ 4 9 15 22] # [ 8 17 27 38]] -- GitLab