GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
'no-transpose' to solve Ax=b, 'transpose' to solve A^Tx=b
'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
order of the matrix A (number of rows and columns)
Float32Array, row-major or column-major (see layout), at least (n-1)*lda+n elements
leading dimension of A (>= n either way — A is square)
Float32Array holding b on input, the solution on output; length at least (n-1)*incx+1
stride for x (must be a positive integer)
Optionallayout: "column-major" | "row-major"storage layout of A (default: 'row-major'); column-major
flips both the stored triangle and the effective trans (the system
being solved stays what you asked for either way)
Solves the triangular system op(A) * x = b for x, in place.
A is kept GPU-resident; x is a CPU Float32Array. A's own layout (set at
GpuMatrix.from time) determines the operation — there is no separate
layout argument here.
GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
'no-transpose' to solve Ax=b, 'transpose' to solve A^Tx=b
'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
order of the matrix A
GpuMatrix, GPU-resident
leading dimension of A (must equal A.lda)
Float32Array holding b on input, the solution on output
stride for x (must be a positive integer)
Solves the triangular system op(A) * x = b for x, in place.
x is kept resident on the GPU (mutated in place). A must be a GpuMatrix;
its own layout (set at GpuMatrix.from time) determines the operation —
there is no separate layout argument here.
import { init, cleanup } from "wgblas";
import { strsv } from "wgblas/strsv";
import { GpuVector } from "wgblas/classes/GpuVector";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
import { randomFloat32Array, randomTriangularFloat32Array } from "wgblas/random";
const device = await init();
const n = 4;
const A = randomTriangularFloat32Array(n, n, "lower", -10, 10);
const b = randomFloat32Array(n, -10, 10);
const AGpu = GpuMatrix.from(A, n, n, n, "row-major");
const xGpu = GpuVector.from(Float32Array.from(b));
console.log("A (lower triangle):", A);
console.log("b:", b);
// x is mutated in place on the GPU: holds b on input, the solution on output
await strsv(device, "lower", "no-transpose", "non-unit", n, AGpu, AGpu.lda, xGpu, 1);
// single readback
const result = await xGpu.read();
console.log("x (solves A*x = b):", result);
AGpu.destroy();
xGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
'no-transpose' to solve Ax=b, 'transpose' to solve A^Tx=b
'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
order of the matrix A
GpuMatrix, GPU-resident
leading dimension of A (must equal A.lda)
GpuVector holding b on input, the solution on output (mutated in place)
stride for x (must be a positive integer)
Solves the triangular system op(A) * x = b for x, in place (x holds b on input, the solution on output).
A is an n×n triangular matrix stored in row-major order. Only the triangle specified by
uplois referenced; the other triangle is not accessed.Browser (standalone HTML):