index_put(input: Tensor, indices: list[Tensor] | tuple[Tensor, ...], values: Tensor, accumulate: bool = False)Out-of-place advanced-indexing write.
Equivalent to out = input.clone(); out[tuple(indices)] = values
(adding at each position when accumulate=True): indices is
read as the key Tensor.__setitem__ reads, by the same owner
(lucid._tensor._indexing._normalize_key). A bool mask selects its
True positions; integer index tensors broadcast together and address
the leading dimensions, the rest taken whole —
index_put(x, (i,), v) on a (4, 3) tensor writes whole rows.
Parameters
inputTensorDestination tensor; not mutated.
indicessequence of TensorsOne integer index tensor per leading dimension of
input, or a
bool mask covering as many dims as it has.valuesTensorValues of
input's dtype, broadcastable to the shape
input[tuple(indices)] reads.accumulatebool= FalseIf True, add at each position — a position named twice receives
both; otherwise overwrite — a position named twice keeps the last
write on the CPU and an unspecified one of its values on Metal.
Returns
TensorA new tensor of input's shape and dtype.
Raises
ValueErrorindices is not a non-empty sequence.IndexErrorMore indices than
input has dims, a mask whose shape does not
match, index tensors that do not broadcast together, or — on the
CPU — an index out of range; Metal drops such a write.lucid._C.engine.DtypeMismatchvalues's dtype is not input's.Examples
>>> import lucid
>>> mask = lucid.tensor([False, False, True, True])
>>> lucid.index_put(lucid.zeros(4), (mask,), lucid.tensor(5.0))
tensor([0., 0., 5., 5.])