GPUDevice from init()
number of elements to scale (must be a positive integer)
scalar multiplier
Float32Array input/output vector
stride for x (must be a positive integer)
Scales a single-precision vector by a constant: x = alpha * x
import { init, cleanup } from "wgblas";
import { sscal } from "wgblas/sscal";
import { saxpy } from "wgblas/saxpy";
import { GpuVector } from "wgblas/classes/GpuVector";
import { randomFloat32Array } from "wgblas/random";
const device = await init();
const n = 10;
const alpha = 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, alpha, xGpu, 1);
await saxpy(device, n, 1.0, xGpu, 1, yGpu, 1);
const result = await yGpu.read();
console.log("result (2x + y):", result);
xGpu.destroy();
yGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
number of elements to scale (must be a positive integer)
scalar multiplier
GpuVector input/output vector (mutated in place)
stride for x (must be a positive integer)
Scales a single-precision vector by a constant: x = alpha * x