Skip to content

Commit

Permalink
refine gcd & lcm docs
Browse files Browse the repository at this point in the history
  • Loading branch information
luotao1 committed Dec 10, 2021
1 parent 1654ae6 commit 09f0c27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 65 deletions.
37 changes: 5 additions & 32 deletions docs/api/paddle/gcd_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ gcd
.. note::

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`。

返回
Expand All @@ -27,32 +28,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
39 changes: 6 additions & 33 deletions docs/api/paddle/lcm_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ 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`。

返回
Expand All @@ -27,32 +28,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

0 comments on commit 09f0c27

Please sign in to comment.