Repository navigation
hpc::phase: phases in turns, a (cos, sin) LUT with stated error bounds, a drift-free accumulator - #343
Merged
Conversation
…s, a drift-free accumulator A phase is a u32 in turns (2^32 = one rotation), so 3θ is p.wrapping_mul(3) and wraparound is free. PhaseLut maps a phase to (cos, sin) through a 2^bits table, at the nearest entry or by linear interpolation, and states a per-component error bound for each, so a caller can carry it into an exact decision. PhaseStep gives the phase after n steps in closed form, so it cannot drift. Re-exported from ndarray::simd. Measured in the lance-graph phasor probe (#1416): interpolation at 2^12 entries matches f32 sin_cos accuracy at about 4.5x its speed and 12x f64. The lookups are scalar; no SIMD path is claimed. Tests check each bound two-sided (never exceeded, not vacuous). Four disable runs are red. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EFw2WdKr1oxvaKCJC2ua2R
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (4)
✨ Finishing Touches📝 Generate docstrings
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Comment |
AdaWorldAPI
marked this pull request as ready for review
October 8, 2026 19:39
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
This PR adds
src/hpc/phase.rs, re-exported fromndarray::simd. It is the "ADOPT" item of the lance-graph phasor probe (D-PHT-1, lance-graph #1416).What
Phases. A phase is a
u32in turns, with2^32= one rotation. So3θisp.wrapping_mul(3),θ + φisp.wrapping_add(q), and wraparound is free.turns_from_radians/radians_from_turnsPhaseLut2^bits[cos, sin]pairs,bitsin 2..=20.phase_lut_4096()PhaseStep { start, step }at(n) = start + n·stepmodulo one turn, in closed form, so it cannot drift.from_radiansreports how far the representable step is from the requested one.PhaseLutmethods:nearest(p)andlerp(p)(linear interpolation), pluslerp_batch.nearest_error_bound()isπ/2^bitsplus f32 rounding;lerp_error_bound()ish²/8(chord sag, withh = 2π/2^bits) plus 4·f32 epsilon.Why
ndarray had no phase LUT, no CORDIC and no SIMD
sin/cos.vml::vscos/vssincall scalarcos/sinper lane.The lance-graph probe measured interpolation at 2^12 entries:
sin_cos(4.6e-7 vs 5.1e-7 relative).sin_cosand 12× faster than f64 (x86-64-v3, release, 1M random phases).The lookups here are scalar. No SIMD path is claimed. A gather batch is a separate, unmeasured step.
Tests
wrapping_mul(3)equals3θ mod 2π.from_radiansreports the step it actually took.Disable runs, each red then restored:
atignoringstart.Gates:
cargo test -p ndarray --lib: 2543 passed.cargo clippy -p ndarray --lib --tests -- -D warnings: clean.The blackboard entry is prepended.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EFw2WdKr1oxvaKCJC2ua2R
Generated by Claude Code