Skip to content

Commit b2657e2

Browse files
authored
Add Hermitian FFT to scipy interface (#161)
* include hfft * add docsting
1 parent 43f137d commit b2657e2

File tree

6 files changed

+456
-85
lines changed

6 files changed

+456
-85
lines changed

CHANGES.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
:code:`mkl_fft` changelog
33
=========================
44

5-
1.3.14 (04/10/2025)
5+
[dev] (MM/DD/YY)
6+
==================
7+
8+
scipy interface :code:`mkl_fft.interfaces.scipy_fft` now includes Hermitian FFT functions:
9+
:code:`hfft`, :code:`ihfft`, :code:`hfftn`, :code:`ihfftn`, :code:`hfft2`, and :code:`ihfft2`
10+
11+
1.3.14 (04/11/2025)
612
===================
713

814
resolves gh-152 by adding an explicit :code:`mkl-service` dependency to :code:`mkl-fft` when building the wheel

mkl_fft/_fft_utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import numpy as np
2828

29-
__all__ = ["_check_norm", "_compute_fwd_scale"]
29+
__all__ = ["_check_norm", "_compute_fwd_scale", "_swap_direction"]
3030

3131

3232
def _check_norm(norm):
@@ -49,3 +49,15 @@ def _compute_fwd_scale(norm, n, shape):
4949
return fsc
5050
else: # norm == "ortho"
5151
return np.sqrt(fsc)
52+
53+
54+
def _swap_direction(norm):
55+
_check_norm(norm)
56+
_swap_direction_map = {
57+
"backward": "forward",
58+
None: "forward",
59+
"ortho": "ortho",
60+
"forward": "backward",
61+
}
62+
63+
return _swap_direction_map[norm]

mkl_fft/_numpy_fft.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
import numpy as np
7777

7878
from . import _pydfti as mkl_fft # pylint: disable=no-name-in-module
79-
from ._fft_utils import _check_norm, _compute_fwd_scale
79+
from ._fft_utils import _compute_fwd_scale, _swap_direction
8080
from ._float_utils import _downcast_float128_array
8181

8282

@@ -124,18 +124,6 @@ def _cook_nd_args(a, s=None, axes=None, invreal=False):
124124
return s, axes
125125

126126

127-
def _swap_direction(norm):
128-
_check_norm(norm)
129-
_swap_direction_map = {
130-
"backward": "forward",
131-
None: "forward",
132-
"ortho": "ortho",
133-
"forward": "backward",
134-
}
135-
136-
return _swap_direction_map[norm]
137-
138-
139127
def trycall(func, args, kwrds):
140128
try:
141129
res = func(*args, **kwrds)
@@ -604,7 +592,7 @@ def hfft(a, n=None, axis=-1, norm=None):
604592

605593
norm = _swap_direction(norm)
606594
x = _downcast_float128_array(a)
607-
x = np.array(x, copy=True, dtype=complex)
595+
x = np.array(x, copy=True)
608596
np.conjugate(x, out=x)
609597
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
610598

@@ -671,10 +659,8 @@ def ihfft(a, n=None, axis=-1, norm=None):
671659
672660
"""
673661

674-
# The copy may be required for multithreading.
675662
norm = _swap_direction(norm)
676663
x = _downcast_float128_array(a)
677-
x = np.array(x, copy=True, dtype=float)
678664
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
679665

680666
output = trycall(

0 commit comments

Comments
 (0)