GPUDevice from init()
number of elements to swap (must be a positive integer)
Float64Array first input/output vector
stride for x (must be a positive integer)
Float64Array second input/output vector
stride for y (must be a positive integer)
Swaps the elements of two double-precision vectors: $$x \leftrightarrow y$$ — GPU-resident overload; see the Float64Array overload above for the routine itself.
Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
import { init, cleanup } from "wgblas";
import { dswap } from "wgblas/dswap";
import { dscal } from "wgblas/dscal";
import { GpuVector } from "wgblas/classes/GpuVector";
const device = await init();
const n = 5;
const alpha = 2.0;
const x = new Float64Array([1, 2, 3, 4, 5]);
const y = new Float64Array([10, 20, 30, 40, 50]);
const xGpu = GpuVector.from(x);
const yGpu = GpuVector.from(y);
console.log("x: ", x);
console.log("y: ", y);
await dswap(device, n, xGpu, 1, yGpu, 1);
await dscal(device, n, alpha, xGpu, 1);
// single readback
const resultX = await xGpu.read();
const resultY = await yGpu.read();
console.log("x (2 * orig y): ", resultX);
console.log("y (orig x): ", resultY);
xGpu.destroy();
yGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
number of elements to swap (must be a positive integer)
GpuVector first input/output vector (must be Float64Array-backed, mutated in place)
stride for x (must be a positive integer)
GpuVector second input/output vector (must be Float64Array-backed, mutated in place)
stride for y (must be a positive integer)
Swaps the elements of two double-precision vectors: $$x \leftrightarrow y$$ — double-double (Dekker) f64 emulation of sswap, since WGSL has no native f64 type.
Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
Browser (standalone HTML):