wgblas
    Preparing search index...

    Function dger

    • Performs the rank-1 update $$A \leftarrow \alpha x y^{T} + A$$ in double precision (double-double emulation — WGSL has no native f64 type).

      A is an m×n matrix stored in row-major order, updated in place. lda is the leading dimension (number of doubles between the start of consecutive rows — must be >= n).

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

      const device = await init();

      // Rank-1 update A = alpha*x*y^T + A. Starting from a zero A, every entry of the
      // result is just x[i]*y[j].
      const m = 2,
      n = 3,
      lda = n;
      const x = new Float64Array([1, 2]);
      const y = new Float64Array([10, 20, 30]);
      const A = new Float64Array(m * lda); // all zeros

      console.log("x =", x);
      console.log("y =", y);

      const { A: result } = await dger(device, m, n, 1, x, 1, y, 1, A, lda);
      console.log("A = x*y^T =");
      console.table([result.slice(0, 3), result.slice(3, 6)]); // [[10,20,30],[20,40,60]]

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

      Browser (standalone HTML):

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

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

      // A starts at zero, so every entry of the result is just x[i]*y[j].
      const m = 2, n = 3, lda = n;
      const x = new Float64Array([1, 2]);
      const y = new Float64Array([10, 20, 30]);
      const A = new Float64Array(m * lda);

      const { A: result } = await dger(device, m, n, 1, x, 1, y, 1, A, lda);

      document.getElementById("out").textContent = [
      "x = [" + [...x].join(", ") + "]",
      "y = [" + [...y].join(", ") + "]",
      "A = x*y^T =",
      " [" + [...result.subarray(0, 3)].join(", ") + "]",
      " [" + [...result.subarray(3, 6)].join(", ") + "]",
      ].join("\n");

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • m: number

        number of rows in A (length of x)

      • n: number

        number of columns in A (length of y)

      • alpha: number

        scalar multiplier for x*y^T

      • x: Float64Array

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

      • incx: number

        stride for x (must be a positive integer)

      • y: Float64Array

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

      • incy: number

        stride for y (must be a positive integer)

      • A: Float64Array

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

      • lda: number

        leading dimension of A (>= n for row-major, >= m for column-major)

      • Optionallayout: "column-major" | "row-major"

        storage layout of A (default: 'row-major')

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

    • Performs the rank-1 update $$A \leftarrow \alpha x y^{T} + A$$ in double precision (double-double emulation).

      x, y, and A are all 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 { dger } from "wgblas/dger";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";

      const device = await init();

      // A starts at zero, so every entry of the result is just x[i]*y[j].
      const m = 2,
      n = 3;
      const x = new Float64Array([1, 2]);
      const y = new Float64Array([10, 20, 30]);

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

      console.log("x =", x);
      console.log("y =", y);

      await dger(device, m, n, 1, xGpu, 1, yGpu, 1, AGpu, AGpu.lda);
      const result = await AGpu.read();
      console.log("A = x*y^T =");
      console.table([result.slice(0, 3), result.slice(3, 6)]); // [[10,20,30],[20,40,60]]

      xGpu.destroy();
      yGpu.destroy();
      AGpu.destroy();
      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • m: number

        number of rows in A

      • n: number

        number of columns in A

      • alpha: number

        scalar multiplier for x*y^T

      • x: GpuVector

        GpuVector input vector (Float64Array-backed, not mutated)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector input vector (Float64Array-backed, not mutated)

      • incy: number

        stride for y (must be a positive integer)

      • A: GpuMatrix

        GpuMatrix (Float64Array-backed), mutated in place

      • lda: number

        leading dimension of A (must equal A.lda)

      Returns Promise<{ gpuTimeMs?: number }>