compute.ndarray.flip¶
Summary¶
compute.ndarray.flip reverses element order along selected axes using a view. The shape stays the same and the selected strides change sign.
Syntax¶
flip<T extends CPUndarray | GPUndarray>(a: T, axes?: number | ReadonlyArray<number>): T
const reversed = nd.flip(a, -1);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
a |
CPUndarray | GPUndarray |
Yes | Live input array. |
axes |
number | ReadonlyArray<number> |
No | Distinct integer axes. Negative indices count from the end. Omission reverses every axis. |
Returns¶
T - View starting at the last element along each selected non-empty axis. Keep its root alive and destroy the view separately.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const nd = wgpu.compute.ndarray;
const a = nd.fromArray("f32", [3], [1, 2, 3]);
const reversed = nd.flip(a);
console.log(reversed.get(0)); // 3
reversed.destroy();
a.destroy();