CPUndarray.zeros¶
Summary¶
CPUndarray.zeros allocates a CPU ndarray and fills its backing bytes with zero.
It has the same layout semantics as CPUndarray.empty.
Use this for deterministic initialization before incremental writes.
This is convenient for counters, masks, and accumulator arrays.
Syntax¶
CPUndarray.zeros(dtype: DType, layout: NdLayoutDescriptor): CPUndarray
const a = CPUndarray.zeros(dtype, layout);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
dtype |
DType |
Yes | Element data type. |
layout |
NdLayoutDescriptor |
Yes | Shape plus optional strides/offset metadata. |
Returns¶
CPUndarray - Zero-filled CPU ndarray.
Call initWebAssembly() before using this class without a WasmGPU instance. See the layout rules for stride and offset defaults and constraints.
Example¶
import { CPUndarray, initWebAssembly } from "@zushah/wasmgpu";
await initWebAssembly();
const a = CPUndarray.zeros("u32", { shape: [8] });
console.log(Array.from(a.data()));
a.destroy();