Repository navigation
Playground: go-ndarray compiled to WebAssembly, step by step - #23
Merged
Merged
Conversation
…pp (WIP) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…nput, text at logical size Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…I, deploy wiring, README Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… over the tested packages Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…k read it as a URL) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… Entry caret clamp) instead of the PR pseudo-version Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A playground at /playground/: go-ndarray itself, compiled to WebAssembly, inside a go-widgets canvas app (the go-tex playground's structure: a nested Go module under
playground/, a Hugo layout, the wasm built at deploy). The landing's nav gets a Playground entry; the page reuses the landing's nav bar,styles.htmland System/Light/Dark toggle unchanged (the icons from #21 are kept — this branch is rebased on #22).A visitor can create arrays (
Arange,Linspace,Zeros/Ones/Full,Eye, typed-inFromData) and apply, step by step,Reshape(with -1),Transpose, NumPy-styleSlice(1:3, ::2, 0, -1), broadcastingAdd/Sub/Mul/Div(a step or a number),Maximum/Minimum, ufuncs (Exp,Log,Sqrt,Sin,Cos,Abs,Square,Power,Clip), reductions whole or along an axis with keepdims (Sum,Mean,Max,Min,ArgMax,CumSum),Concatenate/Stack,MatMul/Dot/Outer. For each step: shape, strides in elements and bytes, offset, contiguity, whether it is a view and which earlier steps it shares memory with, the mean time per call in the browser, values as a viridis heatmap table, the Go statement and the NumPy one. The whole pipeline is shown as a Go program that compiles, or its NumPy equivalent, with a Copy button. Errors are go-ndarray's own text. Eight presets (README example, views, broadcasting, reductions, ufuncs, joins, linalg, a shape mismatch to try).Architecture
playground/engine— model: op catalog, argument parsing, timed runs, Go/NumPy spellings, layout read from go-ndarray'sArray(strides/offset/storage are unexported in v0.7.1, read viareflect, read-only;TestLayoutReadsTheLibraryfails if a release renames them). Size guard (2^22 elements) so a typo cannot OOM the tab.playground/vm— ViewModel: all state asmvvmObservables/ObservableLists/Commands, no widget.playground— View: toolkitLabel,DropDown,ListBox,Entry,Button,ViewSwitcher,TextView,Table,VBox/HBox, bound withmvvmtk+view_binding.go. Nothing drawn by hand.playground/cmd/playground-wasm— browser shell (device-pixel canvas, input,ndarraySetTheme,ndarrayDebug/ndarrayRectsfor the proofs).Depends on go-widgets/toolkit#483 (
Table.CellFill+Viridis+ContrastInk, and anEntrycaret fix the bindings exposed).go.modpins that PR's commit as a pseudo-version; once it is merged and tagged, bump to the tag.go-ndarray's helper goroutines under wasm
Under
GOOS=jsGOMAXPROCS is 1, so every operation takes the serial path and no helper goroutine is ever started. Checked three ways: the engine suite run as wasm under node (goroutine count unchanged after 10^6-elementExp/Sumand a 1000²MatMul), the same test natively with GOMAXPROCS=4 as positive control (2 → 5 goroutines), and in Chrome by the browser proof. Timings on the page are therefore single-threaded and without SIMD.Size
playground.wasm13.0 MB, 3.4 MB gzipped (-s -w -trimpath). Not committed:hugo.ymlbuilds it and copieswasm_exec.jsfrom the same toolchain before Hugo, cache-busted with?v=<sha>.Gates
playground.yml(new): gofmt, vet (native + js/wasm),-race, 100% statement coverage ofengine,vmand the View, the engine suite as wasm under node, wasm build + size in the summary; mvvmlint + bricolint with a negative control each (hack/lint-negative-controls.sh, both bite); a browser proof in headless Chrome.ci.yml: also checks the playground page is built and the landing links to it.Verification (run locally, own protocol)
TestBrowserProofbuilds the site exactly as the deploy does and drives it with real mouse/keyboard in headless Chrome, scheme forced, light@1x, dark@1x, light@2x — 114 assertions, all green: opens on the README example; canvas background = theme background (pixel); heatmap colours on screen (pixels); clicking a step selects it and makes it the input; picking Transpose in the popover + Apply adds a non-contiguous view; a bad reshape typed + Enter showsndarray: shape mismatch…in red (pixels); NumPy tab; Copy puts the program on the clipboard; the mismatch preset fails withndarray: shapes are not broadcastable: [2 3] vs [3 2]; GOMAXPROCS 1 and no new goroutine after 10^6-element steps; the nav toggle repaints the canvas light then dark (pixels); no console error. Negative control: withSetThemedisabled the proof fails on "toggle to Dark paints the dark background". Screenshots go outside every repository (the capture helper refuses a git work tree).🤖 Generated with Claude Code