compute.kernels.luSolve¶
Summary¶
compute.kernels.luSolve applies precomputed LU factors and pivots to one right-hand-side vector per matrix. The leading batch dimensions must match. Reuse the factorization when the coefficients stay fixed and the right-hand side changes.
Syntax¶
luSolve(lu: GPUndarray, ipiv: GPUndarray, b: GPUndarray, opts?: LuSolveOptions): GPUndarray
const x = kernels.luSolve(lu, ipiv, b);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
lu |
GPUndarray |
Yes | Factored f32 or c64 matrices of shape [...batch, n, n]. |
ipiv |
GPUndarray |
Yes | Corresponding zero-based u32 pivots of shape [...batch, n]. Use the pivot array returned with lu. |
b |
GPUndarray |
Yes | Right-hand sides with the same dtype as lu and shape [...batch, n]. Batch axes must match exactly. |
opts |
LuSolveOptions |
No | Alias for KernelOutputOptions. |
Returns¶
GPUndarray - Solution with the shape and dtype of b. Use out: b to replace a C-contiguous right-hand side.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const a = nd.fromArray("f32", [2, 2], [2, 0, 0, 4], { residency: "gpu" });
const b = nd.fromArray("f32", [2], [6, 8], { residency: "gpu" });
const { lu, ipiv } = kernels.luFactor(a);
const x = kernels.luSolve(lu, ipiv, b);
const cpu = await nd.toCPU(x);
console.log(cpu.data()); // [3, 2]
for (const array of [cpu, x, ipiv, lu, b, a]) array.destroy();
Notes¶
Use factors from a nonsingular matrix. A zero diagonal in the upper factor can produce non-finite results.