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_en #69468

Closed
wants to merge 4 commits into from
Closed
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
17 changes: 16 additions & 1 deletion python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4332,7 +4332,22 @@ def scatter_nd_add(
>>> output = paddle.scatter_nd_add(x, index, updates)
>>> print(output.shape)
[3, 5, 9, 10]
"""



**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
"""
if x.dtype != updates.dtype:
raise TypeError(
f"x and updates must have same data type but x.dtype={convert_dtype(x.dtype)}, updates.dtype={convert_dtype(updates.dtype)}"
Expand Down