Skip to content

[clean_rawdata] Silence spurious Accelerate matmul warning in Riemannian ASR - #858

Merged
arnodelorme merged 1 commit into
developfrom
agent/20261129-fix-855
Nov 29, 2026
Merged

arnodelorme merged 1 commit into
developfrom
agent/20261129-fix-855

Conversation

@claude

@claude claude Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Compute the Riemannian ASR chunk covariance with finite_matmul, as the rest of clean_rawdata already does. Apple Accelerate BLAS on macOS arm64 sets FP exception flags on finite GEMM results, so NumPy emitted a spurious divide-by-zero warning. Real non-finite products still warn, and the numbers do not change. The existing sample-data test covers it. The EEGLAB reference run has not been done yet.

Fixes #855

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Claude finished @claude[bot]'s task in 37s —— View job


Code review

  • Overall assessment: Looks good. This one-line swap in asr_process_r replaces filtered @ filtered.T with finite_matmul(filtered, filtered.T). finite_matmul runs the same left @ right on the same arrays (src/eegprep/functions/miscfunc/misc.py:42-51), so the covariance comes out bit-for-bit the same. Only the warning handling changes: warnings are suppressed when the inputs and the result are all finite, and re-raised otherwise.
  • Highest-risk area: None identified. finite_matmul was already imported (asr_process_r.py:8) and is already used for the other three products in this function (lines 143, 164, 166).
  • Merge recommendation: Safe to merge once the core-function reference-run requirement is settled (see below).

Blocking

None.

Important

None.

Nits

None.

Test gaps

None. Writing a test that reproduces this warning would need Apple Accelerate on macOS arm64. A test on Linux/OpenBLAS would pass with or without the fix, so it would not catch a regression. The numbers don't change, so the existing tests in tests/test_riemannian_asr.py and tests/test_sample_data_pop_functions.py still cover correctness.

EEGLAB parity notes

None on behavior. asr_process_r.m still divides by the full chunk length, and the existing parity comment says so. One process point: AGENTS.md asks for a MATLAB reference run (or a dispatched eeglab-reference.yml run) before merging any PR that touches a core function implementation, and the PR body says that run hasn't happened yet. The output is mathematically identical, so the run can't show a numerical difference. A maintainer can either trigger it or explicitly waive it for this warning-only change. Either way, record the decision in the PR description.

Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance.

@arnodelorme

Copy link
Copy Markdown
Collaborator

Review (Claude Fable): needs more work

  • The code is right and minimal. One line sends the last raw product of the Riemannian path through the shared helper finite_matmul. I have nothing to change in the code.
  • Checked on a Mac, which the pull request could not do. On an Apple M5 Pro the test fails on develop and passes with this change, and the cleaned data are bit identical (largest difference 0).
  • Missing before merge: the EEGLAB reference run that AGENTS.md requires for a core function (the body says it was not done), and the CI is not finished (Windows job red, the other test jobs still waiting).
Details

What I ran. macOS 26.6, Apple M5 Pro, arm64, Python 3.12.13, NumPy 2.2.6 built on Accelerate, the locked environment (uv sync --group dev).

Check develop file this pull request
test_pop_clean_rawdata_riemannian_asr_runs_on_sample_data_without_warning_noise fails, RuntimeWarning: divide by zero encountered in matmul at asr_process_r.py:127 passes
Cleaned data of that call (32 x 30504) reference np.array_equal is True, largest difference 0
tests/test_riemannian_asr.py, test_sample_data_pop_functions.py, test_clean_asr.py, test_clean_rawdata.py not run 143 passed, 1 skipped (MATLAB not available)

Is the warning really false? Yes. I looked at the 31 covariance products of that test (32 x 985 or 32 x 986). Each one raises three warnings on this Mac (divide by zero, overflow, invalid value). The inputs are all finite, with no zero and no subnormal value, and sizes between 1e-4 and 483. The results are all finite. They agree with the same product computed without BLAS (np.einsum, optimize=False) to 3.5e-15 in relative terms. So the numbers are right and only the warning is wrong. This is the comparison that issue #855 asked for before silencing anything.

Graphics and histogram. No window changes, so no capture is needed. No number changes (difference exactly 0), so a histogram would show nothing.

Code.

  • finite_matmul (miscfunc/misc.py:42) runs the same left @ right and gives the warnings back when an input or the result is not finite. A real overflow still shows.
  • Lines 143, 164 and 166 of the same function already use it. The only other raw @ in clean_rawdata is private/riemann.py:110, in a branch that ASR does not take. The claim "last raw product" holds.
  • Shared cause: the cause sits in NumPy with Accelerate, not in EEGPrep. The shared helper already exists and the change uses it, so this is the right level.
  • EEGLAB: asr_process_r.m line 154 is SCM = (1/S) * (X * X'). The Python line computes the same thing and the change does not touch it.

What is needed.

  1. Run the EEGLAB reference workflow on this branch (eeglab-reference.yml, or one local MATLAB run) and put the command, the two commits, the pass, fail and skip counts and the runtime in the body. The numbers cannot change here, so Arno may prefer to waive it, but the rule in AGENTS.md has no exception.
  2. Wait for the CI. The Windows job is red and its log could not be read while the run was still going. The last develop run (46199309201) has the same job red for tests/test_guifunc_primitives.py::test_window_without_a_height_is_as_high_as_its_rows (57 against 56), a window test with no link to this change. Confirm it is the same failure here.
  3. Correct the body. "macOS arm64" is too wide: the macOS job of the CI passes on develop, so that runner does not show the warning. It shows on this Apple M5 Pro. Say on which machine it was seen and add the Mac result above. The consequence is that the CI cannot guard this fix. I agree that no new test is useful (it would pass on Linux with or without the fix).

Other open pull requests. docs/source/changelog.rst conflicts with #835 and #797, since all three add an entry at the top of "Unreleased". Whichever merges later needs a small rebase. It merges cleanly with develop (1a74fb9) and with #850. No other open pull request touches asr_process_r.py.

Outside this pull request. With -W error::RuntimeWarning, tests/test_riemannian_asr.py has 7 failures on this Mac, the same on develop and here. They come from raw @ in the test file (lines 53, 69, 87) and from miscfunc/pinv.py:35 when the test calls pinv directly (line 134). The product code calls it through finite_pinv, and the tests pass in a normal run, so nothing to do here.

— orchestrator review

…ance

Apple Accelerate BLAS on macOS arm64 sets FP exception flags on finite
GEMM results, so NumPy reported a spurious divide-by-zero warning from
asr_process_r. Fixes #855

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arnodelorme
arnodelorme force-pushed the agent/20261129-fix-855 branch from f3e2d3f to c975c69 Compare November 29, 2026 07:33
@arnodelorme
arnodelorme merged commit 2855bcf into develop Nov 29, 2026
12 checks passed
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.

pop_clean_rawdata: Riemannian ASR emits a matrix warning on the macOS sample test

1 participant