index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, alpha: float = 1.0)Return input with alpha * source accumulated at index positions along dim.
Differentiable through both input and source. alpha is
accumulated as a Python constant — gradients pass through cleanly
as if the multiplication were inlined.
Parameters
inputTensorSource tensor; not mutated.
dimintAxis along which
index addresses slices.indexTensor1-D integer tensor of length listing positions along
dim to accumulate into.sourceTensorPer-slice update tensor; same shape as
input except
source.shape[dim] == m (matching index length).alphafloat= 1.0Scalar multiplier applied to
source before accumulation.
Default 1.0.Returns
TensorSame shape and dtype as input; positions listed in
index carry input[..., index[i], ...] + alpha * source[..., i, ...].