Skip to content

fix: WASM add/subtract with a packed histogram operand - #71

Merged
alexvictoor merged 2 commits into
masterfrom
fix/wasm-packed-add-exports
Nov 8, 2026
Merged

alexvictoor merged 2 commits into
masterfrom
fix/wasm-packed-add-exports

Conversation

@alexvictoor

@alexvictoor alexvictoor commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Problem

WasmHistogram.add / subtract build the export name from the two suffixes: addHistogram${other}to${this} and subtractHistogram${other}from${this}. The AssemblyScript module exported the packed-operand variants under a different scheme (addPackedHistogramto8, subtractPackedHistogramfromPacked, ...), so adding or subtracting a WASM packed histogram to/from any WASM histogram threw:

TypeError: wasm[`addHistogram${otherHistogram._suffix}to${this._suffix}`] is not a function

Receiver type does not matter: all five receivers (8, 16, 32, 64, packed) fail when the operand is packed. The reverse direction (packed receiver, flat operand) already worked.

Fix

Rename the ten exports in assembly/index.ts to the regular scheme (addHistogramPackedto*, subtractHistogramPackedfrom*). No JS change; nothing else referenced the old names.

Also: repair the CI build

npm run astest:ci has been failing on master since 21b452b (updatedMaxValue now uses value | unitMagnitudeMask instead of +), because assembly/__tests__/HistogramCountsKernels.test.ts still expected the old arithmetic. Since that step runs before vitest, CI never reached the JS tests. The second commit updates the expectation to the OR; the AssemblyScript suite is back to 15277/15277.

Tests

New test in src/Histogram.spec.ts iterating over every (receiver, operand) pair of WASM bucket sizes: add, check total count and max, subtract, check the summary is back to the original. With master's wasm binary the 5 packed-operand cases fail with the error above; with the fix all 25 pass.

npm test: 231 passed, 4 skipped. npm run astest:ci: 15277/15277. npm run typecheck: clean.

Found while benchmarking for #68 / #69 (the sparse add bench had no WASM packed row because of this).

🤖 Generated with Claude Code

alexvictoor and others added 2 commits November 8, 2026 15:21
The JS wrapper builds the export name as
`addHistogram${otherSuffix}to${thisSuffix}` (and the `subtract...from...`
twin), but the AssemblyScript module exported the packed-operand variants
as `addPackedHistogramto*` / `subtractPackedHistogramfrom*`. Any
`wasmHistogram.add(wasmPackedHistogram)` therefore threw
"wasm[...] is not a function", whatever the receiver's bucket size.

Rename the ten exports to follow the regular naming scheme and add a test
covering every (receiver, operand) pair of WASM bucket sizes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…lue fix

Commit 21b452b changed updatedMaxValue from `value + unitMagnitudeMask` to
`value | unitMagnitudeMask` (as in the Java original) but left the
AssemblyScript kernel test expecting the old arithmetic, so `npm run
astest:ci` has failed on master since then and CI never reached the vitest
step.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@alexvictoor
alexvictoor marked this pull request as ready for review November 8, 2026 17:34
@alexvictoor
alexvictoor merged commit 141472c into master Nov 8, 2026
4 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