scipy.fftpack.

next_fast_len#

scipy.fftpack.next_fast_len(target)[source]#

尋找 fft 輸入資料的下一個快速大小,用於零填充等。

SciPy 的 FFTPACK 針對基數 {2, 3, 4, 5} 具有高效的函數,因此這會傳回大於或等於 target 的質因數 2、3 和 5 的下一個合成數。(這些數字也稱為 5-smooth 數、regular 數或 Hamming 數。)

參數:
targetint

開始搜尋的長度。必須為正整數。

返回值:
outint

大於或等於 target 的第一個 5-smooth 數。

注意

在 0.18.0 版本中新增。

範例

在特定機器上,質數長度的 FFT 需要 133 毫秒

>>> from scipy import fftpack
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> min_len = 10007  # prime length is worst case for speed
>>> a = rng.standard_normal(min_len)
>>> b = fftpack.fft(a)

零填充到下一個 5-smooth 長度將計算時間縮短至 211 微秒,加速了 630 倍

>>> fftpack.next_fast_len(min_len)
10125
>>> b = fftpack.fft(a, 10125)

四捨五入到下一個 2 的冪次方並非最佳選擇,需要 367 微秒才能計算,是 5-smooth 大小的 1.7 倍

>>> b = fftpack.fft(a, 16384)