compute.ndarray.min¶
Summary¶
compute.ndarray.min finds the smallest value along selected axes. Use compute.ndarray.max for the largest. Both preserve the real input dtype, including when comparing f64 values on the GPU.
Syntax¶
min<T extends CPUndarray | GPUndarray>(a: T, options?: NdarrayReduceOptions): T
max<T extends CPUndarray | GPUndarray>(a: T, options?: NdarrayReduceOptions): T
const lows = nd.min(a, { axes: -1 });
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
a |
CPUndarray | GPUndarray |
Yes | Live array of real values. For complex arrays, select a real or imaginary component view first. |
options |
NdarrayReduceOptions |
No | axes defaults to all axes, keepDims to false, and nan to "propagate". Use the shared GPU options when reducing GPU arrays. The methods require the input dtype and reject dtype and overflow overrides. |
Returns¶
T - Packed extrema in the source dtype and residency. A slice with zero elements throws if an output value is required. A slice containing only skipped NaNs returns NaN.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const nd = wgpu.compute.ndarray;
const a = nd.fromArray("f32", [2, 3], [4, 2, 8, 5, 7, 1]);
const lows = nd.min(a, { axes: 1 });
console.log(lows.data()); // [2, 1]
lows.destroy();
a.destroy();
Notes¶
Use nan: "omit" to ignore NaNs. For floating input, negative zero compares lower in a minimum and positive zero compares higher in a maximum. Axis handling, limits and GPU encoder behavior follow compute.ndarray.sum.