wgblas
    Preparing search index...

    Function strmv

    • Performs the triangular matrix-vector operation y = op(A) * x

      A is an n×n triangular matrix stored in row-major order. Only the triangle specified by uplo is referenced; the other triangle is not accessed.

      import { init, cleanup } from "wgblas";
      import { strmv } from "wgblas/strmv";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      // 4×4 triangular matrix, lower triangular storage; lda = n
      const n = 4, lda = n;
      const A = randomFloat32Array(n * lda, -10, 10); // only lower triangle is read
      const x = randomFloat32Array(n, -10, 10);
      const y = new Float32Array(n);

      console.log("A (lower triangle):", A);
      console.log("x:", x);
      const { y: result } = await strmv(device, "lower", "no-transpose", "non-unit", n, A, lda, x, 1, y, 1, "row-major");
      console.log("y:", result);
      if (typeof process !== "undefined") cleanup();

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>strmv — wgblas browser example</title>
      <script src="https://unpkg.com/wgblas/dist/wgblas.browser.js"></script>
      </head>
      <body>
      <pre id="out">Running…</pre>
      <script>
      const { init, strmv, randomFloat32Array, cleanup } = window.wgblas;

      (async () => {
      const device = await init();

      const n = 4, lda = n;
      const A = randomFloat32Array(n * lda, -10, 10); // only lower triangle is read
      const x = randomFloat32Array(n, -10, 10);
      const y = new Float32Array(n);

      const { y: result } = await strmv(device, "lower", "no-transpose", "non-unit", n, A, lda, x, 1, y, 1, "row-major");

      document.getElementById("out").textContent =
      "A (lower triangle): " + Array.from(A).map(v => v.toFixed(4)).join(", ") +
      "\nx: " + Array.from(x).map(v => v.toFixed(4)).join(", ") +
      "\ny: " + Array.from(result).map(v => v.toFixed(4)).join(", ");

      cleanup();
      })();
      </script>
      </body>
      </html>

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • uplo: "lower" | "upper"

        'lower' to use the lower triangle, 'upper' to use the upper triangle

      • trans: "no-transpose" | "transpose"

        'no-transpose' for A, 'transpose' for A^T

      • diag: "unit" | "non-unit"

        'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it

      • n: number

        order of the matrix A (number of rows and columns)

      • A: Float32Array

        Float32Array, row-major or column-major (see layout), at least (n-1)*lda+n elements

      • lda: number

        leading dimension of A (>= n either way — A is square)

      • x: Float32Array

        Float32Array input vector, length at least (n-1)*incx+1

      • incx: number

        stride for x (must be a positive integer)

      • y: Float32Array

        Float32Array output vector, length at least (n-1)*incy+1

      • incy: number

        stride for y (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 (op(A) stays what you asked for either way)

      Returns Promise<{ gpuTimeMs?: number; y: Float32Array }>

    • Performs the triangular matrix-vector operation y = op(A) * x

      A is kept GPU-resident; x and y are CPU Float32Arrays. A's own layout (set at GpuMatrix.from time) determines the operation — there is no separate layout argument here.

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • uplo: "lower" | "upper"

        'lower' to use the lower triangle, 'upper' to use the upper triangle

      • trans: "no-transpose" | "transpose"

        'no-transpose' for A, 'transpose' for A^T

      • diag: "unit" | "non-unit"

        'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it

      • n: number

        order of the matrix A

      • A: GpuMatrix

        GpuMatrix, GPU-resident

      • lda: number

        leading dimension of A (must equal A.lda)

      • x: Float32Array

        Float32Array input vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float32Array

        Float32Array output vector

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number; y: Float32Array }>

    • Performs the triangular matrix-vector operation y = op(A) * x

      x and y are kept resident on the GPU. 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 { strmv } from "wgblas/strmv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      const n = 4;
      const A = randomFloat32Array(n * n, -10, 10); // lower triangle is the stored triangle
      const x = randomFloat32Array(n, -10, 10);
      const y = new Float32Array(n);

      const AGpu = GpuMatrix.from(A, n, n, n, "row-major");
      const xGpu = GpuVector.from(x);
      const yGpu = GpuVector.from(y);

      console.log("A (lower triangle):", A);
      console.log("x:", x);

      // results stay on the GPU between steps
      await strmv(device, "lower", "no-transpose", "non-unit", n, AGpu, AGpu.lda, xGpu, 1, yGpu, 1); // y = A*x
      await strmv(device, "lower", "no-transpose", "non-unit", n, AGpu, AGpu.lda, yGpu, 1, xGpu, 1); // x = A*y = A²*x

      // single readback
      const result = await xGpu.read();
      console.log("A²x:", result);

      AGpu.destroy();
      xGpu.destroy();
      yGpu.destroy();

      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • uplo: "lower" | "upper"

        'lower' to use the lower triangle, 'upper' to use the upper triangle

      • trans: "no-transpose" | "transpose"

        'no-transpose' for A, 'transpose' for A^T

      • diag: "unit" | "non-unit"

        'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it

      • n: number

        order of the matrix A

      • A: GpuMatrix

        GpuMatrix, GPU-resident

      • lda: number

        leading dimension of A (must equal A.lda)

      • x: GpuVector

        GpuVector input vector (not mutated)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector output vector (mutated in place)

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>