Skip to content

compute.kernels.argmin

Summary

compute.kernels.argmin returns a device-resident index into a non-empty f32 GPU ndarray. It skips NaNs and uses the first minimum in logical C order, including when the input is a view. Use compute.ndarray.argmin to select along an axis.

Syntax

argmin(a: GPUndarray, opts?: KernelOutputOptions): GPUndarray
const index = kernels.argmin(a);

Parameters

Name Type Required Description
a GPUndarray Yes Non-empty f32 array of any supported shape and layout.
opts KernelOutputOptions No Kernel output and dispatch settings.

Returns

GPUndarray - One u32 at shape []. The index follows logical C order and picks the first occurrence on ties, including signed zero. All-NaN input gives 0xffffffff. Empty input throws.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const a = nd.fromArray("f32", [2, 2], [NaN, 3, -1, -1], { residency: "gpu" });
const index = kernels.argmin(a);
const cpu = await nd.toCPU(index);
console.log(cpu.get()); // 2
cpu.destroy();
index.destroy();
a.destroy();

See Also