Skip to content

perf: integer-only Bareiss determinant via BigInt (#64)#73

Merged
acgetchell merged 2 commits intomainfrom
perf/64-bigint-bareiss-det
Apr 11, 2026
Merged

perf: integer-only Bareiss determinant via BigInt (#64)#73
acgetchell merged 2 commits intomainfrom
perf/64-bigint-bareiss-det

Conversation

@acgetchell
Copy link
Copy Markdown
Owner

@acgetchell acgetchell commented Apr 11, 2026

Replace the BigRational Bareiss determinant with a pure BigInt path: all f64 entries are decomposed into mantissa × 2^exponent, scaled to a common integer base, and eliminated without any rational arithmetic. The result is reconstructed as BigRational only at the end.

  • Add f64_decompose helper (extracted from f64_to_bigrational)
  • Add bareiss_det_int: integer-only Bareiss returning (BigInt, i32)
  • Add bigint_exp_to_bigrational: reconstruction with trailing-zero reduction (no full GCD needed)
  • Refactor bareiss_det as thin wrapper over bareiss_det_int
  • Optimize det_sign_exact to read sign from BigInt directly (skip BigRational reconstruction entirely)
  • Import std::array::from_fn for shorter call sites
  • Replace clippy cast suppression with exact try_from conversions
  • Update AGENTS.md with non-interactive gh CLI patterns
  • 24 new tests (256 total): f64_decompose, bareiss_det_int (D=0–5, fractional, all-zeros, sign), bigint_exp_to_bigrational (positive/ negative exp, reduction, negative values)

Performance (vs pre-bigint baseline on Apple M4 Max):
det_exact: 16x (D=2) → 39x (D=5) faster
det_exact_f64: 10x (D=2) → 38x (D=5) faster
det_sign_exact: 40x at D=5 (bypasses BigRational entirely)
Near-singular: 18x faster

Summary by CodeRabbit

  • Documentation
    • Added GitHub CLI best practices for safely reading and composing issues (use JSON output with cat/jq and heredoc body usage); updated quick-reference examples.
    • Clarified determinant computation docs: exact sign uses an integer-only Bareiss pipeline based on f64 mantissa×2^exponent decomposition (avoids rational/GCD-based approach).

Replace the BigRational Bareiss determinant with a pure BigInt path:
all f64 entries are decomposed into mantissa × 2^exponent, scaled to
a common integer base, and eliminated without any rational arithmetic.
The result is reconstructed as BigRational only at the end.

- Add f64_decompose helper (extracted from f64_to_bigrational)
- Add bareiss_det_int: integer-only Bareiss returning (BigInt, i32)
- Add bigint_exp_to_bigrational: reconstruction with trailing-zero
  reduction (no full GCD needed)
- Refactor bareiss_det as thin wrapper over bareiss_det_int
- Optimize det_sign_exact to read sign from BigInt directly
  (skip BigRational reconstruction entirely)
- Import std::array::from_fn for shorter call sites
- Replace clippy cast suppression with exact try_from conversions
- Update AGENTS.md with non-interactive gh CLI patterns
- 24 new tests (256 total): f64_decompose, bareiss_det_int (D=0–5,
  fractional, all-zeros, sign), bigint_exp_to_bigrational (positive/
  negative exp, reduction, negative values)

Performance (vs pre-bigint baseline on Apple M4 Max):
  det_exact:      16x (D=2) → 39x (D=5) faster
  det_exact_f64:  10x (D=2) → 38x (D=5) faster
  det_sign_exact: 40x at D=5 (bypasses BigRational entirely)
  Near-singular:  18x faster

Co-Authored-By: Oz <oz-agent@warp.dev>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b4ed6ed-1a50-4a8b-a0b3-7adc88a21f9f

📥 Commits

Reviewing files that changed from the base of the PR and between d422b25 and 2ee3f05.

📒 Files selected for processing (3)
  • AGENTS.md
  • REFERENCES.md
  • src/exact.rs
✅ Files skipped from review due to trivial changes (2)
  • REFERENCES.md
  • src/exact.rs

📝 Walkthrough

Walkthrough

This PR replaces the BigRational-backed Bareiss determinant path with an integer-only Bareiss pipeline using f64 decomposition to mantissa/exponent, updates det_sign_exact to use the integer determinant sign, modernizes some array construction, expands tests, and adds GitHub CLI guidance in AGENTS.md (plus a small REFERENCES.md clarification).

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md, REFERENCES.md
Added GitHub CLI (gh) guidance (use `--json ...
Exact arithmetic & tests
src/exact.rs
Introduced f64_decompose and reworked f64→rational behavior; added bareiss_det_int (integer-only Bareiss returning (BigInt, exp)), bigint_exp_to_bigrational and kept bareiss_det as a wrapper. Updated Matrix::<D>::det_sign_exact fallback to use integer sign, switched to std::array::from_fn usage, and expanded unit tests for decomposition and integer Bareiss behaviors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

documentation, enhancement, performance, rust, testing

Poem

🐰 I nibble bits of mantissa and power,

shifting twos in moonlit hour.
BigInt carrots, Bareiss in hand—
exact signs hop across the land. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf: integer-only Bareiss determinant via BigInt (#64)' directly and specifically describes the main optimization introduced in this PR: replacing BigRational-based Bareiss determinant computation with a pure BigInt approach.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/64-bigint-bareiss-det

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.26%. Comparing base (85679b5) to head (2ee3f05).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   88.75%   90.26%   +1.51%     
==========================================
  Files           5        5              
  Lines         409      452      +43     
==========================================
+ Hits          363      408      +45     
+ Misses         46       44       -2     
Flag Coverage Δ
unittests 90.26% <100.00%> (+1.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/exact.rs (1)

189-294: ⚠️ Potential issue | 🟡 Minor

Update the public rustdoc to match the new BigInt determinant path.

The implementation now routes exact determinant/sign work through bareiss_det_int, but the module-level docs and det_sign_exact rustdoc still describe a BigRational Bareiss core. That doc drift will mislead readers about both the algorithm and where the speedup comes from.

Also applies to: 548-555

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/exact.rs` around lines 189 - 294, Update the rustdoc to reflect that
exact determinant/sign work now uses an integer-only Bareiss core via
bareiss_det_int returning (BigInt, exponent) rather than a BigRational Bareiss;
update module-level docs and the det_sign_exact function doc to mention
bareiss_det_int and bigint_exp_to_bigrational (and that bareiss_det simply wraps
these), describe the integer matrix construction and exponent accounting
(mantissa shifting to form BigInt matrix and total_exp = D * e_min), and note
this is the source of the performance improvement instead of a BigRational-based
Bareiss implementation.
🧹 Nitpick comments (1)
AGENTS.md (1)

198-198: Make gh issue list consistent with the documented --json | cat pattern.

Line 198 uses plain gh issue list while line 197 and the guidance above (line 179) recommend always using --json | cat to avoid pager and scope errors. Update for consistency:

Suggested change
-- **List**: `gh issue list` (add `--label enhancement`, `--milestone v0.4.0`, etc. to filter)
+- **List**: `gh issue list --json number,title,labels,milestone --jq '.[]' | cat` (add `--label enhancement`, `--milestone v0.4.0`, etc. to filter)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` at line 198, The example uses plain `gh issue list` which is
inconsistent with the documented pattern; update the example so `gh issue list`
includes the `--json ... | cat` usage (e.g., `gh issue list --label enhancement
--milestone v0.4.0 --json ... | cat`) to match the guidance referenced earlier
and avoid pager/scope issues; locate the `gh issue list` example and replace it
with the `--json | cat` variant while preserving the suggested flags such as
`--label` and `--milestone`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/exact.rs`:
- Around line 189-294: Update the rustdoc to reflect that exact determinant/sign
work now uses an integer-only Bareiss core via bareiss_det_int returning
(BigInt, exponent) rather than a BigRational Bareiss; update module-level docs
and the det_sign_exact function doc to mention bareiss_det_int and
bigint_exp_to_bigrational (and that bareiss_det simply wraps these), describe
the integer matrix construction and exponent accounting (mantissa shifting to
form BigInt matrix and total_exp = D * e_min), and note this is the source of
the performance improvement instead of a BigRational-based Bareiss
implementation.

---

Nitpick comments:
In `@AGENTS.md`:
- Line 198: The example uses plain `gh issue list` which is inconsistent with
the documented pattern; update the example so `gh issue list` includes the
`--json ... | cat` usage (e.g., `gh issue list --label enhancement --milestone
v0.4.0 --json ... | cat`) to match the guidance referenced earlier and avoid
pager/scope issues; locate the `gh issue list` example and replace it with the
`--json | cat` variant while preserving the suggested flags such as `--label`
and `--milestone`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b63d8d3b-6826-46aa-8c26-db5ccb7dc345

📥 Commits

Reviewing files that changed from the base of the PR and between 85679b5 and d422b25.

📒 Files selected for processing (2)
  • AGENTS.md
  • src/exact.rs

Update architecture descriptions in AGENTS.md and REFERENCES.md to
reflect the move from BigRational to integer-only BigInt arithmetic.
Add unit tests for bareiss_det_int covering negative inputs and pivot
swapping. Refine gh CLI patterns for automated issue listing.

Refs: #64
@acgetchell acgetchell linked an issue Apr 11, 2026 that may be closed by this pull request
@acgetchell acgetchell self-assigned this Apr 11, 2026
@acgetchell acgetchell merged commit c8d9712 into main Apr 11, 2026
8 checks passed
@acgetchell acgetchell deleted the perf/64-bigint-bareiss-det branch April 11, 2026 01:51
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.

perf: integer-only Bareiss determinant (BigInt path)

1 participant