wgblas
    Preparing search index...

    Function dtrmv

    • Performs the triangular matrix-vector operation $$y \leftarrow \mathrm{op}(A) x$$ in double precision (double-double emulation — WGSL has no native f64 type).

      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 { dtrmv } from "wgblas/dtrmv";

      const device = await init();

      // y = op(A)*x with A lower triangular. Entries above the diagonal are ignored.
      const n = 3,
      lda = n;
      const A = new Float64Array([2, 0, 0, 3, 4, 0, 5, 6, 8]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0, 0]);

      console.log("A (lower triangular) =");
      console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
      console.log("x =", x);

      const { y: result } = await dtrmv(
      device,
      "lower",
      "no-transpose",
      "non-unit",
      n,
      A,
      lda,
      x,
      1,
      y,
      1,
      );
      console.log("y = A*x =", result); // row sums: [2, 3+4, 5+6+8] = [2, 7, 19]

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

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>dtrmv — 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, dtrmv, cleanup } = window.wgblas;

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

      // Lower triangular; entries above the diagonal are ignored.
      const n = 3, lda = n;
      const A = new Float64Array([2, 0, 0,
      3, 4, 0,
      5, 6, 8]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0, 0]);

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

      document.getElementById("out").textContent = [
      "A (lower triangular) =",
      " [" + [...A.subarray(0, 3)].join(", ") + "]",
      " [" + [...A.subarray(3, 6)].join(", ") + "]",
      " [" + [...A.subarray(6, 9)].join(", ") + "]",
      "x = [" + [...x].join(", ") + "]",
      "y = A*x = [" + [...result].join(", ") + "] // 2, 3+4, 5+6+8",
      ].join("\n");

      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: Float64Array

        Float64Array, 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: Float64Array

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

      • incx: number

        stride for x (must be a positive integer)

      • y: Float64Array

        Float64Array 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: Float64Array }>

    • Performs the triangular matrix-vector operation $$y \leftarrow \mathrm{op}(A) x$$ in double precision (double-double emulation).

      x and y are kept resident on the GPU. A must be a GpuMatrix (Float64Array- backed); its own layout (set at GpuMatrix.from time) determines the operation — there is no separate layout argument here.

      import { init, cleanup } from "wgblas";
      import { dtrmv } from "wgblas/dtrmv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";

      const device = await init();

      // Lower triangular; entries above the diagonal are ignored.
      const n = 3;
      const A = new Float64Array([2, 0, 0, 3, 4, 0, 5, 6, 8]);
      const x = new Float64Array([1, 1, 1]);

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

      console.log("A (lower triangular) =");
      console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
      console.log("x =", x);

      await dtrmv(
      device,
      "lower",
      "no-transpose",
      "non-unit",
      n,
      AGpu,
      AGpu.lda,
      xGpu,
      1,
      yGpu,
      1,
      );
      console.log("y = A*x =", await yGpu.read()); // [2, 3+4, 5+6+8] = [2, 7, 19]

      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 (Float64Array-backed), GPU-resident

      • lda: number

        leading dimension of A (must equal A.lda)

      • x: GpuVector

        GpuVector input vector (Float64Array-backed, not mutated)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector output vector (Float64Array-backed, mutated in place)

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>