# Example · Smooth a noisy row

Read neighbors safely using separate input and output buffers.

Last updated: 2026-09-09

Package: recipes | Status: complete-program

Tags: cpu, gpu, recipe

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.

```yh
start.yh · compute example
```


## Example · Smooth a noisy row

Read neighbors safely using separate input and output buffers.

Verification: type checked

```yh
[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])) }
```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.recipe__compute_filter"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

```

Expected output:

```text
0
3
3
3
0
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/recipe--compute-filter/program --backend metal -o /tmp/yeho-example
/tmp/yeho-example
```


Change the center input from 9.0 to 3.0. Then try a constant row where every input is 6.0.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
