wgblas
    Preparing search index...

    Function srot

    • Applies a Givens plane rotation to vectors x and y: x = cx + sy y = -sx + cy

      import { init, cleanup } from "wgblas";
      import { srot } from "wgblas/srot";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      const n = 10;
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(n, -10, 10);

      // 45-degree rotation: c = cos(π/4), s = sin(π/4)
      const angle = Math.PI / 4;
      const c = Math.cos(angle);
      const s = Math.sin(angle);

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

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

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

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: Float32Array

        Float32Array input/output vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float32Array

        Float32Array 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: Float32Array; y: Float32Array }
          | { gpuTimeMs: number; x: Float32Array; y: Float32Array },
      >

    • Applies a Givens plane rotation to vectors x and y: x = cx + sy y = -sx + cy

      import { init, cleanup } from "wgblas";
      import { srot } from "wgblas/srot";
      import { sscal } from "wgblas/sscal";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      const n = 10;
      const xCpu = randomFloat32Array(n, -10, 10);
      const yCpu = randomFloat32Array(n, -10, 10);

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

      // 45-degree rotation
      const c = Math.cos(Math.PI / 4);
      const s = Math.sin(Math.PI / 4);

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

      // scale x by 2 on GPU, then rotate both vectors
      await sscal(device, n, 2.0, xGpu, 1);
      await srot(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 (mutated in place)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector input/output vector (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 }>