simd: group_walk as a (group,row) visitor; add PowerSums power-sum fold - #337
Conversation
The private keyed-reduction walker no longer takes an i64 sink: it yields
(group, row) and each fold owns its destination. The 15 existing folds
were migrated mechanically; no public signature changes.
New: PowerSums { n: u64, sum: i64, sum_sq: u128 } (#[repr(C)], 32 bytes,
layout pinned at compile time) and masked_group_power_sums_i32 with
_via / _pair, the exact degree-0/1/2 power sums per group in one pass.
A scratch benchmark chose the shapes: the visitor costs nothing for the
existing folds, and the record beats three separate lanes at large K.
The u128 square sum is load-bearing: a u64-truncation disable run turns
the four exactness tests red.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ho2JosrXCnZPbB7RFssrse
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. 2 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. 📝 WalkthroughWalkthroughThe shared ChangesMasked Grouped Reductions
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Caller
participant masked_group_power_sums_i32_via
participant group_walk
participant PowerSums
Caller->>masked_group_power_sums_i32_via: Provide mask, index, table, values, and output
masked_group_power_sums_i32_via->>group_walk: Supply group count and fold
group_walk->>PowerSums: Pass group and row indices to update count, sum, and squared sum
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change adds grouped power sums while preserving the existing reduction interfaces. No concrete merge-blocking issue is established; merge after normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
I hop through rows beneath the mask Comment |
What
group_walknow yields(group, row)and never sees a sink (groups: usize,fold: FnMut(usize, usize)). Itsi64slot was an accident of the first folds. All 15 existing folds were migrated mechanically (|k, i| out[k] = …, passingout.len()). No public signature changes.#[repr(C)] PowerSums { n: u64, sum: i64, sum_sq: u128 }, the exact degree-0/1/2 power sums, plusmasked_group_power_sums_i32/_via/_pairsharing one fold, all re-exported fromndarray::simd. No statistical vocabulary at this layer: what the sums mean is decided upstream (jc).align_of::<u128>(). That is 16 on x86_64/aarch64 and 8 on some cross targets; size and offsets are the same everywhere. It also checks the documented Σx row bound,(2^32-1)·2^31 ≤ i64::MAX.Why this shape (measured before the change)
Scratch benchmark over 72 cells: resident/via/pair keys × mask density 1/50/100 % × K 1…65 536 × realistic/extreme values; median of 15 reps, two runs.
The record wins because it touches one cache line per row instead of three, and its hot loop has 2 stack reloads instead of 6. One cell is unexplained: SoA beats AoS by ~35 % on dense resident/via keys at K = 16. It reproduced in both runs; it is recorded and not investigated, since the decision doesn't depend on it.
Evidence
n = 2;u64::MAX, asserted from the oracle before the kernel is checked;i32::MINin one group, exact;cargo test --lib: 2516 passed, 32 ignored. Group doctests: 17/17.clippy --lib -D warningsand fmt are clean.Not in this PR
GroupFold::PowerSumsI32+Out::PowerSums, reusingValue::GroupReduced. The R2IL vocabulary gets its byte only after that parity is green.🤖 Generated with Claude Code
https://claude.ai/code/session_01Ho2JosrXCnZPbB7RFssrse
Generated by Claude Code
Summary by CodeRabbit