wgblas
    Preparing search index...

    Function isamax

    • Returns the 0-based index of the element with the largest absolute value. Ties are broken in favour of the lower index, matching CBLAS behaviour.

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

      const device = await init();

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

      console.log("x: ", x);
      const { index } = await isamax(device, n, x, 1);
      console.log("index: ", index);
      console.log("x[index]: ", x[index]);
      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 vector

      • incx: number

        stride for x (must be a positive integer)

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

      0-based index of max |x[i]|

    • Returns the 0-based index of the element with the largest absolute value. Ties are broken in favour of the lower index, matching CBLAS behaviour.

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

      const device = await init();

      const n = 10;
      const scale = 2.0;
      const x = randomFloat32Array(n, -10, 10);

      const xGpu = GpuVector.from(x);

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

      await sscal(device, n, scale, xGpu, 1);
      const { index } = await isamax(device, n, xGpu, 1);
      console.log("index (of 2x): ", index);

      xGpu.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 vector

      • incx: number

        stride for x (must be a positive integer)

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

      0-based index of max |x[i]|