For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
scatter_elements
def scatter_elements[rank: Int, input_type: DType, indices_type: DType, *, target: StringSpan[ImmStaticOrigin] = StringSpan("cpu"), atomic_update_fn: OptionalReg[def[dtype: DType](Pointer[Scalar[dtype], *?, address_space=*?], Scalar[dtype]) thin -> None] = None](input: ManagedTensorSlice[static_spec=input.static_spec], indices: ManagedTensorSlice[static_spec=indices.static_spec], updates: ManagedTensorSlice[static_spec=updates.static_spec], _axis: Int, output: ManagedTensorSlice[static_spec=output.static_spec], ctx: DeviceContextBase)
Implements ONNX ScatterElements op which is equivalent to Pytorch scatter.
Parameters:
- rank (
Int): Rank of theinput,indices,updates, andoutputtensors. - input_type (
DType): Element type ofinput,updates, andoutput. - indices_type (
DType): Element type ofindices(must beint32orint64). - target (
StringSpan[ImmStaticOrigin]): Target backend to execute on, such as "cpu" or "gpu". - atomic_update_fn (
OptionalReg[def[dtype: DType](Pointer[Scalar[dtype], *?, address_space=*?], Scalar[dtype]) thin -> None]): Callable that atomically applies an update to a destination pointer. Called for every update on CPU and GPU, in unspecified order. Use_atomic_addfor addition or_atomic_reduce[reduce_fn]for a binary reduction. Without a callable, duplicate indices leave an unspecified winner.
Args:
- input (
ManagedTensorSlice[static_spec=input.static_spec]): Source tensor copied intooutputbefore scattering. - indices (
ManagedTensorSlice[static_spec=indices.static_spec]): Indices along_axisselecting where updates land inoutput. - updates (
ManagedTensorSlice[static_spec=updates.static_spec]): Values to scatter intooutputat positions given byindices. - _axis (
Int): Axis along which to scatter; must be in[-rank, rank). - output (
ManagedTensorSlice[static_spec=output.static_spec]): Output tensor, same shape asinput, receiving scattered updates. - ctx (
DeviceContextBase): Device context for execution.