Skip to content

Commit

Permalink
add paddle.gcd & lcm docs (#4130)
Browse files Browse the repository at this point in the history
  • Loading branch information
luotao1 authored Dec 10, 2021
1 parent fe4c873 commit d7aa3e0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 40 deletions.
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ tensor数学操作
" :ref:`paddle.diff <cn_api_tensor_diff>` ", "沿着指定维度对输入Tensor计算n阶的前向差值"
" :ref:`paddle.rad2deg <cn_api_paddle_tensor_rad2deg>` ", "将元素从弧度的角度转换为度"
" :ref:`paddle.deg2rad <cn_api_paddle_tensor_deg2rad>` ", "将元素从度的角度转换为弧度"
" :ref:`paddle.gcd <cn_api_paddle_tensor_gcd>` ", "计算两个输入的按元素绝对值的最大公约数"
" :ref:`paddle.lcm <cn_api_paddle_tensor_lcm>` ", "计算两个输入的按元素绝对值的最小公倍数"


.. _tensor_logic:
Expand Down
18 changes: 18 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,15 @@ gather_nd(index, name=None)

请参考 :ref:`cn_api_tensor_cn_gather_nd`

gcd(x, y, name=None)
:::::::::

计算两个输入的按元素绝对值的最大公约数

返回:计算后的Tensor

请参考 :ref:`cn_api_paddle_tensor_gcd`

gradient()
:::::::::

Expand Down Expand Up @@ -1177,6 +1186,15 @@ kron(y, name=None)

请参考 :ref:`cn_api_paddle_tensor_kron`

lcm(x, y, name=None)
:::::::::

计算两个输入的按元素绝对值的最小公倍数

返回:计算后的Tensor

请参考 :ref:`cn_api_paddle_tensor_lcm`

less_equal(y, name=None)
:::::::::

Expand Down
18 changes: 1 addition & 17 deletions docs/api/paddle/deg2rad_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions docs/api/paddle/gcd_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _cn_api_paddle_tensor_gcd:

gcd
-------------------------------

.. py:function:: paddle.gcd(x, y, name=None)
计算两个输入的按元素绝对值的最大公约数,输入必须是整型。

.. note::

gcd(0,0)=0, gcd(0, y)=|y|

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

返回
:::::::::

输出Tensor,与输入数据类型相同。

代码示例
:::::::::

COPY-FROM: paddle.gcd
32 changes: 32 additions & 0 deletions docs/api/paddle/lcm_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _cn_api_paddle_tensor_lcm:

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** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。
- **y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。

返回
:::::::::

输出Tensor,与输入数据类型相同。

代码示例
:::::::::

COPY-FROM: paddle.lcm
24 changes: 1 addition & 23 deletions docs/api/paddle/rad2deg_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d7aa3e0

Please sign in to comment.