Skip to content
fn

scatter_set_op

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

scatter_set: out[..., index[i], ...] = src[..., i, ...] along dim (overwrite). A copy of base with the indexed slices replaced by src — the single-op primitive that index_copy routes through.

Parameters

base, indices, src, dim
Same semantics as scatter_add_op.

Returns

TensorImplPtr

Same shape and dtype as base.

Notes

Gradients: ∂/∂base[i]=grad[i]\partial / \partial \text{base}[i] = \text{grad}[i] except at overwritten positions where it is 0; ∂/∂src[j]=grad[idx[j]]\partial / \partial \text{src}[j] = \text{grad}[\text{idx}[j]] (a plain gather). Duplicate indices follow the reference framework's last-writer-wins convention.