New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extremely long runtimes in numpy.fft.fft (Trac #1266) #1864
Comments
@endolith wrote on 2009-11-20 |
@rgommers wrote on 2011-03-01 |
@rgommers wrote on 2011-03-01 David C. has implemented the Bluestein transform if you need it: https://github.com/cournape/numpy/tree/bluestein Should hopefully land in Numpy trunk soon. |
Milestone changed to |
in this pr a padding to small primes is proposed |
Yes, instead of |
I have also come across this issue using the detect_equilibration function of pymbar that repeatedly calls np.fft and np.ifft through statsmodels autocorrelation function on many increasingly shorter arrays. I found out profiling the code, which has ultimately led me to this thread. The only work around so far is to explicitly call np.fft.fftpack._fft_cache.clear() to make sure that the memory requirement does not grow dangerously. This does not seem to be the ideal solution though. It would be nice to have either a kwarg such as "memsafe=True" and/or a function to manually clear the cache without referring to the global variable explicitely. |
@juliantaylor Padding isn't applicable to plain FFTs, correct? Just to convolution/correlation? @rgommers The Bluestein algorithm does speed up the FFT for prime sizes, as done in scipy/scipy#4288 , but requires pre-computation of complex chirps, and is most efficient when you keep the chirp in memory and repeatedly re-use it on chunks of data. So I'm not sure if this is good for numpy and maybe just defer to scipy.fftpack.czt for this application? Anyway I think this can be closed as a duplicate of #1177 ? Unless something else like Rader's algorithm is better than Bluestein's? and @smcantab 's issue is different? |
@endolith this was a long time ago :) but yes, now that I look at it again it seems a different issue. The problem I reported might still be relevant though and I had to implement the workaround I suggested in pymbar for it to work. |
FYI, I ran in to someone at an audio conference whos showed me this example. It is easy to reproduce and extreme.
fft of length 1e6: 16 MILLIseconds fft of length 1e6 + 3: 1 MINUTE and 42 SECONDS |
Feature, not a bug. FFTPACK is only "fast" when the size factors as a product of the numbers 2, 3, 4, 5. There has been a long standing desire to use a faster algorithm for large prime sizes, but it has not been implemented. Note that 100003 is prime. |
I wouldn't call it a "feature", but it's normal and not a bug. :) scipy/scipy#4288 has Bluestein's algorithm, but it requires pre-computation of a complex chirp, so would need to do some testing to see at which prime sizes it becomes worthwhile. |
Interesting. The main thing I know is that the default fft implementation for Julia and Matlab don't have this behavior. I'm curious what the Julia implementation does to avoid this behavior. |
Julia and Matlab call FFTW, which we cannot do because of its license. |
Note that there are Python bindings for FFTW; pyFFTW seems rather current. If FFT speed is a concern, that is probably the way to go. FFTPACK was a good implementation for its day, but code and hardware have moved on. |
@charris I definitely appreciate the info and that's unfortunate, but makes sense regarding the license. |
This should be fixed in numpy 1.17. |
thanks @mreineck, closing |
Original ticket http://projects.scipy.org/numpy/ticket/1266 on 2009-10-19 by trac user koehler, assigned to unknown.
Although the documenttation of numpy.fft.fft states that:
"This is most efficient for n a power of two. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's." ,I think that it may be important to report this oddity in the fft runtime.
Dependent on the array length, the fft runtime varies really extreme:
The text was updated successfully, but these errors were encountered: