From 6e55bc34df4f60ef0f2943efe34f9c3aa3dc8e86 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Fri, 3 Dec 2021 17:54:04 +0800 Subject: [PATCH 1/4] add paddle.gcd & lcm docs --- docs/api/paddle/Overview_cn.rst | 2 ++ docs/api/paddle/Tensor_cn.rst | 18 ++++++++++ docs/api/paddle/gcd_cn.rst | 58 +++++++++++++++++++++++++++++++++ docs/api/paddle/lcm_cn.rst | 58 +++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 docs/api/paddle/gcd_cn.rst create mode 100644 docs/api/paddle/lcm_cn.rst diff --git a/docs/api/paddle/Overview_cn.rst b/docs/api/paddle/Overview_cn.rst index 30472846ce8..73339415fd0 100755 --- a/docs/api/paddle/Overview_cn.rst +++ b/docs/api/paddle/Overview_cn.rst @@ -115,6 +115,8 @@ tensor数学操作 " :ref:`paddle.log1p ` ", "该OP计算Log1p(加一的自然对数)结果" " :ref:`paddle.rad2deg ` ", "将元素从弧度的角度转换为度" " :ref:`paddle.deg2rad ` ", "将元素从度的角度转换为弧度" + " :ref:`paddle.gcd ` ", "计算两个输入的按元素绝对值的最大公约数" + " :ref:`paddle.lcm ` ", "计算两个输入的按元素绝对值的最小公倍数" .. _tensor_logic: diff --git a/docs/api/paddle/Tensor_cn.rst b/docs/api/paddle/Tensor_cn.rst index ef5717b3eb5..909ffb3da67 100755 --- a/docs/api/paddle/Tensor_cn.rst +++ b/docs/api/paddle/Tensor_cn.rst @@ -1014,6 +1014,15 @@ gather_nd(index, name=None) 请参考 :ref:`cn_api_tensor_cn_gather_nd` +gcd(x1, x2, name=None) +::::::::: + +计算两个输入的按元素绝对值的最大公约数 + +返回:计算后的Tensor + +请参考 :ref:`cn_api_paddle_tensor_gcd` + gradient() ::::::::: @@ -1150,6 +1159,15 @@ kron(y, name=None) 请参考 :ref:`cn_api_paddle_tensor_kron` +lcm(x1, x2, name=None) +::::::::: + +计算两个输入的按元素绝对值的最小公倍数 + +返回:计算后的Tensor + +请参考 :ref:`cn_api_paddle_tensor_lcm` + less_equal(y, name=None) ::::::::: diff --git a/docs/api/paddle/gcd_cn.rst b/docs/api/paddle/gcd_cn.rst new file mode 100644 index 00000000000..a470d5af112 --- /dev/null +++ b/docs/api/paddle/gcd_cn.rst @@ -0,0 +1,58 @@ +.. _cn_api_paddle_tensor_gcd: + +gcd +------------------------------- + +.. py:function:: paddle.gcd(x1, x2, name=None) + +计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 + +.. note:: + + gcd(0,0)=0, gcd(0, x2)=|x2| + +参数 +::::::::: + +- **x1, x2** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 + 如果x1和x2的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), + 请参见 :ref:`cn_user_guide_broadcasting` 。 +- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +::::::::: + +输出Tensor,与输入数据类型相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + x1 = paddle.to_tensor(12) + x2 = paddle.to_tensor(20) + paddle.gcd(x1, x2) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [4]) + + x3 = paddle.to_tensor(np.arange(6)) + paddle.gcd(x3, x2) + # Tensor(shape=[6], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [20, 1 , 2 , 1 , 4 , 5]) + + x4 = paddle.to_tensor(0) + paddle.gcd(x4, x2) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [20]) + + paddle.gcd(x4, x4) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [0]) + + x5 = paddle.to_tensor(-20) + paddle.gcd(x1, x5) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [4]) diff --git a/docs/api/paddle/lcm_cn.rst b/docs/api/paddle/lcm_cn.rst new file mode 100644 index 00000000000..c226dc92a40 --- /dev/null +++ b/docs/api/paddle/lcm_cn.rst @@ -0,0 +1,58 @@ +.. _cn_api_paddle_tensor_lcm: + +lcm +------------------------------- + +.. py:function:: paddle.lcm(x1, x2, name=None) + +计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 + +.. note:: + + lcm(0,0)=0, lcm(0, x2)=0 + +参数 +::::::::: + +- **x1, x2** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 + 如果x1和x2的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), + 请参见 :ref:`cn_user_guide_broadcasting` 。 +- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +::::::::: + +输出Tensor,与输入数据类型相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + x1 = paddle.to_tensor(12) + x2 = paddle.to_tensor(20) + paddle.lcm(x1, x2) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [60]) + + x3 = paddle.to_tensor(np.arange(6)) + paddle.lcm(x3, x2) + # Tensor(shape=[6], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [0, 20, 20, 60, 20, 20]) + + x4 = paddle.to_tensor(0) + paddle.lcm(x4, x2) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [0]) + + paddle.lcm(x4, x4) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [0]) + + x5 = paddle.to_tensor(-20) + paddle.lcm(x1, x5) + # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, + # [60]) From 4694022e48c73b88d503caf619a4003ed29e12dd Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Mon, 6 Dec 2021 12:01:14 +0800 Subject: [PATCH 2/4] adjust api params name --- docs/api/paddle/Tensor_cn.rst | 4 ++-- docs/api/paddle/gcd_cn.rst | 8 ++++---- docs/api/paddle/lcm_cn.rst | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/api/paddle/Tensor_cn.rst b/docs/api/paddle/Tensor_cn.rst index 909ffb3da67..94391343b5a 100755 --- a/docs/api/paddle/Tensor_cn.rst +++ b/docs/api/paddle/Tensor_cn.rst @@ -1014,7 +1014,7 @@ gather_nd(index, name=None) 请参考 :ref:`cn_api_tensor_cn_gather_nd` -gcd(x1, x2, name=None) +gcd(x, y, name=None) ::::::::: 计算两个输入的按元素绝对值的最大公约数 @@ -1159,7 +1159,7 @@ kron(y, name=None) 请参考 :ref:`cn_api_paddle_tensor_kron` -lcm(x1, x2, name=None) +lcm(x, y, name=None) ::::::::: 计算两个输入的按元素绝对值的最小公倍数 diff --git a/docs/api/paddle/gcd_cn.rst b/docs/api/paddle/gcd_cn.rst index a470d5af112..bfd9a10f3b0 100644 --- a/docs/api/paddle/gcd_cn.rst +++ b/docs/api/paddle/gcd_cn.rst @@ -3,19 +3,19 @@ gcd ------------------------------- -.. py:function:: paddle.gcd(x1, x2, name=None) +.. py:function:: paddle.gcd(x, y, name=None) 计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 .. note:: - gcd(0,0)=0, gcd(0, x2)=|x2| + gcd(0,0)=0, gcd(0, y)=|y| 参数 ::::::::: -- **x1, x2** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - 如果x1和x2的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), +- **x, y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 + 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), 请参见 :ref:`cn_user_guide_broadcasting` 。 - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 diff --git a/docs/api/paddle/lcm_cn.rst b/docs/api/paddle/lcm_cn.rst index c226dc92a40..cb1abc012d7 100644 --- a/docs/api/paddle/lcm_cn.rst +++ b/docs/api/paddle/lcm_cn.rst @@ -3,19 +3,19 @@ lcm ------------------------------- -.. py:function:: paddle.lcm(x1, x2, name=None) +.. py:function:: paddle.lcm(x, y, name=None) 计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 .. note:: - lcm(0,0)=0, lcm(0, x2)=0 + lcm(0,0)=0, lcm(0, y)=0 参数 ::::::::: -- **x1, x2** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - 如果x1和x2的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), +- **x, y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 + 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), 请参见 :ref:`cn_user_guide_broadcasting` 。 - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 From 1654ae6516f05e1b0be7c0798d04d415a784cd12 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Fri, 10 Dec 2021 11:08:03 +0800 Subject: [PATCH 3/4] use copy-from --- docs/api/paddle/deg2rad_cn.rst | 18 +----------------- docs/api/paddle/rad2deg_cn.rst | 24 +----------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/docs/api/paddle/deg2rad_cn.rst b/docs/api/paddle/deg2rad_cn.rst index 026fd311ad3..e971832ce25 100644 --- a/docs/api/paddle/deg2rad_cn.rst +++ b/docs/api/paddle/deg2rad_cn.rst @@ -25,20 +25,4 @@ deg2rad 代码示例 ::::::::: -.. code-block:: python - - import paddle - import numpy as np - - x1 = paddle.to_tensor([180.0, -180.0, 360.0, -360.0, 90.0, -90.0]) - result1 = paddle.deg2rad(x1) - print(result1) - # Tensor(shape=[6], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [3.14159274, -3.14159274, 6.28318548, -6.28318548, 1.57079637, - # -1.57079637]) - - x2 = paddle.to_tensor(180) - result2 = paddle.deg2rad(x2) - print(result2) - # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [3.14159274]) +COPY-FROM: paddle.deg2rad diff --git a/docs/api/paddle/rad2deg_cn.rst b/docs/api/paddle/rad2deg_cn.rst index 3baa5f80a3d..f286cbd4bfc 100644 --- a/docs/api/paddle/rad2deg_cn.rst +++ b/docs/api/paddle/rad2deg_cn.rst @@ -25,26 +25,4 @@ rad2deg 代码示例 ::::::::: -.. code-block:: python - - import paddle - import numpy as np - - x1 = paddle.to_tensor([3.142, -3.142, 6.283, -6.283, 1.570, -1.570]) - result1 = paddle.rad2deg(x1) - print(result1) - # Tensor(shape=[6], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [180.02334595, -180.02334595, 359.98937988, -359.98937988, - # 9.95437622 , -89.95437622]) - - x2 = paddle.to_tensor(np.pi/2) - result2 = paddle.rad2deg(x2) - print(result2) - # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [90.]) - - x3 = paddle.to_tensor(1) - result3 = paddle.rad2deg(x3) - print(result3) - # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - # [57.29578018]) +COPY-FROM: paddle.rad2deg From 4d2398d61f204c8990e1c6d1a8ef8b57c5a840a9 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Fri, 10 Dec 2021 14:29:22 +0800 Subject: [PATCH 4/4] refine gcd & lcm docs --- docs/api/paddle/gcd_cn.rst | 38 ++++++------------------------------ docs/api/paddle/lcm_cn.rst | 40 +++++++------------------------------- 2 files changed, 13 insertions(+), 65 deletions(-) diff --git a/docs/api/paddle/gcd_cn.rst b/docs/api/paddle/gcd_cn.rst index bfd9a10f3b0..87562d5d1be 100644 --- a/docs/api/paddle/gcd_cn.rst +++ b/docs/api/paddle/gcd_cn.rst @@ -11,12 +11,14 @@ gcd gcd(0,0)=0, gcd(0, y)=|y| + 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), + 请参见 :ref:`cn_user_guide_broadcasting` 。 + 参数 ::::::::: -- **x, y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), - 请参见 :ref:`cn_user_guide_broadcasting` 。 +- **x** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 +- **y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 返回 @@ -27,32 +29,4 @@ gcd 代码示例 ::::::::: -.. code-block:: python - - import paddle - import numpy as np - - x1 = paddle.to_tensor(12) - x2 = paddle.to_tensor(20) - paddle.gcd(x1, x2) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [4]) - - x3 = paddle.to_tensor(np.arange(6)) - paddle.gcd(x3, x2) - # Tensor(shape=[6], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [20, 1 , 2 , 1 , 4 , 5]) - - x4 = paddle.to_tensor(0) - paddle.gcd(x4, x2) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [20]) - - paddle.gcd(x4, x4) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [0]) - - x5 = paddle.to_tensor(-20) - paddle.gcd(x1, x5) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [4]) +COPY-FROM: paddle.gcd diff --git a/docs/api/paddle/lcm_cn.rst b/docs/api/paddle/lcm_cn.rst index cb1abc012d7..2c76cd9dcb0 100644 --- a/docs/api/paddle/lcm_cn.rst +++ b/docs/api/paddle/lcm_cn.rst @@ -5,18 +5,20 @@ lcm .. py:function:: paddle.lcm(x, y, name=None) -计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 +计算两个输入的按元素绝对值的最小公倍数,输入必须是整型。 .. note:: lcm(0,0)=0, lcm(0, y)=0 + 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), + 请参见 :ref:`cn_user_guide_broadcasting` 。 + 参数 ::::::::: -- **x, y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - 如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), - 请参见 :ref:`cn_user_guide_broadcasting` 。 +- **x** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 +- **y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 返回 @@ -27,32 +29,4 @@ lcm 代码示例 ::::::::: -.. code-block:: python - - import paddle - import numpy as np - - x1 = paddle.to_tensor(12) - x2 = paddle.to_tensor(20) - paddle.lcm(x1, x2) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [60]) - - x3 = paddle.to_tensor(np.arange(6)) - paddle.lcm(x3, x2) - # Tensor(shape=[6], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [0, 20, 20, 60, 20, 20]) - - x4 = paddle.to_tensor(0) - paddle.lcm(x4, x2) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [0]) - - paddle.lcm(x4, x4) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [0]) - - x5 = paddle.to_tensor(-20) - paddle.lcm(x1, x5) - # Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, - # [60]) +COPY-FROM: paddle.lcm