wgblas
    Preparing search index...

    Function drot

    • Applies a Givens plane rotation to double-precision vectors x and y: $$\begin{aligned} x &\leftarrow cx + sy \\ y &\leftarrow -sx + cy \end{aligned}$$ — double-double (Dekker) f64 emulation of srot, since WGSL has no native f64 type.

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

      const device = await init();

      const n = 5;
      const x = new Float64Array([1, 2, 3, 4, 5]);
      const y = new Float64Array([10, 20, 30, 40, 50]);

      // c = 0, s = 1: a clean 90-degree rotation, so x' = y and y' = -x.
      const c = 0;
      const s = 1;

      console.log("x (before):", x);
      console.log("y (before):", y);

      const { x: xOut, y: yOut } = await drot(device, n, x, 1, y, 1, c, s);

      console.log("x (after): ", xOut);
      console.log("y (after): ", yOut);

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

      Browser (standalone HTML):

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

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

      const n = 5;
      const x = new Float64Array([1, 2, 3, 4, 5]);
      const y = new Float64Array([10, 20, 30, 40, 50]);

      // c = 0, s = 1: a clean 90-degree rotation, so x' = y and y' = -x.
      const c = 0;
      const s = 1;

      const xBefore = Array.from(x).map(v => v.toFixed(4)).join(", ");
      const yBefore = Array.from(y).map(v => v.toFixed(4)).join(", ");

      const { x: xOut, y: yOut } = await drot(device, n, x, 1, y, 1, c, s);

      document.getElementById("out").textContent =
      "x (before): " + xBefore +
      "\ny (before): " + yBefore +
      "\nx (after): " + Array.from(xOut).map(v => v.toFixed(4)).join(", ") +
      "\ny (after): " + Array.from(yOut).map(v => v.toFixed(4)).join(", ");

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: Float64Array

        Float64Array input/output vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float64Array

        Float64Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

      • c: number

        cosine of rotation angle

      • s: number

        sine of rotation angle

      Returns Promise<
          | { x: Float64Array; y: Float64Array }
          | { gpuTimeMs: number; x: Float64Array; y: Float64Array },
      >

    • Applies a Givens plane rotation to double-precision vectors x and y: $$\begin{aligned} x &\leftarrow cx + sy \\ y &\leftarrow -sx + cy \end{aligned}$$ — GPU-resident overload; see the Float64Array overload above for the routine itself.

      import { init, cleanup } from "wgblas";
      import { drot } from "wgblas/drot";
      import { dscal } from "wgblas/dscal";
      import { GpuVector } from "wgblas/classes/GpuVector";

      const device = await init();

      const n = 5;
      const xCpu = new Float64Array([1, 2, 3, 4, 5]);
      const yCpu = new Float64Array([10, 20, 30, 40, 50]);

      const xGpu = GpuVector.from(xCpu);
      const yGpu = GpuVector.from(yCpu);

      // c = 0, s = 1: a clean 90-degree rotation, so x' = y and y' = -x.
      const c = 0;
      const s = 1;

      console.log("x (cpu): ", xCpu);
      console.log("y (cpu): ", yCpu);

      // scale x by 2 on GPU, then rotate both vectors
      await dscal(device, n, 2.0, xGpu, 1);
      await drot(device, n, xGpu, 1, yGpu, 1, c, s);

      console.log("x (after): ", await xGpu.read());
      console.log("y (after): ", await yGpu.read());

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

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: GpuVector

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

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

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

      • incy: number

        stride for y (must be a positive integer)

      • c: number

        cosine of rotation angle

      • s: number

        sine of rotation angle

      Returns Promise<{} | { gpuTimeMs: number }>