Skip to content

compute.kernels.luFactor

Summary

compute.kernels.luFactor factors square GPU matrices with partial pivoting. It packs lower and upper factors together and returns the zero-based pivot rows separately. Keep both outputs to solve multiple systems with the same coefficients.

Syntax

luFactor(a: GPUndarray, opts?: LuFactorOptions): LuFactorResult
const { lu, ipiv } = kernels.luFactor(a);

Parameters

Name Type Required Description
a GPUndarray Yes f32 or c64 array of shape [...batch, n, n]. Each leading coordinate identifies an independent matrix.
opts LuFactorOptions No Overwrite policy, optional pivots storage and kernel output and dispatch settings.

Returns

LuFactorResult - lu has the input dtype and shape, with lower-triangular multipliers below the diagonal and the upper factor on and above it. The lower diagonal is implicitly one. ipiv is u32 of shape [...batch, n]. Pivot i gives the zero-based row swapped with row i at that step.

Type Details

type LuFactorOptions = KernelOutputOptions & {
    overwrite?: boolean;
    ipiv?: GPUndarray;
};
type LuFactorResult = { lu: GPUndarray; ipiv: GPUndarray };

By default the input remains intact with separate outputs. With overwrite: true, the call returns a as lu and writes through its layout. Each input element must have a distinct address, and out must be omitted. A supplied ipiv must be C-contiguous and its range must be disjoint from lu.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const a = nd.fromArray("f32", [2, 2], [0, 1, 2, 3], { residency: "gpu" });
const { lu, ipiv } = kernels.luFactor(a);
const pivots = await nd.toCPU(ipiv);
console.log(pivots.data()); // [1, 1]
for (const array of [pivots, ipiv, lu, a]) array.destroy();

Notes

Supply nonsingular matrices. A zero pivot can lead to non-finite values, and the call returns no singularity status.

See Also