-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add paddle.gcd & lcm docs #4130
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.. _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** (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`。 | ||
|
||
返回 | ||
::::::::: | ||
|
||
输出Tensor,与输入数据类型相同。 | ||
|
||
代码示例 | ||
::::::::: | ||
|
||
.. code-block:: python | ||
|
||
import paddle | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 示例代码同英文,建议使用 COPY:FROM 方便保持一致性~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
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]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.. _cn_api_paddle_tensor_lcm: | ||
|
||
lcm | ||
------------------------------- | ||
|
||
.. py:function:: paddle.lcm(x, y, name=None) | ||
|
||
计算两个输入的按元素绝对值的最大公约数,输入必须是整型。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 最大公约数 -> 最小公倍数 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
.. note:: | ||
|
||
lcm(0,0)=0, lcm(0, y)=0 | ||
|
||
参数 | ||
::::::::: | ||
|
||
- **x, y** (Tensor) - 输入的Tensor,数据类型为:int8,int16,int32,int64,uint8。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 格式同 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), | ||
请参见 :ref:`cn_user_guide_broadcasting` 。 | ||
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 | ||
|
||
返回 | ||
::::::::: | ||
|
||
输出Tensor,与输入数据类型相同。 | ||
|
||
代码示例 | ||
::::::::: | ||
|
||
.. code-block:: python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 示例代码同 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里同英文的格式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done