ai.onnx.ScatterElements
ai.onnx · standard ONNX operator · ONNX opset ≥ 18
Description
Produces a copy of data with values updated at positions given by indices along the specified axis. For each entry in updates, the axis coordinate comes from indices while all other coordinates come from the entry's own position in updates. An optional reduction (add, mul, max, min) combines updates with existing values instead of overwriting; with none, duplicate indices are not allowed.
See the ONNX ScatterElements spec for the reference semantics.
Inputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
data |
data |
T |
— | — | Input tensor of rank r >= 1 that is copied to form the output base. | required |
indices |
indices |
I |
— | — | Integer index tensor of the same rank as data; each value selects a position along axis. |
required |
updates |
updates |
T |
— | — | Values to scatter, same rank and shape as indices. |
required |
Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
output |
output |
T |
same as data |
same as data |
Copy of data with scattered updates applied; same shape as data. |
required |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
axis |
0 |
Which axis to scatter on; negative values count from the back. Accepted range is [-r, r-1] where r = rank(data). |
reduction |
"none" |
Reduction to apply when writing updates: none (overwrite, no duplicate indices), add, mul, max, or min. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, int32, uint32, int8, uint8, int16, bool |
I |
int32 |
Device requirements
Some implementation variants require subgroups. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.
Files
metadata.json— kernel metadata (id, digests, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casesscatter-elements-f32-add-axis0-histogram.wgsl.jinjascatter-elements-reduction-atomic.wgsl.jinjascatter-elements-reduction.wgsl.jinjascatter-elements.wgsl.jinjascatter-f16-f32-convert.wgsl.jinjascatter-flat-copy.wgsl.jinjascatter-narrow-wrap.wgsl.jinja
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.ScatterElements", { version: 1 });
const { output } = await kernel({
data: { data: dataData, shape: [3] },
indices: { data: indicesData, shape: [2] },
updates: { data: updatesData, shape: [2] },
});
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.