recipes · recipe ·
Example · Smooth a noisy row
Read neighbors safely using separate input and output buffers.
Now each output depends on neighboring input values. We will average the value on the left, the current value, and the value on the right. This is a small three-tap smoothing filter. Read from one buffer and write into another. If every invocation read and overwrote the same buffer, one might see a neighbor before its update and another might see it after. The result could depend on scheduling.
start.yh · compute exampleStatus: complete-program
Example · Smooth a noisy row
Read neighbors safely using separate input and output buffers.
gpu · cpu · type checked
[auto]
compute Smooth(buffer of float input, buffer of float output)
{
int index = compute.index
if index >= input.count { return }
if index >= output.count { return }
if index == 0 or index + 1 >= input.count
{
output[index] = input[index]
return
}
output[index] = (input[index-1] + input[index] + input[index+1]) / 3.0
}
buffer of float input
input.Add(0.0) input.Add(0.0) input.Add(9.0) input.Add(0.0) input.Add(0.0)
buffer of float output
output.Resize(5)
computeTask job = dispatch Smooth(input, output)
wait job
if job.failed { Console.Error(job.error.message) Process.Exit(1) }
for index from 0 < output.count { Console.Log(Text.From(output[index])) }project.mech
manifestVersion = "2"
package = "api.example.recipe__compute_filter"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"
[app]
kind = "headless"
Expected output
0 3 3 3 0
Notes and source
Change the center input from 9.0 to 3.0. Then try a constant row where every input is 6.0.
demonhunterlabs/app/lib/yeho-walkthrough.ts