From 69353d5066dc5cc2ea2e68506163d4583aca57fb Mon Sep 17 00:00:00 2001 From: Xinyu Yang <102154774+ndyysheep@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:17:22 +0800 Subject: [PATCH 1/4] [SCU][Add API Legend No.21] Add the legend of scatter_nd_add_en --- python/paddle/tensor/manipulation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index b2b29874cb5d65..f5f2f5e7def22e 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -4332,6 +4332,16 @@ 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( From dc59ac23f721788098e1f16c53036318d1c2900a Mon Sep 17 00:00:00 2001 From: Xinyu Yang <102154774+ndyysheep@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:48:21 +0800 Subject: [PATCH 2/4] Update manipulation.py --- python/paddle/tensor/manipulation.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index f5f2f5e7def22e..9d375e01c45c5a 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -4335,13 +4335,19 @@ def scatter_nd_add( - **Explanation of Example 1**: +**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 - 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( From 0a5fe61196ff586a13b6228ca3bbea1e3f347aef Mon Sep 17 00:00:00 2001 From: Xinyu Yang <102154774+ndyysheep@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:14:24 +0800 Subject: [PATCH 3/4] Update manipulation.py --- python/paddle/tensor/manipulation.py | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 9d375e01c45c5a..c017c0575de01f 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -4335,20 +4335,23 @@ def scatter_nd_add( -**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 - - """ + **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( + # Your error handling code + ) 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)}" From cfecb6e8853c304e3e028e0103c09a14279b0385 Mon Sep 17 00:00:00 2001 From: Xinyu Yang <102154774+ndyysheep@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:16:06 +0800 Subject: [PATCH 4/4] Update manipulation.py --- python/paddle/tensor/manipulation.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index c017c0575de01f..6eb849464facde 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -4348,10 +4348,6 @@ def scatter_nd_add( :alt: Example 1 Illustration :align: center """ - if x.dtype != updates.dtype: - raise TypeError( - # Your error handling code - ) 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)}"