Skip to content

[FIX] ASR: round half away from zero for window/bad-chan counts#116

Open
sappelhoff wants to merge 2 commits into
nbara:masterfrom
sappelhoff:fix/asr-round-half-away
Open

[FIX] ASR: round half away from zero for window/bad-chan counts#116
sappelhoff wants to merge 2 commits into
nbara:masterfrom
sappelhoff:fix/asr-round-half-away

Conversation

@sappelhoff

Copy link
Copy Markdown
Collaborator

numpy's np.round (banker's rounding, round-half-to-even) and Python's int() truncation diverge from MATLAB's round-half-away-from-zero at exact-half inputs, giving ±1 counts for the bad-channel count and window length N in clean_windows and asr_calibrate. Add a _round_half_away helper and apply it at those sites.

Reachability is narrow (ties need specific channel counts or odd-integer sfreq with win_len=0.5; common rates never trigger), so this mainly hardens the edge cases.

Testing

Added a helper unit test covering ties (2.5→3, 128.5→129, -2.5→-3), divergence from np.round, array input, and int() exactness. Full tests/test_asr.py passes; ruff clean.

numpy's np.round (banker's rounding) and int() truncation diverge from
MATLAB's round-half-away-from-zero at exact-half inputs, giving +-1 counts
for the bad-channel count and window length N in clean_windows and
asr_calibrate. Add a _round_half_away helper and apply it at those sites.
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.11%. Comparing base (3721224) to head (0daabd0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #116   +/-   ##
=======================================
  Coverage   83.10%   83.11%           
=======================================
  Files          25       25           
  Lines        2818     2819    +1     
=======================================
+ Hits         2342     2343    +1     
  Misses        476      476           

☔ View full report in Codecov by Harness.
📢 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.

nonlinear_eigenspace drew its optimization starting point from an unseeded
module-level Generator, so the riemann ASR path produced slightly different
results on every call. The starting point only affects convergence, not the
resulting eigenspace, so seed it with a fixed value. This makes the riemann
ASR output reproducible run-to-run and stabilizes the incremental-vs-bulk
equivalence check in test_asr_class.

Adds a regression test asserting repeated calls return identical results.
@sappelhoff

Copy link
Copy Markdown
Collaborator Author

Note: includes the nonlinear_eigenspace reproducibility fix from #118. test_asr_class[*-riemann] compares incremental-vs-bulk output with a loose tolerance and is flaky on CI because that path used an unseeded RNG; this can trip on any PR regardless of what it changes. #118 is the root fix — once it merges first, this commit drops out on rebase.

@sappelhoff sappelhoff mentioned this pull request Jul 14, 2026
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.

1 participant