GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
order of the matrix A (number of rows and columns)
scalar multiplier for x*x^T
Float32Array input vector, length at least (n-1)*incx+1
stride for x (must be a positive integer)
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)
Optionallayout: "column-major" | "row-major"
storage layout of A (default: 'row-major'); for a symmetric
matrix, column-major storage just means the other triangle is the one
physically referenced for a given uplo
Performs the symmetric rank-1 update $$A \leftarrow \alpha x x^{T} + A$$
x and A are both kept resident on the GPU. A's own layout (set at
GpuMatrix.from time) determines the operation — there is no separate
layout argument here.
import { init, cleanup } from "wgblas";
import { ssyr } from "wgblas/ssyr";
import { GpuVector } from "wgblas/classes/GpuVector";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
const device = await init();
// Only the upper triangle is written: entry (i,j) for j >= i is x[i]*x[j].
const n = 3;
const x = new Float32Array([1, 2, 3]);
const xGpu = GpuVector.from(x);
const AGpu = GpuMatrix.from(new Float32Array(n * n), n, n, n, "row-major");
console.log("x =", x);
await ssyr(device, "upper", n, 1, xGpu, 1, AGpu, AGpu.lda);
const result = await AGpu.read();
console.log("A = x*x^T (upper triangle) =");
console.table([result.slice(0, 3), result.slice(3, 6), result.slice(6, 9)]); // [[1,2,3],[0,4,6],[0,0,9]]
xGpu.destroy();
AGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
order of the matrix A
scalar multiplier for x*x^T
GpuVector input vector (not mutated)
stride for x (must be a positive integer)
GpuMatrix, mutated in place
leading dimension of A (must equal A.lda)
Performs the symmetric rank-1 update $$A \leftarrow \alpha x x^{T} + A$$
A is an n×n symmetric matrix stored in row-major order, updated in place. Only the triangle specified by
uplois referenced and updated; the other triangle is left untouched (implied by symmetry).Browser (standalone HTML):