Skip to content

compute.ndarray#dtype

Summary

compute.ndarray#dtype identifies how each logical element is stored. Read it before interpreting a CPU typed-array view, choosing a conversion, or passing the array to a GPU operation with dtype restrictions.

Syntax

readonly Ndarray.dtype: DType
const dtype = array.dtype;

Returns

DType - The fixed element type of a CPU or GPU ndarray. Use dtypeInfo to look up component count, element width, typed-array constructor and direct WGSL representation. A complex element uses two consecutive components in real, imaginary order.

Example

import { dtypeInfo } from "@zushah/wasmgpu";

const a = wgpu.compute.ndarray.fromArray("c64", [2], [2, 3, 4, 5]);
console.log(a.dtype, dtypeInfo(a.dtype).bytesPerElement); // c64, 8
a.destroy();

See Also