ai.onnx.Compress

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

Description

Selects slices from the input tensor along an axis where the corresponding condition element is true. If axis is omitted, the input is flattened and elements are selected by position. The condition may be shorter than the selected dimension; values beyond its length are discarded. The data-dependent output extent must equal the number of true entries in the inspected prefix.

See the ONNX Compress spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
input input T Input tensor of rank r >= 1 to select from. required
condition condition C 1 Rank-1 boolean mask indicating which slices or elements to select; may be shorter than the axis dimension, in which case trailing slices are discarded. required

Outputs

Name Bind key Logical dtype Rank Shape Description Presence
output output T derived Selected slices with rank r when axis is specified, or rank 1 when the input is flattened. The selected dimension equals the number of true values in the inspected condition prefix. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
axis Axis along which to select slices; if omitted the input is flattened before selection. Negative values index from the end; accepted range is [-r, r-1].

Type constraints

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

Files

Use with @huggingface/kernels

The loader automatically allocates outputs whose metadata it can derive from the manifest contract and this call.

The explicit outputs entries provide shape and logical dtype metadata for the results listed below:

  • output

Each entry either requests an optional result or supplies metadata that cannot be inferred from the inputs.

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.Compress", { version: 1 });
// Explicit destinations request optional results or supply metadata that cannot be inferred.
const { output } = await kernel({
  input: { data: inputData, shape: [3, 2] },
  condition: { data: conditionData, shape: [5] },
}, {
  outputs: { output: { shape: [2], dtype: "float32" } },
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.