{"id":"recipe--compute-filter","name":"Example · Smooth a noisy row","owner":"yeho","package":"recipes","kind":"recipe","signature":"start.yh · compute example","description":"Read neighbors safely using separate input and output buffers.","context":"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.","parameters":[],"returns":"","members":[],"tags":["cpu","gpu","recipe"],"updated":"2026-09-09","source":{"repository":"demonhunterlabs","path":"app/lib/yeho-walkthrough.ts"},"status":"complete-program","notes":["Change the center input from 9.0 to 3.0. Then try a constant row where every input is 6.0."],"examples":[{"id":"program","title":"Example · Smooth a noisy row","description":"Read neighbors safely using separate input and output buffers.","code":"[auto]\ncompute Smooth(buffer of float input, buffer of float output)\n{\n    int index = compute.index\n    if index >= input.count { return }\n    if index >= output.count { return }\n    if index == 0 or index + 1 >= input.count\n    {\n        output[index] = input[index]\n        return\n    }\n    output[index] = (input[index-1] + input[index] + input[index+1]) / 3.0\n}\n\nbuffer of float input\ninput.Add(0.0) input.Add(0.0) input.Add(9.0) input.Add(0.0) input.Add(0.0)\nbuffer of float output\noutput.Resize(5)\ncomputeTask job = dispatch Smooth(input, output)\nwait job\nif job.failed { Console.Error(job.error.message) Process.Exit(1) }\nfor index from 0 < output.count { Console.Log(Text.From(output[index])) }","manifest":"manifestVersion = \"2\"\npackage = \"api.example.recipe__compute_filter\"\nversion = \"0.1.0\"\nlanguageEdition = \"yeho-core-2026.1\"\n\n[app]\nkind = \"headless\"\n","tags":["gpu","cpu"],"run":"metal","expected":"0\n3\n3\n3\n0","verification":"type checked","sha256":"b44679fa6c68c8c10d4c2043f5485e4b69a5175d8c362b48cbe078e8ca2684d2","checked":"2026-09-09","diagnostic":"","observedOutput":null,"checkedBackend":null}],"searchTerms":[],"url":"https://demonhunterlabs.com/academy/api?item=recipe--compute-filter","json":"https://demonhunterlabs.com/reference/items/recipe--compute-filter.json","markdown":"https://demonhunterlabs.com/reference/text/recipe--compute-filter.md"}
