Skip to content

FIX: Limit NaN propagation during overlap-add FIR filtering - #14614

Merged
larsoner merged 4 commits into
mne-tools:mainfrom
VivinAT04:fix/fir-nan-propagation-12375
Dec 2, 2026
Merged

larsoner merged 4 commits into
mne-tools:mainfrom
VivinAT04:fix/fir-nan-propagation-12375

Conversation

@VivinAT04

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Fixes #12375.

What does this implement/fix?

This addresses excessive NaN propagation during
overlap-add FIR filtering.

The implementation uses finite-support validity masking
to prevent non-finite input samples from contaminating
entire FFT blocks while retaining the existing FFT-based
filtering approach.

Testing and validation

  • Reduced NaN propagation from 3478 to 456 samples.
  • Preserved 3022 additional valid samples.
  • 359 tests passed, 2 skipped.
  • No numerical differences on tested clean signals.
  • Approximately 1.62% performance overhead when
    filtering one million clean samples.
  • Ruff linting and formatting checks passed.

Additional information

  • Tested on macOS ARM64 using Python 3.13.18.
  • Positive and negative infinity are treated as NaN.
  • CUDA and MNE-C testing remain outstanding.

AI assistance

AI assisted with bug investigation, code
implementation and regression test development.
The tests were executed and the results were
verified locally on macOS.

@larsoner

larsoner commented Dec 1, 2026

Copy link
Copy Markdown
Member

@VivinAT04 it looks like your PR description was likely copy-pasted from an LLM, please keep in mind all interactions should be in your own words

I think this makes sense but I suspect the code could be DRY'ed with the recent resampling code with a helper, and the tests seem much longer than needed, can you look?

@VivinAT04

VivinAT04 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Eric, Thankyou so much for reviewing the Pull Request. Sorry for sounding like LLM, I used them to structure the original PR description so it can be easier for you to understand quicker. I gone through the documentation and may sure i don't repeat this again. Am so sorry. I will writer future interactions in my own words as you said.

I looked at the existing FFT resampling implementation and the extracted common Not a number (NAN) window detection logic into a shared helper function called _nan_window_mask(). Both FIR filtering and FFT sampling now uses this helper function.

I also simplified the regression tests from 64 to 19 cases. The local test runs resulted in 314 passed.

Thanks for your guidance

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Trimmed the test to be more compact, marking for merge, thanks @VivinAT04 !

@larsoner
larsoner enabled auto-merge (squash) December 2, 2026 16:21
@larsoner
larsoner disabled auto-merge December 2, 2026 17:37
@larsoner
larsoner merged commit bda1b9a into mne-tools:main Dec 2, 2026
24 checks passed
@welcome

welcome Bot commented Dec 2, 2026

Copy link
Copy Markdown

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@VivinAT04

Copy link
Copy Markdown
Contributor Author

Thanks, Eric, for reviewing my contribution and simplifying the tests. I appreciate your guidance throughout the process. Happy to have my first contribution merged, and I look forward to contributing more to MNE!

larsoner added a commit to larsoner/mne-python that referenced this pull request Dec 2, 2026
* upstream/main:
  FIX: Limit NaN propagation during overlap-add FIR filtering (mne-tools#14614)
  ENH: Add save() to ConductorModel and InverseOperator (mne-tools#14612)
  FIX: Make minimum-phase firwin2 high-pass filters work with even filter lengths (mne-tools#14627)
  DOC: Note that cap montages do not line up with fsaverage in template-MRI tutorial (mne-tools#14628)
  DOC: Say adjacency=None is rarely right for sensor or source data in cluster tests (mne-tools#14629)
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.

Highpass filter and NaNs result in long NaN segments

2 participants