Skip to content

compute.kernels.min

Summary

compute.kernels.min reduces a non-empty real GPU ndarray to its smallest value. It keeps the result on the device as a scalar of the input dtype. Use compute.ndarray.min when reducing selected axes or comparing f64 values.

Syntax

min(a: GPUndarray, opts?: KernelOutputOptions): GPUndarray
const low = kernels.min(a);

Parameters

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

Returns

GPUndarray - Scalar of shape [] and the input dtype. NaN propagates and negative zero is ordered below positive zero. Empty input throws.

Example

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

See Also