wgblas
    Preparing search index...

    Function cscal

    • Scales a complex vector by a complex constant: $$x \leftarrow \alpha x$$

      import { init, cleanup } from "wgblas";
      import { cscal } from "wgblas/cscal";
      import { Complex32, Complex32Array } from "wgblas/classes/Complex32";

      const device = await init();

      const n = 3;
      const alpha = new Complex32(2, 3); // 2 + 3i
      const x = new Complex32Array([1, 1, 0, 2, 2, -1]); // 1+1i, 0+2i, 2-1i

      console.log("before:", x.map((z) => `${z.re}+${z.im}i`).join(", "));
      const { x: result } = await cscal(device, n, alpha, x, 1);
      console.log("after: ", result.map((z) => `${z.re}+${z.im}i`).join(", "));
      if (typeof process !== "undefined") cleanup();

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>cscal — wgblas browser example</title>
      <script src="https://unpkg.com/wgblas/dist/wgblas.browser.js"></script>
      </head>
      <body>
      <pre id="out">Running…</pre>
      <script>
      const { init, cscal, cleanup, Complex32, Complex32Array } = window.wgblas;

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

      const n = 3;
      const alpha = new Complex32(2, 3); // 2 + 3i
      const x = new Complex32Array([1, 1, 0, 2, 2, -1]); // 1+1i, 0+2i, 2-1i

      const fmt = (arr) => arr.map((z) => `${z.re}+${z.im}i`).join(", ");
      console.log("before:", fmt(x));
      const { x: result } = await cscal(device, n, alpha, x, 1);
      console.log("after: ", fmt(result));

      document.getElementById("out").textContent =
      "before: " + fmt(x) +
      "\nafter: " + fmt(result);

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements to scale (must be a positive integer)

      • alpha: Complex32

        complex scalar multiplier

      • x: Complex32Array

        Complex32Array input/output vector

      • incx: number

        stride for x (must be a positive integer)

      Returns Promise<{ x: Complex32Array } | { gpuTimeMs: number; x: Complex32Array }>

    • Scales a complex vector by a complex constant: $$x \leftarrow \alpha x$$

      import { init, cleanup } from "wgblas";
      import { cscal } from "wgblas/cscal";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { Complex32, Complex32Array } from "wgblas/classes/Complex32";

      const device = await init();

      const n = 3;
      const alpha = new Complex32(2, 3); // 2 + 3i
      const x = new Complex32Array([1, 1, 0, 2, 2, -1]); // 1+1i, 0+2i, 2-1i

      const xGpu = GpuVector.from(x);

      console.log("x: ", x.map((z) => `${z.re}+${z.im}i`).join(", "));

      await cscal(device, n, alpha, xGpu, 1);

      const result = await xGpu.read();
      console.log("result:", result.map((z) => `${z.re}+${z.im}i`).join(", "));

      xGpu.destroy();
      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements to scale (must be a positive integer)

      • alpha: Complex32

        complex scalar multiplier

      • x: GpuVector

        Complex32Array-backed GpuVector input/output vector (mutated in place)

      • incx: number

        stride for x (must be a positive integer)

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