programs/train and infer's CPU reference: SGD of a cubic on sin(pi x) samples, warp sums and the SGD step, op for op in Z
$ sexc add @ajax/mesh-ref-cubic- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 01:59v/# 1 version
- drwxr-xr-x-Oct 27 01:59files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 01:59 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- @ajax/mesh-ftz ^0.1.0, @ajax/mesh-ref-block ^0.1.0, @ajax/mesh-abi-view-train ^0.1.0
- dependents
- @ajax/mesh-prog-infer, @ajax/mesh-prog-infer-wasm, @ajax/mesh-prog-train, @ajax/mesh-prog-train-wasm
- keywords
- alphaos mesh reference train infer sgd
- homepage
- https://github.com/thomasdavis/alpha-c-mesh/tree/main/packages/mesh-ref-cubic
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/mesh-ref-cubic 2 3programs/train's and programs/infer's CPU reference, written operation for operation as the programs 4compute in the cluster float mode: a cubic `p0 + p1·x + p2·x² + p3·x³` fitted by SGD to `sin(πx)` sampled 5on a 256-point grid. Each step, lane l of a warp takes sample `(8l + off) mod 256`, and the loss and the 6four gradient sums are warp butterflies; `apply` is the SGD update and `loss` the value a step records. 7`sin_pi` is train's own (an f64 Taylor polynomial after folding into [−½, ½], with flushing converts). 8 9**Ported from** `crates/mesh-ref/src/lib.rs` (`cubic_z`, `cubic`, `warp_sum`, `step_sums`, `apply`, 10`loss`, `sin_pi`, `grid`, `samples`). Freestanding. 11 12**Tested** by a golden digest from the Rust: the samples, a 64-point grid, `sin_pi` over 200 000 inputs, 13300 SGD steps (every sum, loss and parameter, and the cubic at a point) and a warp sum. 14 15## Differences 16 17- `grid` and `samples` write caller buffers instead of returning `Vec`s; `cubic` takes a float (Rust has 18 `cubic_z` on `Z` and `cubic` on `f32`, which are the same here).