Skip to content

Add streaming GPU normal equations for least-squares fitting - #2

Merged
SamG-Coder merged 1 commit into
mainfrom
feat/least-squares
Sep 22, 2026
Merged

SamG-Coder merged 1 commit into
mainfrom
feat/least-squares

Conversation

@SamG-Coder

Copy link
Copy Markdown
Owner

NNTC's browser encoder needs to fit a small affine model from many GPU-generated observation rows without reading all rows back to JavaScript. Add a reusable NormalEquations accumulator: it streams row batches through deterministic GPU partial sums and performs the final small, pivoted solve on the host.

The API validates buffer ownership, row layout and bounds, supports multiple output channels and a relative ridge, and rejects empty or singular fits. GPU arithmetic is f32; this does not claim native f64/QR conditioning or accuracy.

Validation:

  • npm test: 785 tests passed.
  • node scripts/test-least-squares.mjs: 1,031 rows streamed in two batches on Edge/WebGPU; maximum coefficient difference from the CPU reference was 1.19e-7, with no WebGPU errors.
  • NNTC integration exercised repeated fits and buffer cleanup during normal completion and cancellation.

@SamG-Coder
SamG-Coder marked this pull request as ready for review September 22, 2026 22:54
@SamG-Coder
SamG-Coder merged commit f45a967 into main Sep 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant