wgblas
    Preparing search index...

    Function dasum

    • Computes the sum of absolute values of a vector of doubles in extended precision: result = sum(|x[i]|). Each element of x has abs() applied, then is split into a (hi, lo) double-double f32 pair (see splitDoubleDouble/f64.mjs) since WGSL has no f64 type; accumulation uses Dekker's double-double algorithm (see shaders/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.

      import { init, cleanup } from "wgblas";
      import { dasum } from "wgblas/dasum";
      import { randomFloat64Array } from "wgblas/random";

      const device = await init();

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

      console.log("x: ", x);
      const { asum } = await dasum(device, n, x, 1);
      console.log("asum: ", asum);
      if (typeof process !== "undefined") cleanup();

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>dasum — wgblas browser example</title>
      <script src="https://manit2004.github.io/wgblas/wgblas.browser.js"></script>
      </head>
      <body>
      <pre id="out">Running…</pre>
      <script>
      const { init, dasum, randomFloat64Array, cleanup } = window.wgblas;

      (async () => {
      const device = await init();

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

      const { asum } = await dasum(device, n, x, 1);

      document.getElementById("out").textContent =
      "x: " + Array.from(x).map(v => v.toFixed(4)).join(", ") +
      "\nasum: " + asum.toFixed(4);

      cleanup();
      })();
      </script>
      </body>
      </html>

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: Float64Array

        Float64Array input vector

      • incx: number

        stride for x (must be a positive integer)

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

      absolute sum scalar — always a CPU readback, even for GpuVector inputs

    • Computes the sum of absolute values of a vector of doubles in double precision: result = sum(|x[i]|).

      import { init, cleanup } from "wgblas";
      import { dasum } from "wgblas/dasum";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { randomFloat64Array } from "wgblas/random";

      const device = await init();

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

      const xGpu = GpuVector.from(x);

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

      const { asum } = await dasum(device, n, xGpu, 1);
      console.log("asum: ", asum);

      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

        Float64Array-backed GpuVector input vector

      • incx: number

        stride for x (must be a positive integer)

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

      absolute sum scalar — always a CPU readback, even for GpuVector inputs