Skip to content

compute.ndarray.real

Summary

compute.ndarray.real selects the real component of each complex element. Use compute.ndarray.imag for the imaginary component. Both share the input storage.

Syntax

real<T extends CPUndarray | GPUndarray>(a: T): T
imag<T extends CPUndarray | GPUndarray>(a: T): T
const re = nd.real(z);

Parameters

Name Type Required Description
a CPUndarray | GPUndarray Yes Live array with dtype "c64" or "c128". Other dtypes throw.

Returns

T - View with the input shape and byte strides and the corresponding component dtype ("f32" or "f64"). The imaginary view selects addresses one component past the real component. Writes update that part of the complex element.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const nd = wgpu.compute.ndarray;
const z = nd.fromArray("c64", [2], [1, -1, 2, -2]);
const im = nd.imag(z);
im.set(5, 0);
console.log(z.get(0)); // [1, 5]
im.destroy();
z.destroy();

See Also