From 937ea24e8bda7215b5c2388e8663f25cffb49a7d Mon Sep 17 00:00:00 2001 From: yang131313 Date: Mon, 1 Aug 2022 21:18:24 +0800 Subject: [PATCH] =?UTF-8?q?API=20doc(en)=20Bugs=20fix=20in=20=E7=AC=AC?= =?UTF-8?q?=E5=9B=9B=E6=9C=9F=E4=BD=93=E9=AA=8C=E8=AF=84=E4=BC=B0=20(#4474?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix docs(en) bugs;test=document_fix * update paddle.add docs;test=document_fix * update paddle.where docs;test=document_fix * for ci;test=document_fix * Update manipulation.py * update paddle.where;test=document_fix Co-authored-by: Ligoml <39876205+Ligoml@users.noreply.github.com> --- python/paddle/tensor/manipulation.py | 2 +- python/paddle/tensor/math.py | 52 ++++++++++++++++++++++++---- python/paddle/tensor/search.py | 10 +++--- python/paddle/tensor/stat.py | 2 ++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 0439cc2767f..8d818aae57a 100755 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -3082,7 +3082,7 @@ def expand(x, shape, name=None): Expand the input tensor to a given shape. - Both the number of dimensions of ``x`` and the number of elements in ``shape`` should be less than or equal to 6. The dimension to expand must have a value 1. + Both the number of dimensions of ``x`` and the number of elements in ``shape`` should be less than or equal to 6. And the number of dimensions of ``x`` should be less than the number of elements in ``shape``. The dimension to expand must have a value 1. Args: diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index f70c9a0c410..05b9e0069da 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -493,17 +493,55 @@ def _elementwise_op(helper): def add(x, y, name=None): """ - Examples: + Elementwise Add Operator. + Add two tensors element-wise + The equation is: - .. code-block:: python + .. math:: - import paddle + Out=X+Y + + X : a tensor of any dimension. + Y: a tensor whose dimensions must be less than or equal to the dimensions of X. + + There are two cases for this operator: + 1. The shape of Y is the same with X. + 2. The shape of Y is a continuous subsequence of X. + For case 2: + 1. Broadcast Y to match the shape of X, where axis is the start dimension index for broadcasting Y onto X. + 2. If axis is -1 (default), axis=rank(X)−rank(Y). + 3. The trailing dimensions of size 1 for Y will be ignored for the consideration of subsequence, such as shape(Y) = (2, 1) => (2). + + For example: + + .. code-block:: python + + shape(X) = (2, 3, 4, 5), shape(Y) = (,) + shape(X) = (2, 3, 4, 5), shape(Y) = (5,) + shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 + shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 + shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 + shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 - x = paddle.to_tensor([2, 3, 4], 'float64') - y = paddle.to_tensor([1, 5, 2], 'float64') - z = paddle.add(x, y) - print(z) # [3., 8., 6. ] + Args: + x (Tensor) – (Variable), Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64. + y (Tensor) – (Variable), Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64. + with_quant_attr (BOOLEAN) – Whether the operator has attributes used by quantization. + name (string, optional) – Name of the output. Default is None. It’s used to print debug info for developers. Details: :ref:`api_guide_Name` + + Returns: + N-dimension tensor. A location into which the result is stored. It’s dimension equals with x + + Examples: + + .. code-block:: python + + import paddle + x = paddle.to_tensor([2, 3, 4], 'float64') + y = paddle.to_tensor([1, 5, 2], 'float64') + z = paddle.add(x, y) + print(z) # [3., 8., 6. ] """ if in_dygraph_mode(): diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index a962f49358e..e7b2b515cdc 100644 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -589,18 +589,18 @@ def where(condition, x=None, y=None, name=None): Tensor: A Tensor with the same shape as :attr:`condition` and same data type as :attr:`x` and :attr:`y`. Examples: + .. code-block:: python - :name:where-example import paddle - + x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) + out = paddle.where(x>1, x, y) - print(out) #out: [1.0, 1.0, 3.2, 1.2] - + out = paddle.where(x>1) print(out) #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, diff --git a/python/paddle/tensor/stat.py b/python/paddle/tensor/stat.py index 1bf2df89855..ed6cf6fd593 100644 --- a/python/paddle/tensor/stat.py +++ b/python/paddle/tensor/stat.py @@ -217,6 +217,8 @@ def numel(x, name=None): Args: x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64. + name (str, optional): Name for the operation (optional, default is None). + For more information, please refer to :ref:`api_guide_Name`. Returns: Tensor: The number of elements for the input Tensor. -- GitLab