From 9b6c69dbac86c78c0cd0f5aa21fb7858b120734e Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 25 Sep 2025 13:05:40 -0700 Subject: [PATCH 1/3] wrap remaining scipy functions to complete the namespace, instead of importing directly avoids circular dependencies under certain conditions --- mkl_fft/interfaces/_scipy_fft.py | 48 ++++++++++++++++++++++++++++++++ mkl_fft/interfaces/scipy_fft.py | 8 +++--- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/mkl_fft/interfaces/_scipy_fft.py b/mkl_fft/interfaces/_scipy_fft.py index 77429c7b..36007e30 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 c3ae4717..4adce522 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, ) From ff605f0bd75c69b47922ad5ba7b534e4407c2ed7 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 25 Sep 2025 13:38:04 -0700 Subject: [PATCH 2/3] add gh-226 to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3221a9..1c2c0eed 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) From fb77662cd0e4bc6aa790dd4ce35ce3e4ba8a7e4c Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 26 Sep 2025 10:41:00 -0700 Subject: [PATCH 3/3] rfftfreq docstring formatting changes --- mkl_fft/interfaces/_scipy_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkl_fft/interfaces/_scipy_fft.py b/mkl_fft/interfaces/_scipy_fft.py index 36007e30..910f6525 100644 --- a/mkl_fft/interfaces/_scipy_fft.py +++ b/mkl_fft/interfaces/_scipy_fft.py @@ -669,7 +669,7 @@ def fftfreq(n, d=1.0, *, xp=None, device=None): def rfftfreq(n, d=1.0, *, xp=None, device=None): """ Return the Discrete Fourier Transform sample frequencies (for usage with - rfft, irfft). + `rfft`, `irfft`). For full documentation refer to `scipy.fft.rfftfreq`.