Skip to content
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

【PaddlePaddle Hackathon 3 No.14】为 Paddle 新增 remainder_ API #5156

Merged
merged 18 commits into from
Aug 31, 2022
1 change: 1 addition & 0 deletions docs/api/api_label
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ paddle.floor .. _api_paddle_floor:
paddle.Tensor.floor_ .. _api_paddle_Tensor_floor_:
paddle.floor_divide .. _api_paddle_floor_divide:
paddle.mod .. _api_paddle_mod:
paddle.remainder .. _api_tensor_remainder:
paddle.gather .. _api_paddle_gather:
paddle.gather_nd .. _api_paddle_gather_nd:
paddle.greater_equal .. _api_paddle_greater_equal:
Expand Down
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ tensor 数学操作
" :ref:`paddle.stanh <cn_api_fluid_layers_stanh>` ", "stanh 激活函数"
" :ref:`paddle.std <cn_api_tensor_cn_std>` ", "沿给定的轴 axis 计算 x 中元素的标准差"
" :ref:`paddle.subtract <cn_api_paddle_tensor_subtract>` ", "逐元素相减算子"
" :ref:`paddle.remainder <cn_api_tensor_remainder>` ", "逐元素取模算子"
" :ref:`paddle.remainder_ <cn_api_tensor_remainder_>` ", "Inplace 版本的 remainder API,对输入 x 采用 Inplace 策略"
" :ref:`paddle.sum <cn_api_tensor_sum>` ", "对指定维度上的 Tensor 元素进行求和运算"
" :ref:`paddle.tan <cn_api_fluid_layers_tan>` ", "三角函数 tangent"
" :ref:`paddle.tanh <cn_api_tensor_tanh>` ", "tanh 激活函数"
Expand Down
11 changes: 10 additions & 1 deletion docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,16 @@ remainder(y, name=None)

返回类型:Tensor

mod 函数的别名,请参考 :ref:`cn_api_tensor_mod`
mod 函数的别名,请参考 :ref:`cn_api_tensor_remainder`

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

返回:计算后的 Tensor

返回类型:Tensor

Inplace 版本的 :ref:`cn_api_tensor_remainder_` API,对输入 `x` 采用 Inplace 策略。

reshape(shape, name=None)
:::::::::
Expand Down
6 changes: 3 additions & 3 deletions docs/api/paddle/mod_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mod

参数
:::::::::
- x(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- y(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- name(str,可选)- 操作的名称(可选,默认值为 None)。更多信息请参见 :ref:`api_guide_Name`。
- **x**(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- **y**(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- **name**(str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为 None

返回
:::::::::
Expand Down
8 changes: 8 additions & 0 deletions docs/api/paddle/remainder__cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _cn_api_tensor_remainder_:

remainder\_
-------------------------------

.. py:function:: paddle.remainder_(x, y, name=None)

Inplace 版本的 :ref:`cn_api_tensor_remainder` API,对输入 `x` 采用 Inplace 策略。
31 changes: 31 additions & 0 deletions docs/api/paddle/remainder_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. _cn_api_tensor_remainder:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有点奇怪的是,这个页面(https://preview-pr-5156.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/remainder_cn.html)无法渲染在侧边栏,在该页面也无法渲染侧边栏

https://github.com/PaddlePaddle/Paddle/blob/126940b344022c44cc220a7e0214fcf300957b7e/python/paddle/tensor/math.py#L787

另外 mod 和 remainder 只是 alias 关系,也许我们可以有一个规范来避免这种重复 @BrilliantYuKaimin (这个和 mod 内容基本是一致的)

Copy link
Collaborator

@Ligoml Ligoml Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个很神奇,因为代码里就是这么写的:https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/tensor/math.py#L787

mod = remainder  # noqa: F841
floor_mod = remainder  # noqa: F841

也就是说这三个API拥有同一个ID,所以官网只会生成其中一个API文档,这个我之前提过,解决办法就是def 三个API,然后分别管理文档

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def mod(x, y, name=None):
    return remainder(x, y, name)

mod.__doc__ = remainder.__doc__

这样?呃……好麻烦……


remainder
-------------------------------

.. py:function:: paddle.remainder(x, y, name=None)


逐元素取模算子。公式为:

.. math::
\\out = x \% y\\

.. note::
``paddle.remainder`` 遵守 broadcasting,如您想了解更多,请参见 :ref:`cn_user_guide_broadcasting` 。
zrr1999 marked this conversation as resolved.
Show resolved Hide resolved

参数
:::::::::

- **x**(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- **y**(Tensor)- 多维 Tensor。数据类型为 float32 、float64、int32 或 int64。
- **name**(str,可选) - 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为 None。

返回
:::::::::
``Tensor``,存储运算后的结果。如果 x 和 y 有不同的 shape 且是可以广播的,返回 Tensor 的 shape 是 x 和 y 经过广播后的 shape。如果 x 和 y 有相同的 shape,返回 Tensor 的 shape 与 x,y 相同。

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

COPY-FROM: paddle.remainder