wgblas
    Preparing search index...

    Function dsymv

    • Performs the symmetric matrix-vector operation $$y \leftarrow \alpha A x + \beta y$$ in double precision (double-double emulation — WGSL has no native f64 type).

      A is an n×n symmetric matrix stored in row-major order. Only the triangle specified by uplo is referenced; the other triangle is inferred by symmetry.

      import { init, cleanup } from "wgblas";
      import { dsymv } from "wgblas/dsymv";

      const device = await init();

      // y = alpha*A*x + beta*y, A symmetric. Only the upper triangle is read, so the
      // zeros below the diagonal stand for the mirrored values.
      const n = 3,
      lda = n;
      const A = new Float64Array([2, 1, 0, 0, 2, 1, 0, 0, 2]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0, 0]);

      console.log("A (upper triangle stored) =");
      console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
      console.log("x =", x);

      const { y: result } = await dsymv(device, "upper", n, 1, A, lda, x, 1, 0, y, 1);
      // Implied full matrix is [[2,1,0],[1,2,1],[0,1,2]] -> row sums [3, 4, 3]
      console.log("y = A*x =", result);

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

      Browser (standalone HTML):

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

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

      // Only the upper triangle is read; the zeros below stand for the mirrored 1s.
      const n = 3, lda = n;
      const A = new Float64Array([2, 1, 0,
      0, 2, 1,
      0, 0, 2]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0, 0]);

      const { y: result } = await dsymv(device, "upper", n, 1, A, lda, x, 1, 0, y, 1);

      document.getElementById("out").textContent = [
      "A (upper triangle stored) =",
      " [" + [...A.subarray(0, 3)].join(", ") + "]",
      " [" + [...A.subarray(3, 6)].join(", ") + "]",
      " [" + [...A.subarray(6, 9)].join(", ") + "]",
      "x = [" + [...x].join(", ") + "]",
      "y = A*x = [" + [...result].join(", ") + "] // implied A = [[2,1,0],[1,2,1],[0,1,2]]",
      ].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

      • n: number

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

      • alpha: number

        scalar multiplier for A*x

      • 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)

      • beta: number

        scalar multiplier for y

      • y: Float64Array

        Float64Array input/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'); for a symmetric matrix, column-major storage just means the other triangle is the one physically referenced for a given uplo

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

    • Performs the symmetric matrix-vector operation $$y \leftarrow \alpha A x + \beta y$$ 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 { dsymv } from "wgblas/dsymv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";

      const device = await init();

      // Only the upper triangle is read; the zeros below stand for the mirrored 1s.
      const n = 3;
      const A = new Float64Array([2, 1, 0, 0, 2, 1, 0, 0, 2]);
      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 (upper triangle stored) =");
      console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
      console.log("x =", x);

      await dsymv(device, "upper", n, 1, AGpu, AGpu.lda, xGpu, 1, 0, yGpu, 1);
      // Implied full matrix [[2,1,0],[1,2,1],[0,1,2]] -> row sums
      console.log("y = A*x =", await yGpu.read()); // [3, 4, 3]

      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

      • n: number

        order of the matrix A

      • alpha: number

        scalar multiplier for A*x

      • 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)

      • beta: number

        scalar multiplier for y

      • y: GpuVector

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

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>