ai.onnx.ScatterND

ai.onnx · standard ONNX operator · ONNX opset ≥ 18

Description

Copies data and then scatters values from updates into the copy at positions specified by indices, producing an output with the same shape as data. Each entry in indices is a k-tuple that addresses either a single element (when k equals the rank of data) or a slice; an optional reduction attribute replaces the default overwrite with an elementwise add, mul, max, or min accumulation.

See the ONNX ScatterND spec for the reference semantics.

Inputs

Name Bind key Logical dtype WebGPU storage Rank Shape Description Presence
data data T runtime-selected; narrow integers and bool use 32-bit slots Source tensor of rank r >= 1 that is copied to form the base of the output. required
indices indices I int32 Logical int64 index tensor of rank q >= 1 whose last dimension gives signed k-tuples that address into data; WebGPU stores it as int32. required
updates updates T runtime-selected; narrow integers and bool use 32-bit slots Values to scatter into the output, of rank q + r - k - 1, matching the leading (q-1) index dimensions and the trailing (r-k) data slice dimensions. required

Outputs

Name Bind key Logical dtype Rank Shape Description Presence
output output T same as data same as data Result tensor of rank r with the same shape as data, with selected positions overwritten or reduced by updates. required

Attributes

Default values (overridable per request):

Attribute Default Description
reduction "none" Reduction to apply when writing each update value: none (overwrite), add, mul, max, or min.

Type constraints

Variable Allowed dtypes
T float32, float16, int32, uint32, int8, uint8, int16, bool
I int64

Files

Use with @huggingface/kernels

The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.

Replace each *Data placeholder with a typed array containing the corresponding input data.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.ScatterND", { version: 1 });
const { output } = await kernel({
  data: { data: dataData, shape: [2, 2] },
  indices: { data: indicesData, shape: [2, 1] },
  updates: { data: updatesData, shape: [2, 2] },
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.