Skip to content

ENH: use real FFTs for real-valued CWT convolution - #864

Open
ChS-YHWH wants to merge 1 commit into
PyWavelets:mainfrom
ChS-YHWH:enh/cwt-real-fft
Open

ENH: use real FFTs for real-valued CWT convolution#864
ChS-YHWH wants to merge 1 commit into
PyWavelets:mainfrom
ChS-YHWH:enh/cwt-real-fft

Conversation

@ChS-YHWH

Copy link
Copy Markdown

Summary

When method="fft" and both the input data and the integrated wavelet kernel are real-valued, use numpy.fft.rfft and numpy.fft.irfft instead of the full complex fft and ifft.

Complex-valued inputs or wavelets retain the existing complex FFT path. The public cwt signature, the default method="conv", coefficient shapes and dtypes, scale order, and input immutability are unchanged.

Rationale

For real-valued data and kernels, the discrete Fourier transform is conjugate-symmetric. Computing only the non-redundant half-spectrum reduces FFT work and temporary frequency-domain storage without changing the convolution being evaluated.

Validation

  • Full test suite: 1050 passed, 2 skipped.
  • 720 differential cases covering:
    • 12 shape and axis combinations;
    • float32, float64, complex64, and complex128 inputs;
    • five real and complex wavelets;
    • ordered, fractional, and non-monotonic scale sets.
  • The complex-path differential comparisons were identical.
  • Worst maximum absolute difference:
    • float64: 1.33e-14
    • float32: 4.95e-6
  • Input arrays remained unchanged.
  • Ruff checks passed.

The small differences on real-valued inputs are expected floating-point roundoff from using a mathematically equivalent FFT representation and remain within the numerical precision of the corresponding dtype.

Performance

Local median timings were collected with the baseline and candidate interleaved in one process, CPU affinity fixed to one core, and numerical library threads limited to one.

Case Baseline Candidate Speedup
Small real-valued input 2.639 ms 2.097 ms 1.259x
Existing ASV-style real 1-D case 33.628 ms 23.050 ms 1.459x
Large real-valued input 85.413 ms 61.867 ms 1.381x
Batched real-valued input 103.811 ms 71.773 ms 1.446x
Complex-wavelet control 39.360 ms 39.364 ms 1.000x

These timings are local feasibility measurements, not a cross-machine performance guarantee.

Development note

This change was developed with AI assistance and was manually reviewed by the submitter. The tests and benchmark measurements reported above were run locally during preparation.

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