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

[SCU][Add API Legend No.21] Add the legend of scatter_nd_add_cn #6964

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion docs/api/paddle/scatter_nd_add_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,13 @@ Tensor,数据类型和形状都与 :code:`x` 相同。
代码示例
::::::::::::

COPY-FROM: paddle.scatter_nd_add
Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么把这块儿删了? 这部分是引用源码里的代码示例


output = [0, 22, 12, 14, 4, 5]
Copy link
Collaborator

Choose a reason for hiding this comment

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

这部分是笔误了多加了么


**示例一图解说明**:

在这个示例中,通过 Paddle 的 scatter_nd_add 函数对张量 x 进行稀疏加法操作。初始张量 x 为 [0, 1, 2, 3, 4, 5],通过 index 指定需要更新的索引位置,并使用 updates 中的值进行累加。scatter_nd_add 函数会根据 index 的位置逐步累加 updates 中的对应值,而不是替换原有值,最终得到输出张量为 [0, 22, 12, 14, 4, 5],实现了对张量部分元素的累加更新而保持其他元素不变。
.. figure:: ../../images/api_legend/scatter_nd_add.png
:width: 700
:alt: 示例一图示
:align: center
Comment on lines +63 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

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

图解部分放在 参数 板块上面,即api简介的那部分。 而不是替换原有值 有些多余,可以删掉

69 changes: 69 additions & 0 deletions docs/api/paddle/scatter_nd_add_en.rst
Copy link
Collaborator

Choose a reason for hiding this comment

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

英文文档是直接从 源码 里抽取docstring再自动转成rst的,不用手写,这块儿全删了吧

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. _en_api_paddle_scatter_nd_add:

scatter_nd_add
-------------------------------

.. py:function:: paddle.scatter_nd_add(x, index, updates, name=None)




Performs sparse addition on individual values or slices in a Tensor, resulting in an output Tensor.

:code:`x` is a Tensor with a dimension of :code:`R`. :code:`index` is a Tensor with a dimension of :code:`K`, which means that the shape of :code:`index` is :math:`[i_0, i_1, ..., i_{K-2}, Q]`, where :math:`Q \leq R`. :code:`updates` is a Tensor with a dimension of :math:`K - 1 + R - Q` and a shape of :math:`index.shape[:-1] + x.shape[index.shape[-1]:]`.

According to the :math:`[i_0, i_1, ..., i_{K-2}]` of :code:`index`, it selects the corresponding :code:`updates` slice and adds it to the :code:`x` slice obtained by the last dimension of :code:`index`, resulting in the final output Tensor.

Examples:

::

- Example 1:
x = [0, 1, 2, 3, 4, 5]
index = [[1], [2], [3], [1]]
updates = [9, 10, 11, 12]

Result:

output = [0, 22, 12, 14, 4, 5]

- Example 2:
x = [[65, 17], [-14, -25]]
index = [[], []]
updates = [[[-1, -2], [1, 2]],
[[3, 4], [-3, -4]]]
x.shape = (2, 2)
index.shape = (2, 0)
updates.shape = (2, 2, 2)

Result:

output = [[67, 19], [-16, -27]]


Parameters
::::::::::::

- **x** (Tensor) - The input tensor, data type can be int32, int64, float32, float64.
- **index** (Tensor) - The index tensor, data type must be non-negative int32 or non-negative int64. Its dimension :code:`index.ndim` must be greater than 1, and :code:`index.shape[-1] <= x.ndim`
- **updates** (Tensor) - The update tensor, which must have the same data type as :code:`x`. Its shape must be :code:`index.shape[:-1] + x.shape[index.shape[-1]:]`.
- **name** (str, optional) - For more details, refer to :ref:`api_guide_Name`. Generally, this does not need to be set. Default is None.

Returns
::::::::::::

A tensor with the same data type and shape as :code:`x`.

Example Code
::::::::::::


output = [0, 22, 12, 14, 4, 5]

**Explanation of Example 1**:

In this example, the scatter_nd_add function of Paddle performs sparse addition on the tensor `x`. The initial tensor `x` is `[0, 1, 2, 3, 4, 5]`. The `index` specifies the positions to be updated, and the values in `updates` are used to accumulate them. The scatter_nd_add function will add the corresponding values in `updates` to the specified positions in `x`, rather than replacing the original values. Finally, the output tensor is `[0, 22, 12, 14, 4, 5]`, achieving the cumulative update of specific elements in the tensor while keeping other elements unchanged.
.. figure:: ../../images/api_legend/scatter_nd_add.png
:width: 700
:alt: Example 1 Illustration
:align: center
Binary file added docs/images/api_legend/scatter_nd_ad.png
Copy link
Collaborator

Choose a reason for hiding this comment

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

红色虚线框似乎会增加图片的理解难度,可以删掉。 +9 可以放在方向键的左侧保持统一

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.