ai.onnx.Gather

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

Description

Gathers entries from data along the specified axis using an indices tensor, producing an output of rank q + (r - 1) where r is the rank of data and q is the rank of indices. Each index value selects a (r-1)-dimensional slice from data along axis, and the resulting slices are arranged into the output tensor with the q index dimensions replacing the gathered axis.

See the ONNX Gather spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
data data T Tensor of rank r >= 1 to gather entries from. required
indices indices I Integer index tensor of any rank q; each value must be in [-s, s-1] where s is the size of data along axis. required

Outputs

Name Bind key Logical dtype Rank Shape Description Presence
output output T derived derived; see description Output tensor of rank q + (r - 1) containing the gathered slices. required

Attributes

Default values (overridable per request):

Attribute Default Description
axis 0 Axis of data along which to gather; negative values count from the back. Accepted range is [-r, r-1] where r = rank(data).

Type constraints

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

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.Gather", { version: 1 });
const { output } = await kernel({
  data: { data: dataData, shape: [4] },
  indices: { data: indicesData, shape: [4] },
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.