For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
scatter_elements
def scatter_elements[rank: Int, input_type: DType, indices_type: DType, *, reduce_fn: OptionalReg[def[dtype: DType, width: SIMDLength](SIMD[dtype, width], SIMD[dtype, width]) thin -> SIMD[dtype, width]] = 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: DeviceContext)
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). - βreduce_fn (
OptionalReg[def[dtype: DType, width: SIMDLength](SIMD[dtype, width], SIMD[dtype, width]) thin -> SIMD[dtype, width]]): Reduction function to apply: none (default, overwrite), add, mul, max, min. Updates for duplicate indices are reduced atomically, in unspecified order (without a reduce_fn, duplicates leave an unspecified winner instead).
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 (
DeviceContext): Device context for execution.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!