IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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 the input, indices, updates, and output tensors.
  • ​input_type (DType): Element type of input, updates, and output.
  • ​indices_type (DType): Element type of indices (must be int32 or int64).
  • ​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_add for addition or _atomic_reduce[reduce_fn] for a binary reduction. Without a callable, duplicate indices leave an unspecified winner.

Args:

Was this page helpful?