rocket-fft extends Numba by scipy.fft and numpy.fft
Project description
rocket-fft
Rocket-FFT makes Numba aware of numpy.fft
and scipy.fft
. Rocket-FFT takes its name from the PocketFFT Fast Fourier Transformation library that powers it, and Numba's goal of making your scientific Python code blazingly fast - like a rocket 🚀.
Rocket-FFT has been tested against both the SciPy and Numpy test suites, plus some additional typing tests. Therefore, it is considered safe to use, but the author still welcomes bug reports to help improve the project.
Getting started
The easiest way to get Rocket-FFT is to pip install rocket-fft
. Alternatively, you can build it yourself by cloning this repository and running pip install .
. The latter will require a C++ compiler to be installed on your system.
Rocket-FFT uses setuptools entry points to register itself as an extension of Numba, so there is no need for additional imports. Once installed, you can use it in your code like this:
import numba as nb
import numpy as np
@nb.njit
def jit_fft(x):
return np.fft.fft(x)
Supported Numpy functions
The whole numpy.fft
module is supported, which contains all the functions listed below:
-
numpy.fft.fft
-
numpy.fft.ifft
-
numpy.fft.fft2
-
numpy.fft.ifft2
-
numpy.fft.fftn
-
numpy.fft.ifftn
-
numpy.fft.rfft
-
numpy.fft.irfft
-
numpy.fft.rfft2
-
numpy.fft.irfft2
-
numpy.fft.rfftn
-
numpy.fft.irfftn
-
numpy.fft.hfft
-
numpy.fft.ihfft
-
numpy.fft.fftfreq
-
numpy.fft.rfftfreq
-
numpy.fft.fftshift
-
numpy.fft.ifftshift
Supported SciPy functions
Most of the scipy.fft
module is supported as well, including:
-
scipy.fft.fft
-
scipy.fft.ifft
-
scipy.fft.fft2
-
scipy.fft.ifft2
-
scipy.fft.fftn
-
scipy.fft.ifftn
-
scipy.fft.rfft
-
scipy.fft.irfft
-
scipy.fft.rfft2
-
scipy.fft.irfft2
-
scipy.fft.rfftn
-
scipy.fft.irfftn
-
scipy.fft.hfft
-
scipy.fft.ihfft
-
scipy.fft.hfft2
-
scipy.fft.ihfft2
-
scipy.fft.hfftn
-
scipy.fft.ihfftn
-
scipy.fft.dct
-
scipy.fft.dct2
-
scipy.fft.dctn
-
scipy.fft.idctn
-
scipy.fft.dst
-
scipy.fft.idst
-
scipy.fft.dstn
-
scipy.fft.idstn
-
scipy.fft.fht
-
scipy.fft.ifht
-
scipy.fft.fftshift
-
scipy.fft.ifftshift
-
scipy.fft.fftfreq
-
scipy.fft.ifftfreq
-
scipy.fft.fhtoffset
-
scipy.fft.next_fast_len
Type conversion
By default, Rocket-FFT follows SciPy's approach to type conversion. However, if you would like to use Numpy's approach instead, you can do so by calling the numpy_like
function from the rocket_fft module, like this:
from rocket_fft import numpy_like
numpy_like()
It is also possible to undo this change and switch back to the SciPy approach by calling the scipy_like
function. Keep in mind that this change must be made before the internal functions of Rocket-FFT are compiled, as the type conversion rule is frozen upon compilation.
Compilation time
Rocket-FFT uses several techniques to keep compilation times low, despite the flexible signatures of the scipy.fft
and numpy.fft
functions. One of the key strategies is to do as much work as possible at compile time. This allows Rocket-FFT to keep compilation times at a few hundred milliseconds. Calls with default arguments are handled specially and therefore compile the fastest
Limitations on Linux and MacOS
Rocket-FFT uses a C-interface that is wrapped with ctypes
on Linux and MacOS, due to an unresolved issue related to LLVM. As a result, all functions are not cacheable. However, on Windows the functions are cached without any issues.
Low-level interface
If you don't need the convenience of the flexible signatures provided by SciPy and Numpy, you can use the low-level Pocketfft interface instead. Using the low-level interface can significantly reduce compilation times and has less overhead. Additionally, it offers some additional functions that are not available through the Scipy and Numpy interfaces. It is an option to consider if you prioritize speed on small transforms and have a good understanding of how to use FFT. You can use it like this:
from rocket_fft import c2c
c2c(...)
The low-level interface implements the following functions:
from numpy import complex64, complex128, float32, float64, int64, ndarray
# Note that single and double precision can't be mixed
complex_array = ndarray[complex64] | ndarray[complex128]
real_array = ndarray[float32] | ndarray[float64]
def c2c(ain: complex_array, aout: real_array, axes: ndarray[int64], forward: bool, fct: float64, nthreads: int64): ...
def r2c(ain: real_array, aout: complex_array, axes: ndarray[int64], forward: bool, fct: float64, nthreads: int64): ...
def c2r(ain: complex_array, aout: real_array, axes: ndarray[int64], forward: bool, fct: float64, nthreads: int64): ...
# Like c2c but on real-valued input array and thus using symmetry
def c2c_sym(ain: real_array, aout: complex_array, axes: ndarray[int64], forward: bool, fct: float64, nthreads: int64): ...
def dst(ain: real_array, aout: real_array, axes: ndarray[int64], type: int64, fct: float64, ortho: bool, nthreads: int64): ...
def dct(ain: real_array, aout: real_array, axes: ndarray[int64], type: int64, fct: float64, ortho: bool, nthreads: int64): ...
def separable_hartley(ain: real_array, aout: real_array, axes: ndarray[int64], fct: float64, nthreads: int64): ...
def genuine_hartley(ain: real_array, aout: real_array, axes: ndarray[int64], fct: float64, nthreads: int64): ...
def fftpack(ain: real_array, aout: real_array, axes: ndarray[int64], real2hermitian: bool, forward: bool, fct: float64, nthreads: int64): ...
def good_size(target: int64, real: bool): ...
It's important to note that the low-level Pocketfft interface does not provide the same level of safety and convenience as SciPy and Numpy. There is no safety net, and it is up to the user to ensure proper usage. You may need to refer to the original Pocketfft C++ implementation to understand how to use the functions properly. It is recommended to be familiar with the usage of FFT before using the low-level interface to avoid errors.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for rocket_fft-0.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f50188263c762436ee5e1d27ff147f50173304235427c199a66275fdd48305d |
|
MD5 | 85fd7d92b56c0cbc63e784637bb7248e |
|
BLAKE2b-256 | 949c22cca3190bbdb095af2484a34c04db6bc9a94482b4a9c7d7ba201ac988c5 |
Hashes for rocket_fft-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87311239cc543f58b443750727b7422de748c1355cc87a2049968b9352e8dc33 |
|
MD5 | 5def7d5be56a943b7674a6bcd0480e98 |
|
BLAKE2b-256 | de31f344a93f3c48238117677dcfdc21267437387959e639dc9ce8cfc24ca2f6 |
Hashes for rocket_fft-0.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1131759cf752fcfbbc05ea36ae2a0e5d4f4c7eb064aa5bd74aa008eb8b0445a |
|
MD5 | 1a7b20e3c27c3073ee64ae373c876243 |
|
BLAKE2b-256 | e08b2275069dfea72410ee719284ffb1288d72c6ff765de48cefab566b874d78 |
Hashes for rocket_fft-0.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a435377510d50d780c877c8582f7b3df79c555dfb02eafcdc74581b5853fc822 |
|
MD5 | 4ad30f946f4a3132fcdca0fba28db96f |
|
BLAKE2b-256 | 0f8cfb99b5f4a6ebc7adafc97d7626f38ffaf986f4c6baf343555f471526baff |
Hashes for rocket_fft-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 215c353133f512b082405414e6792a2d31021ed6475546d38df27054cc8b1bf9 |
|
MD5 | a319606dcf8aaea0e4e847acf9ddc052 |
|
BLAKE2b-256 | 2b900f9377e8dd2f7e7c9b56488f1a9e706db5b8764c2477103c824b53e5e872 |
Hashes for rocket_fft-0.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe557f432a55e4031197ebee7290512d7689ee7ec5ad158adac7e6a03365ff5d |
|
MD5 | 477ed8dcd95ecc65efb2459a6d84cd55 |
|
BLAKE2b-256 | 61b49b386b669d108f522bd2926a4dc43cf17c35569425befb1de318d64416aa |
Hashes for rocket_fft-0.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbbe605000b991523459cd6fe9a56e56e76ee3442321b3426b0d2bcb56b4b613 |
|
MD5 | 5cb7dc06b329da991abad0d4773cf379 |
|
BLAKE2b-256 | 7507606b96e4e7d74607f34daad29aa24711bfb62827b9e4c86dcfc18a096c29 |
Hashes for rocket_fft-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e3cba856afc237bb15a3ed9375bf32b4c3dc71701f0f6d2afc0296854e5fe0 |
|
MD5 | f78c284ea391a78f74cae17979554da9 |
|
BLAKE2b-256 | cdc2c79d8414e06aa546ea804468139e63dea5c3582930a7f9538dd31322d5ba |
Hashes for rocket_fft-0.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b6609e57f7f66de8410a0f976689fefd8d20ba4cfb5438b33f682965bb23169 |
|
MD5 | a449ccbcc99d16ca6c6aeed343974b56 |
|
BLAKE2b-256 | 513c6f32d0cf6c5b10a7628850fac3335c55fbf3833df5f346883a89b821ff66 |