Skip to content

fix: propagate NaN in Matrix::inf_norm (#85)#92

Merged
acgetchell merged 1 commit intomainfrom
fix/85-inf-norm-nan-propagation
Apr 20, 2026
Merged

fix: propagate NaN in Matrix::inf_norm (#85)#92
acgetchell merged 1 commit intomainfrom
fix/85-inf-norm-nan-propagation

Conversation

@acgetchell
Copy link
Copy Markdown
Owner

@acgetchell acgetchell commented Apr 20, 2026

Matrix::inf_norm() silently returned 0.0 for matrices containing NaN entries because NaN > max_row_sum always evaluates to false, so NaN rows were skipped entirely. This contradicts the expected mathematical behavior that any NaN entry contaminates the norm.

  • Detect NaN row sums explicitly and short-circuit to f64::NAN (marked cold_path()). Preferred f64::maximum is still unstable behind float_minimum_maximum as of Rust 1.95, so the explicit check is used instead.
  • Document NaN/Inf behavior with a new "Non-finite handling" section and a NaN doctest.
  • Add regression tests across D=2..=5 via a macro: all-NaN → NaN, single-NaN → NaN, +∞ entry → +∞.

Tests: just ci — 98 lib, 26 doc, 259 exact-feature, 101 Python, all examples, all linters/validators.

Closes #85

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of NaN values in matrix calculations to ensure proper propagation instead of being ignored in comparisons.
  • Documentation

    • Enhanced documentation specifying NaN and infinity behavior in matrix operations.
  • Tests

    • Added regression tests verifying correct handling of edge cases with NaN and infinity values.

`Matrix::inf_norm()` silently returned 0.0 for matrices containing NaN
entries because `NaN > max_row_sum` always evaluates to false, so NaN
rows were skipped entirely. This contradicts the expected mathematical
behavior that any NaN entry contaminates the norm.

- Detect NaN row sums explicitly and short-circuit to `f64::NAN`
  (marked `cold_path()`). Preferred `f64::maximum` is still unstable
  behind `float_minimum_maximum` as of Rust 1.95, so the explicit
  check is used instead.
- Document NaN/Inf behavior with a new "Non-finite handling" section
  and a NaN doctest.
- Add regression tests across D=2..=5 via a macro:
  all-NaN → NaN, single-NaN → NaN, `+∞` entry → `+∞`.

Tests: `just ci` — 98 lib, 26 doc, 259 exact-feature, 101 Python,
all examples, all linters/validators.

Closes #85

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

coderabbitai Bot commented Apr 20, 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: 4c4d22be-c341-474e-a1e2-be67f7c6cc0c

📥 Commits

Reviewing files that changed from the base of the PR and between 56973bc and 16ffa45.

📒 Files selected for processing (1)
  • src/matrix.rs

📝 Walkthrough

Walkthrough

The Matrix::<D>::inf_norm() method was updated to explicitly detect NaN row sums and return f64::NAN immediately using cold_path(), preventing silent incorrect results. Documentation expanded to specify NaN/∞ propagation semantics. Regression tests added covering all-NaN matrices, single NaN entries, and infinity propagation across dimensions 2–5.

Changes

Cohort / File(s) Summary
NaN detection and documentation
src/matrix.rs
Enhanced inf_norm() with explicit NaN row sum detection and immediate f64::NAN return via cold_path(). Updated method documentation to specify NaN/∞ propagation semantics. Added regression tests for all-NaN matrices, single NaN entries, and infinity entries across dimensions D=2–5.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A matrix once lost in the NaN,
Now returns what it should, not a plan!
No more hiding, no more lies—
The infinity now truthfully flies! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: propagate NaN in Matrix::inf_norm (#85)' accurately and concisely describes the main change: fixing NaN propagation in the inf_norm method, and references the issue number.
Linked Issues check ✅ Passed The implementation correctly addresses issue #85 by explicitly detecting NaN row sums and returning f64::NAN immediately, providing the correct behavior specified in the issue requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing NaN propagation in Matrix::inf_norm() with documentation updates and regression tests, directly addressing issue #85 with no unrelated modifications.
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 fix/85-inf-norm-nan-propagation

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 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.65%. Comparing base (56973bc) to head (16ffa45).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   88.58%   88.65%   +0.07%     
==========================================
  Files           5        5              
  Lines         482      485       +3     
==========================================
+ Hits          427      430       +3     
  Misses         55       55              
Flag Coverage Δ
unittests 88.65% <100.00%> (+0.07%) ⬆️

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.

@acgetchell
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

✅ Actions performed

Full review triggered.

@acgetchell acgetchell enabled auto-merge April 20, 2026 19:05
@acgetchell acgetchell disabled auto-merge April 20, 2026 19:06
@acgetchell acgetchell merged commit b60a734 into main Apr 20, 2026
9 checks passed
@acgetchell acgetchell deleted the fix/85-inf-norm-nan-propagation branch April 20, 2026 19:06
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.

bug: inf_norm silently returns 0.0 for matrices containing NaN

1 participant