Skip to content
fn

scatter_add_op

→TensorImplPtr
int scatter_add_op(const int & base, const int & indices, const int & src, int dim)

Python wrappers

Public Python APIs implemented by this engine symbol.

User-facing scatter-add: out = base with src accumulated at positions given by indices along dim.

Math

out[i0,…,id−1,indices[j],id+1,… ]+=src[i0,…,j,… ] \text{out}[i_0, \dots, i_{d-1}, \text{indices}[j], i_{d+1}, \dots] \mathrel{+}= \text{src}[i_0, \dots, j, \dots]

Parameters

baseTensorImplPtr
Tensor providing the initial values; same shape as the output.
indicesTensorImplPtr
int32 or int64 tensor indexing into base along dim. Shape matches src.
srcTensorImplPtr
Values to add, in base's dtype.
dimint
Axis along which scattering occurs.

Returns

TensorImplPtr

Same shape and dtype as base.

Raises

DtypeMismatch
If src is not in base's dtype or indices is not int32 / int64 — the rule of scatter_amax_op, scatter_amin_op, scatter_prod_op and scatter_set_op too. Nothing is cast.

Notes

Full autograd support. Gradients: ∂/∂base=grad_out\partial / \partial \text{base} = \text{grad\_out}, ∂/∂src=gather(grad_out,dim,indices)\partial / \partial \text{src} = \text{gather}(\text{grad\_out}, \text{dim}, \text{indices}).