simd: _sym group sum — symmetric range with a reserved empty code - #321
Merged
Merged
Conversation
masked_group_sum_seeded_i32 and _via: a slot still holding the caller's `empty` marker has seen no row, so the first selected row REPLACES the marker and later rows add (wrapping_add, as the plain sum). The plain sum cannot separate an empty group from one whose rows cancel to 0. `empty` = i64::MIN is the intended marker: a sum of n i32 stays strictly above it for every n < 2^32, which leaves a symmetric real range ±(2^63 - 1). The doc names the one reachable case (exactly 2^32 rows of i32::MIN) so a caller with that row count bounds it or picks another marker. One walker, as the rest of the family: two named closures over group_walk. Tests: both addresses against the scalar oracle at every length, plus the cancel-vs-empty case and both VIA drops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GXUahz73MZxtxWcfpHp9dG
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueComment |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_5cae7d3d-2e65-4c9b-a841-812e1ffd8a53) |
…hosen marker
masked_group_sum_seeded_i32{,_via}(…, empty, …) let any caller pick any
marker, so a full-range caller could reserve a real value by accident.
The reservation is now opt-in by NAME only:
- masked_group_sum_sym_i32{,_via}: symmetric range ±(2^63−1), with
SYM_EMPTY_I64 = i64::MIN reserved as "no row reached this group" — the
4-bit −7..+7 + NaN reading, never the −8..+7 one.
- Every unsuffixed reduction keeps the full two's-complement range and never
treats i64::MIN specially. A new test pins that: the full-range sum adds to
an i64::MIN slot where the _sym sum replaces it.
The rule is stated once, on SYM_EMPTY_I64. One fold closure serves both key
addresses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GXUahz73MZxtxWcfpHp9dG
_sym group sum — symmetric range with a reserved empty code
AdaWorldAPI
marked this pull request as ready for review
September 23, 2026 08:54
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_2446c836-9c84-4b71-9a94-8dfe2b270785) |
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
masked_group_sum_sym_i32andmasked_group_sum_sym_i32_via: grouped sums that can tell an empty group from a group whose rows sum to zero.SYM_EMPTY_I64 = i64::MIN: the one value these functions reserve to mean "no row reached this group".All three are re-exported from
ndarray::simd.Full range vs
_sym(the naming rule)Only functions with the
_symsuffix reserve a value, and the reserved value is fixed (the caller does not choose it)._symsuffix: the function uses the full two's-complement range. Everyi64it writes is a real value,i64::MINincluded, and it never treatsi64::MINspecially. Callers that treat the output as plain integers are always right._symsuffix: real sums live in the symmetric range ±(2⁶³−1), andSYM_EMPTY_I64means "empty". This is the 4-bit analogue of reading a nibble as −7..+7 and keeping −8 as NaN, rather than using the full −8..+7.The rule is written once, in the docs of
SYM_EMPTY_I64.An earlier revision of this PR (
masked_group_sum_seeded_i32(…, empty, …)) let the caller pass any marker. That meant a caller expecting full-range behaviour could reserve a real value by accident, so it was removed.How it works
outwithSYM_EMPTY_I64first.wrapping_add, the same as the plain sum.group_walk, and one fold closure serves both key addresses. No new bit loop.Row limit: the marker can be hit by a real sum only at 2³² or more rows. Exactly 2³² rows of
i32::MINsum toi64::MIN. Callers that fold that many rows into one group must cap the row count.Why
This is for SQL
HAVINGover grouped results in lance-graph's quack layer (AdaWorldAPI/lance-graph#1266). There the reserved code stays internal: quack turns each raw result into "empty slots set to 0" plus a K-bit presence mask before anything downstream sees it.Tests
sym_sum_matches_the_reference_and_marks_empty_groups: both key addresses against a scalar reference, at every length inLENS.a_cancelling_group_is_present_and_an_unreached_group_is_empty: a group whose rows cancel to 0 is present, a group no row reached is empty, and both lookup steps of the_viapath drop rows correctly.full_range_sum_never_treats_the_sym_code_as_empty: the plain sum adds to a slot holdingi64::MIN, while the_symsum replaces it.Disable run: turning the
_symfold into a plainwrapping_addmakes all three_sym-sensitive tests fail. clippy-D warningsand fmt are clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01GXUahz73MZxtxWcfpHp9dG