Skip to content

istft handle noverlap=0 and use resolved nfft_int - #38319

Open
leopozh wants to merge 1 commit into
jax-ml:mainfrom
leopozh:fix-istft-noverlap
Open

leopozh wants to merge 1 commit into
jax-ml:mainfrom
leopozh:fix-istft-noverlap

Conversation

@leopozh

@leopozh leopozh commented Jun 9, 2026

Copy link
Copy Markdown

Fixes #38315

istft resolves the overlap with noverlap or nperseg_int // 2, so an explicit noverlap=0 (a valid value) is treated as unset and is replaced by the nperseg // 2 default, producing a wrong reconstruction that diverges from SciPy

Its inverse FFT is called with the raw nfft instead of the resolved nfft_int, so a one-sided transform with nfft=None and an odd nperseg drops the length correction and crashes with a broadcasting error

Also added some tests for it

(Caught a test tolerance issue where float64/complex128 cases used a flat rtol/atol=1e-4. With JAX x64 disabled, those inputs downcast to float32, making the tolerance mislabeled and too loose for true float64. Switched to dtype-specific tolerances: 1e-6 for float64/complex128 and 1e-4 for float32/complex64, matching the existing istft test behavior before submitting this pr)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request fixes two issues in the istft implementation in jax/_src/scipy/signal.py. First, it ensures that noverlap=0 is honored instead of being overridden by the default nperseg // 2. Second, it uses nfft_int instead of nfft when performing the inverse FFT, resolving an issue when nfft is None and nperseg is odd. Corresponding unit tests have been added to verify these fixes. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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.

istft handling of nooverlap=0 and nfft_int

1 participant