gpuFold (Function)
Signature: gpuFold(buffer: GpuBuffer<int> | GpuBuffer<float> | GpuBuffer<bool>, initial: t1, combine: (t1, t0) -> t1) -> t1
Description: Reduces a buffer to one scalar with a pure combine function. Use an associative combine: a device backend may reassociate.
Parameters
- buffer (GpuBuffer
| GpuBuffer | GpuBuffer ): The buffer to reduce - initial (t1): The initial scalar accumulator
- combine ((t1, t0) -> t1): The pure (accumulator, element) function
Returns: t1
Example
toGpu([1, 2, 3]) |> gpuFold(0, fn(a, x) => (a + x) ?: a)
toGpu [1, 2, 3] |> gpuFold (0, \(a, x) => (a + x) ?: a)