wgblas
    Preparing search index...

    Function sdot

    • Computes the dot product of two vectors: result = sum(x[i] * y[i])

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

      const device = await init();

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

      console.log("x: ", x);
      console.log("y: ", y);
      const { dot } = await sdot(device, n, x, 1, y, 1);
      console.log("dot: ", dot);
      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)

      • y: Float32Array

        Float32Array input vector

      • incy: number

        stride for y (must be a positive integer)

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

      dot product scalar — always a CPU readback, even for GpuVector inputs

    • Computes the dot product of two vectors: result = sum(x[i] * y[i])

      import { init, cleanup } from "wgblas";
      import { sdot } from "wgblas/sdot";
      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 y = randomFloat32Array(n, -10, 10);

      const xGpu = GpuVector.from(x);
      const yGpu = GpuVector.from(y);

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

      await sscal(device, n, scale, xGpu, 1);
      const { dot } = await sdot(device, n, xGpu, 1, yGpu, 1);
      console.log("dot: ", dot);

      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 vector

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector input vector

      • incy: number

        stride for y (must be a positive integer)

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

      dot product scalar — always a CPU readback, even for GpuVector inputs