[ torch 参数更多 ]torch.Tensor.index_add

torch.Tensor.index_add

torch.Tensor.index_add(dim, index, source, *, alpha=1)

paddle.index_add

paddle.index_add(x, index, axis, value, name=None)

其中 Pytorch 与 Paddle 参数有差异,具体如下:

参数映射

| PyTorch | PaddlePaddle | 备注 | | ————- | ———— | —————————————————— | | - | x | 表示输入的 Tensor 。 | | dim | axis | 表示进行运算的轴,仅参数名不一致。 | | index | index | 包含索引下标的 1-D Tensor。 | | source | value | 被加的 Tensor,仅参数名不一致。 | | alpha | - | source 的 缩放倍数, Paddle 无此参数,需要转写。Paddle 应将 alpha 和 source 的乘积作为 value。 |

转写示例

alpha:source 的缩放倍数

# Pytorch 写法
x.index_add(dim=1, index=index, source=source, alpha=alpha)

# Paddle 写法
paddle.index_add(x, index=index, axis=1, value=alpha*source)