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 | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
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 |
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 |
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 | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
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, no duplicate index tuples), add, mul, max, or min. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, int32, uint32, int8, uint8, int16, bool |
I |
int64 |
Files
metadata.json— kernel metadata (id, digests, per-variant templates, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casesdatamove-scatter-row.wgsl.jinjascatter-f16-f32-convert.wgsl.jinjascatter-flat-copy.wgsl.jinjascatter-narrow-wrap.wgsl.jinjascatter-nd-reduction-atomic.wgsl.jinjascatter-nd-reduction-f16-packed-atomic.wgsl.jinjascatter-nd-reduction-slice.wgsl.jinjascatter-nd.wgsl.jinjascatter-scalar-add.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.2
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of 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
- -
Requires WebGPU support. See the compatibility table.