Skip to content

Commit 3cb11f3

Browse files
authored
Merge pull request #226 from IntelPython/complete-scipy-interface-namespace
Use wrappers to complete SciPy interface namespace
2 parents c4696d2 + fb77662 commit 3cb11f3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189)
1414
* Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
1515
* Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
16+
* Added thin wrappers for `fftfreq`, `rfftfreq`, `fftshift`, and `ifftshift` to `scipy_fft` interface [gh-226](https://github.com/IntelPython/mkl_fft/pull/226)
1617

1718
### Fixed
1819
* Fixed a bug for N-D FFTs when both `s` and `out` are given [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)

mkl_fft/interfaces/_scipy_fft.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import mkl
3838
import numpy as np
39+
import scipy
3940

4041
import mkl_fft
4142

@@ -61,6 +62,10 @@
6162
"ihfft2",
6263
"hfftn",
6364
"ihfftn",
65+
"fftshift",
66+
"ifftshift",
67+
"fftfreq",
68+
"rfftfreq",
6469
"get_workers",
6570
"set_workers",
6671
]
@@ -650,6 +655,49 @@ def ihfftn(
650655
return result
651656

652657

658+
# define thin wrappers for scipy functions to avoid circular dependencies
659+
def fftfreq(n, d=1.0, *, xp=None, device=None):
660+
"""
661+
Return the Discrete Fourier Transform sample frequencies.
662+
663+
For full documentation refer to `scipy.fft.fftfreq`.
664+
665+
"""
666+
return scipy.fft.fftfreq(n, d=d, xp=xp, device=device)
667+
668+
669+
def rfftfreq(n, d=1.0, *, xp=None, device=None):
670+
"""
671+
Return the Discrete Fourier Transform sample frequencies (for usage with
672+
`rfft`, `irfft`).
673+
674+
For full documentation refer to `scipy.fft.rfftfreq`.
675+
676+
"""
677+
return scipy.fft.rfftfreq(n, d=d, xp=xp, device=device)
678+
679+
680+
def fftshift(x, axes=None):
681+
"""
682+
Shift the zero-frequency component to the center of the spectrum.
683+
684+
For full documentation refer to `scipy.fft.fftshift`.
685+
686+
"""
687+
return scipy.fft.fftshift(x, axes=axes)
688+
689+
690+
def ifftshift(x, axes=None):
691+
"""
692+
The inverse of `fftshift`. Although identical for even-length `x`, the
693+
functions differ by one sample for odd-length `x`.
694+
695+
For full documentation refer to `scipy.fft.ifftshift`.
696+
697+
"""
698+
return scipy.fft.ifftshift(x, axes=axes)
699+
700+
653701
def get_workers():
654702
"""
655703
Gets the number of workers used by mkl_fft by default.

mkl_fft/interfaces/scipy_fft.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@
2424
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
28-
# Added for completing the namespaces
29-
from scipy.fft import fftfreq, fftshift, ifftshift, rfftfreq
30-
3127
# pylint: disable=no-name-in-module
3228
from ._scipy_fft import (
3329
fft,
3430
fft2,
31+
fftfreq,
3532
fftn,
33+
fftshift,
3634
get_workers,
3735
hfft,
3836
hfft2,
3937
hfftn,
4038
ifft,
4139
ifft2,
4240
ifftn,
41+
ifftshift,
4342
ihfft,
4443
ihfft2,
4544
ihfftn,
@@ -48,6 +47,7 @@
4847
irfftn,
4948
rfft,
5049
rfft2,
50+
rfftfreq,
5151
rfftn,
5252
set_workers,
5353
)

0 commit comments

Comments
 (0)