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

【Hackathon 4th 】新增 trapezoid 和 cumulative_trapezoid doc #5685

Merged
merged 10 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/api/api_label
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ paddle.sum .. _api_paddle_sum:
paddle.t .. _api_paddle_t:
paddle.take .. _api_paddle_take:
paddle.frexp .. _api_paddle_frexp:
paddle.trapezoid .. _api_paddle_trapezoid:
paddle.cumulative_trapezoid .. _api_paddle_cumulative_trapezoid:
paddle.tanh .. _api_paddle_tanh:
paddle.tanh_ .. _api_paddle_tanh_:
paddle.tile .. _api_paddle_tile:
Expand Down Expand Up @@ -1210,4 +1212,4 @@ paddle.bernoulli .. _api_paddle_bernoulli:
paddle.uniform .. _api_paddle_uniform:
paddle.get_cuda_rng_state .. _api_paddle_get_cuda_rng_state:
paddle.flops .. _api_paddle_flops:
paddle.load .. _api_paddle_load:
paddle.load .. _api_paddle_load:
4 changes: 2 additions & 2 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ tensor 数学操作
" :ref:`paddle.atanh <cn_api_fluid_layers_atanh>` ", "反双曲正切函数"
" :ref:`paddle.take <cn_api_paddle_tensor_take>` ", "输出给定索引处的输入元素,结果与 index 的形状相同"
" :ref:`paddle.frexp <cn_api_paddle_frexp>` ", "用于把一个浮点数分解为尾数和指数的函数"


" :ref:`paddle.trapezoid <cn_api_paddle_tensor_trapezoid>` ", "在指定维度上对输入实现 trapezoid rule 算法。使用累积求和函数 sum"
" :ref:`paddle.cumulative_trapezoid <cn_api_paddle_tensor_cumulative_trapezoid>` ", "在指定维度上对输入实现 trapezoid rule 算法。使用累积求和函数 cumsum"
.. _tensor_math_inplace:

tensor 数学操作原位(inplace)版本
Expand Down
2 changes: 2 additions & 0 deletions docs/api/paddle/Tensor/Overview_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,5 @@ Methods
is_complex
is_integer
frexp
trapezoid
cumulative_trapezoid
24 changes: 23 additions & 1 deletion docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2485,11 +2485,33 @@ data_ptr()

返回类型:int

trapezoid(y, x=None, dx=None, axis=-1, name=None)
:::::::::

在指定维度上对输入实现 trapezoid rule 算法。使用求和函数 sum。

返回:计算后的 Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_tensor_trapezoid`

cumulative_trapezoid(y, x=None, dx=None, axis=-1, name=None)
:::::::::

在指定维度上对输入实现 trapezoid rule 算法。使用求和函数 cumsum。
Ainavo marked this conversation as resolved.
Show resolved Hide resolved

返回:计算后的 Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_tensor_cumulative_trapezoid`
Ainavo marked this conversation as resolved.
Show resolved Hide resolved

polar(abs, angle)
:::::::::
用于将输入的模和相位角计算得到复平面上的坐标
返回:一个复数 Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_polar`
请参考 :ref:`cn_api_paddle_polar`
27 changes: 27 additions & 0 deletions docs/api/paddle/cumulative_trapezoid_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _cn_api_paddle_tensor_cumulative_trapezoid:

cumulative_trapezoid
--------------------------------

.. py:function:: paddle.cumulative_trapezoid(y, x=None, dx=None, axis=-1, name=None)

在指定维度上对输入实现 `trapezoid rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ 算法。与 :ref:`cn_api_paddle_tensor_trapezoid` 的区别是,所用累积求和函数为 cumsum。


参数
:::::::::

- **y** (Tensor) - 输入多维 Tensor,可选的数据类型为 float16、float32、float64。
- **x** (Tensor,可选) - ``y`` 中数值对应的浮点数所组成的 Tensor,类型与 ``y`` 相同,形状与 ``y`` 的形状相匹配;若 ``x`` 有输入,已知 ``y`` 的尺寸为 `[d_1, d_2, ... , d_n]` 且 `axis=k`,则 ``x`` 的尺寸只能为 `[d_k]` 或 `[d_1, d_2, ... , d_n]`;如果 ``x`` 为 None,则假定采样点均匀分布 ``dx``。
- **dx** (float,可选) - 相邻采样点之间的常数间隔;当 ``x`` 和 ``dx`` 均未指定时,``dx`` 默认为 1.0。
- **axis** (int,可选) - 计算 trapezoid rule 时 ``y`` 的维度。默认值 -1。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
返回
:::::::::
Tensor,按 trapezoidal rule 计算出 ``y`` 等于 N 维张量时的定积分,结果为 N 维张量。


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

COPY-FROM: paddle.cumulative_trapezoid
27 changes: 27 additions & 0 deletions docs/api/paddle/trapezoid_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _cn_api_paddle_tensor_trapezoid:

trapezoid
--------------------------------

.. py:function:: paddle.trapezoid(y, x=None, dx=None, axis=-1, name=None)

在指定维度上对输入实现 `trapezoid rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ 算法。与 :ref:`cn_api_paddle_tensor_cumulative_trapezoid` 的区别是,所用累积求和函数为 sum。


参数
:::::::::

- **y** (Tensor) - 输入多维 Tensor,可选的数据类型为 float16、float32、float64。
- **x** (Tensor,可选) - ``y`` 中数值对应的浮点数所组成的 Tensor,类型与 ``y`` 相同,形状与 ``y`` 的形状相匹配;若 ``x`` 有输入,已知 ``y`` 的尺寸为 `[d_1, d_2, ... , d_n]` 且 `axis=k`,则 ``x`` 的尺寸只能为 `[d_k]` 或 `[d_1, d_2, ... , d_n]`;如果 ``x`` 为 None,则假定采样点均匀分布 ``dx``。
- **dx** (float,可选) - 相邻采样点之间的常数间隔;当 ``x`` 和 ``dx`` 均未指定时,``dx`` 默认为 1.0。
- **axis** (int,可选) - 计算 trapezoid rule 时 ``y`` 的维度。默认值 -1。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
返回
:::::::::
Tensor,按 trapezoidal rule 计算出 ``y`` 等于 N 维张量时的定积分,如果 ``y`` 是一维张量,则结果是浮点数。如果 N 大于 1 维,则结果为 N-1 维张量。


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

COPY-FROM: paddle.trapezoid