GPUDevice from init()
number of elements (must be a positive integer)
Float64Array input vector
stride for x (must be a positive integer)
Float64Array input vector
stride for y (must be a positive integer)
dot product scalar — always a CPU readback, even for GpuVector inputs
Computes the dot product of two vectors of doubles in extended precision:
$$\text{result} = \sum_{i} x_i y_i$$
Accumulation uses Dekker's double-double algorithm (see shaders/f64/),
giving ~48 bits of mantissa.
import { init, cleanup } from "wgblas";
import { ddot } from "wgblas/ddot";
import { GpuVector } from "wgblas/classes/GpuVector";
const device = await init();
const n = 5;
const x = new Float64Array([1, 1e-9, 2, 3, 4]);
const y = new Float64Array([1, 1, 1, 1, 1]);
const xGpu = GpuVector.from(x);
const yGpu = GpuVector.from(y);
console.log("x: ", x);
console.log("y: ", y);
const { dot } = await ddot(device, n, xGpu, 1, yGpu, 1);
console.log("dot: ", dot); // 10.000000001, not 10
xGpu.destroy();
yGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
number of elements (must be a positive integer)
Float64Array-backed GpuVector input vector
stride for x (must be a positive integer)
Float64Array-backed GpuVector input vector
stride for y (must be a positive integer)
dot product scalar — always a CPU readback, even for GpuVector inputs
Computes the dot product of two vectors of doubles in extended precision: $$\text{result} = \sum_{i} x_i y_i$$ Each element of
xandyis split into a (hi, lo) double-double f32 pair (seesplitDoubleDouble/f64.mjs) since WGSL has no f64 type; the elementwise products and their accumulation both use Dekker's double-double algorithm (seeshaders/f64/), giving ~48 bits of mantissa — more than a single f32 (24 bits) but less than true f64 (52 bits), so results are not bit-exact with a CPU double.Browser (standalone HTML):