silx
silx copied to clipboard
Fix FFT norm (pyfftw & numpy)
Fixing problem on normalization of FFT
Usual normalization is on backward FFT ( ./1 on forward & ./N on backward) but we can expect to have a non-normalize FFT (with parameter normalize="none"), this option is not implemented correctly
Solution & modifications :
- numpy :
norm="backward"on FFT &norm="forward"on IFFT - pyfftw :
normalise_idft=Trueon FFT &normalise_idft=Falseon IFFT
(There is also a problem with pyfftw implementation, it does not have the expected behavior with the last version (0.13), https://github.com/pyFFTW/pyFFTW/issues/341 but the solution normally bypass this problem)
TODO
- [x] ~~requirements for numpy version ? >= 1.12 ? or different in setup.py ? (if >= 1.10, a case could be avoided in npfft.py)~~
- [ ] normalization "by hand" if numpy version do not allow normalization="none" ? or keep a warning ?
- [ ] need to be tested with both version of pyfftw 0.12 & 0.13
- [x] ~~more efficient solution than np_version in ["1.8", ...]~~
Failure on old numpy implem ? --> "backward" & "forward" keywords only for version after 1.20
================================== FAILURES =================================== ... venv_test\lib\site-packages\numpy\fft_pocketfft.py:367: in rfft if norm is not None and _unitary(norm): ... E ValueError: Invalid norm value backward, should be None or "ortho". venv_test\lib\site-packages\numpy\fft_pocketfft.py:88: ValueError
next commit fixes it
Still CI failures : ================================== FAILURES =================================== _____________________ TestMaskToolsWidget.testWithAnImage _____________________ ...
Thanks!
From what I see in requirements.txt and pyproject.toml, the minimum required numpy version is 1.12, not 1.8.
To simplify version comparison a little bit, you can use from pkg_resources import parse_version, eg. parse_version("1.10.2") > parse_version("1.8.0").
The latest CI failures seem related to GUI (happens from time to time)
Ok it seems the same for me, so I removed code that take into account version 1.8 & 1.9.
Ho ! from pkg_resources import parse_version was exactly what I was looking for. Thanks
Test fails for numpy == 1.19.5. Seems to be because not all normalization were available for this version.
Just tested on my machine:
test_normsfails withnumpy==1.19.5test_normspasses withnumpy==1.20.0
Tested with pyfftw 0.12 and 0.13.