diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3221a..1c2c0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189) * Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) * Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) +* Added thin wrappers for `fftfreq`, `rfftfreq`, `fftshift`, and `ifftshift` to `scipy_fft` interface [gh-226](https://github.com/IntelPython/mkl_fft/pull/226) ### Fixed * Fixed a bug for N-D FFTs when both `s` and `out` are given [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) diff --git a/mkl_fft/interfaces/_scipy_fft.py b/mkl_fft/interfaces/_scipy_fft.py index 77429c7..910f652 100644 --- a/mkl_fft/interfaces/_scipy_fft.py +++ b/mkl_fft/interfaces/_scipy_fft.py @@ -36,6 +36,7 @@ import mkl import numpy as np +import scipy import mkl_fft @@ -61,6 +62,10 @@ "ihfft2", "hfftn", "ihfftn", + "fftshift", + "ifftshift", + "fftfreq", + "rfftfreq", "get_workers", "set_workers", ] @@ -650,6 +655,49 @@ def ihfftn( return result +# define thin wrappers for scipy functions to avoid circular dependencies +def fftfreq(n, d=1.0, *, xp=None, device=None): + """ + Return the Discrete Fourier Transform sample frequencies. + + For full documentation refer to `scipy.fft.fftfreq`. + + """ + return scipy.fft.fftfreq(n, d=d, xp=xp, device=device) + + +def rfftfreq(n, d=1.0, *, xp=None, device=None): + """ + Return the Discrete Fourier Transform sample frequencies (for usage with + `rfft`, `irfft`). + + For full documentation refer to `scipy.fft.rfftfreq`. + + """ + return scipy.fft.rfftfreq(n, d=d, xp=xp, device=device) + + +def fftshift(x, axes=None): + """ + Shift the zero-frequency component to the center of the spectrum. + + For full documentation refer to `scipy.fft.fftshift`. + + """ + return scipy.fft.fftshift(x, axes=axes) + + +def ifftshift(x, axes=None): + """ + The inverse of `fftshift`. Although identical for even-length `x`, the + functions differ by one sample for odd-length `x`. + + For full documentation refer to `scipy.fft.ifftshift`. + + """ + return scipy.fft.ifftshift(x, axes=axes) + + def get_workers(): """ Gets the number of workers used by mkl_fft by default. diff --git a/mkl_fft/interfaces/scipy_fft.py b/mkl_fft/interfaces/scipy_fft.py index c3ae471..4adce52 100644 --- a/mkl_fft/interfaces/scipy_fft.py +++ b/mkl_fft/interfaces/scipy_fft.py @@ -24,15 +24,13 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# Added for completing the namespaces -from scipy.fft import fftfreq, fftshift, ifftshift, rfftfreq - # pylint: disable=no-name-in-module from ._scipy_fft import ( fft, fft2, + fftfreq, fftn, + fftshift, get_workers, hfft, hfft2, @@ -40,6 +38,7 @@ ifft, ifft2, ifftn, + ifftshift, ihfft, ihfft2, ihfftn, @@ -48,6 +47,7 @@ irfftn, rfft, rfft2, + rfftfreq, rfftn, set_workers, )