wgblas
    Preparing search index...

    Function srotm

    • Applies a modified Givens plane rotation H to vectors x and y: x = H[0][0]*x + H[0][1]*y y = H[1][0]*x + H[1][1]*y

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

      const device = await init();

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

      // flag = -1: full 2x2 matrix H
      // H = [ h11 h12 ] = [ 0.6 0.8 ]
      // [ h21 h22 ] [-0.8 0.6 ]
      const param = new Float32Array([-1, 0.6, -0.8, 0.8, 0.6]);

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

      const { x: xOut, y: yOut } = await srotm(device, n, x, 1, y, 1, param);

      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)

      • param: Float32Array

        5-element Float32Array: [flag, h11, h21, h12, h22] flag = -2: identity (no-op), -1: full H, 0: unit diagonal, 1: unit off-diagonal

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

    • Applies a modified Givens plane rotation H to vectors x and y: x = H[0][0]*x + H[0][1]*y y = H[1][0]*x + H[1][1]*y

      import { init, cleanup } from "wgblas";
      import { srotm } from "wgblas/srotm";
      import { saxpy } from "wgblas/saxpy";
      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);

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

      // flag = 0: unit diagonal — H = [ 1 h12 ]
      // [ h21 1 ]
      const param = new Float32Array([0, 1, -0.5, 0.5, 1]);

      // shift y by adding 2*x on GPU, then apply modified rotation
      await saxpy(device, n, 2.0, xGpu, 1, yGpu, 1);
      await srotm(device, n, xGpu, 1, yGpu, 1, param);

      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)

      • param: Float32Array

        5-element Float32Array: [flag, h11, h21, h12, h22] flag = -2: identity (no-op), -1: full H, 0: unit diagonal, 1: unit off-diagonal

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