wgblas
    Preparing search index...

    Function dtrsv

    • Solves the triangular system for $x$, in place — x holds b on input, the solution on output, in double precision (double-double emulation — WGSL has no native f64 type): $$\mathrm{op}(A) x = b$$

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

      const device = await init();

      // Solves A*x = b in place: x holds b going in, the solution coming out.
      // Same A and b as the dtrmv example, so this undoes that multiply.
      const n = 3,
      lda = n;
      const A = new Float64Array([2, 0, 0, 3, 4, 0, 5, 6, 8]);
      const x = new Float64Array([2, 7, 19]); // b

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

      const { x: result } = await dtrsv(
      device,
      "lower",
      "no-transpose",
      "non-unit",
      n,
      A,
      lda,
      x,
      1,
      );
      console.log("x (solves A*x = b) =", result); // [1, 1, 1]

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

      Browser (standalone HTML):

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

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

      // Solves A*x = b in place: x holds b going in, the solution coming out.
      const n = 3, lda = n;
      const A = new Float64Array([2, 0, 0,
      3, 4, 0,
      5, 6, 8]);
      const x = new Float64Array([2, 7, 19]); // b

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

      document.getElementById("out").textContent = [
      "A (lower triangular) =",
      " [" + [...A.subarray(0, 3)].join(", ") + "]",
      " [" + [...A.subarray(3, 6)].join(", ") + "]",
      " [" + [...A.subarray(6, 9)].join(", ") + "]",
      "b = [2, 7, 19]",
      "x (solves A*x = b) = [" + [...result].join(", ") + "]",
      ].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' to solve Ax=b, 'transpose' to solve A^Tx=b

      • 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 holding b on input, the solution on output; length at least (n-1)*incx+1

      • incx: number

        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)

      Returns Promise<{ gpuTimeMs?: number; x: Float64Array }>

    • Solves the triangular system for $x$, in place, in double precision (double-double emulation): $$\mathrm{op}(A) x = b$$

      x is kept resident on the GPU (mutated in place). 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 { dtrsv } from "wgblas/dtrsv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";

      const device = await init();

      // Solves A*x = b in place on the GPU: xGpu holds b going in, the solution out.
      const n = 3;
      const A = new Float64Array([2, 0, 0, 3, 4, 0, 5, 6, 8]);
      const b = new Float64Array([2, 7, 19]);

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

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

      await dtrsv(
      device,
      "lower",
      "no-transpose",
      "non-unit",
      n,
      AGpu,
      AGpu.lda,
      xGpu,
      1,
      );
      console.log("x (solves A*x = b) =", await xGpu.read()); // [1, 1, 1]

      AGpu.destroy();
      xGpu.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' to solve Ax=b, 'transpose' to solve A^Tx=b

      • 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 (Float64Array-backed) holding b on input, the solution on output (mutated in place)

      • incx: number

        stride for x (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>