scatter(input: Tensor, dim: _int, index: Tensor, src: Tensor | Scalar, reduce: str | None = ...)Implementing kernel
C++ engine symbols that back this Python API.Write src into input along dim at positions index.
Inverse of gather. For each entry of src the destination
is determined by substituting index into the dim coordinate;
all other coords are inherited from the source position. If
multiple sources target the same destination the result is
implementation-defined unless reduce is given.
Parameters
inputTensorDestination tensor (will be copied — out-of-place).
dimintAxis along which to scatter.
indexTensorInteger index tensor; same shape as
src.srcTensor or scalarValues to write, of
input's dtype — another dtype is
refused rather than cast — or one number written everywhere
index points.reducestr= ...'add' or 'multiply' to disambiguate collisions
deterministically.Returns
TensorUpdated tensor of the same shape as input.
Notes
For deterministic accumulation prefer scatter_add.
Examples
>>> import lucid
>>> base = lucid.zeros(3, 4)
>>> idx = lucid.tensor([[0, 1, 2, 0]])
>>> src = lucid.tensor([[1.0, 2.0, 3.0, 4.0]])
>>> lucid.scatter(base, dim=0, index=idx, src=src)
Tensor(shape=(3, 4))