Wire %fixp (fixed-point) arrays into Lagoon#44
Open
sigilante wants to merge 1 commit into
Open
Conversation
Phase B of the fixed-point buildout: integrates /lib/fixed into Lagoon as the %fixp kind, element-wise plus quire-style exact reductions. Representation: a fixed-point element occupies 2^bloq bits with a + b + 1 = 2^bloq (q3.4 @ bloq3/8b, q7.8 @ bloq4/16b, q15.16 @ bloq5/32b), matching the %int2/%unum tiling. The precision [a b] is carried in meta.tail and read via ;;([a=@ b=@] tail). - sur/lagoon: %fixp enabled in the kind union. - fun-scalar: add/sub/mod and all comparisons need only the width and reuse /lib/twoc directly (identical to %int2 on the stored integer); mul/div rescale by 2^b through /lib/fixed (mul re-quantizes back to the array precision rather than widening, since array elements are uniform); comparisons return the fixed value 1.0 (= 2^b) / 0.0. - trans-scalar %abs: two's-complement abs at the element width. - get-term (%ux, no fixed-point printer), eye/ones constant 1.0 = 2^b from meta.tail, scale raw-pack, change guarded with a ~| message. - Reductions: dot/mmul use a new +fixp-fdp that accumulates the integer products Sum sx*sy exactly, then rescales by 2^b once (exact, no per-product truncation). cumsum needs no special path (fixed add is already exact modular integer add). Tests: /tests/lib/lagoon-fixp (7) over q3.4 -- arith, comparisons, abs, ones, cumsum, exact dot and mmul. All pass on ~hex; %unum (14) and %int2 (5) regression suites still green. Co-Authored-By: Claude Opus 4.8 <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.
Phase B of the fixed-point buildout — integrates
/lib/fixedinto Lagoon asthe
%fixparray kind, element-wise plus exact reductions, mirroring the%int2/%unumintegrations.Independent of PR #43 (Phase A scalar API): this uses only
/lib/fixed'spre-existing
mul/div/scale/to-s/ngarms.Representation
A fixed-point element occupies
2^bloqbits, witha + b + 1 = 2^bloq(q3.4 @ bloq3/8b, q7.8 @ bloq4/16b, q15.16 @ bloq5/32b) — the same power-of-2
tiling every other kind uses. The precision
[a b]rides inmeta.tail(its declared "future data" slot), read via
;;([a=@ b=@] tail).What's wired
sur/lagoon:%fixpenabled in thekindunion.fun-scalar:add/sub/modand all comparisons need only theelement width and reuse
/lib/twocdirectly (identical to%int2on thestored integer).
mul/divrescale by2^bthrough/lib/fixed;mulre-quantizes back to the array precision rather than widening (array
elements are uniform — truncating, documented). Comparisons return the
fixed value
1.0(=2^b) /0.0.trans-scalar%abs: two's-complement abs at the element width.get-term(%ux, no fixed-point printer),eye/onesconstant1.0 = 2^bfrommeta.tail,scaleraw-pack,changeguardedwith a
~|message (conversion not yet wired).dot/mmuluse a new+fixp-fdpthat accumulates theinteger products
Σ sx·syexactly, then rescales by2^bonce — exact,no per-product truncation.
cumsumneeds no special path (fixed add isalready exact modular integer add).
Tests —
/tests/lib/lagoon-fixp(7, all pass on ~hex)q3.4 coverage: arithmetic, comparisons, abs, the
onesbuilder,cumsum,and exact
dot/mmul. The%unum(14) and%int2(5) regression suitesremain green.
Not in scope
change/convert for%fixp(use/lib/fixed'sto-rs/from-rs); jets.🤖 Generated with Claude Code