Skip to content

Add Hermitian FFT to scipy interface #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
:code:`mkl_fft` changelog
=========================

1.3.14 (04/10/2025)
[dev] (MM/DD/YY)
==================

scipy interface :code:`mkl_fft.interfaces.scipy_fft` now includes Hermitian FFT functions:
:code:`hfft`, :code:`ihfft`, :code:`hfftn`, :code:`ihfftn`, :code:`hfft2`, and :code:`ihfft2`

1.3.14 (04/11/2025)
===================

resolves gh-152 by adding an explicit :code:`mkl-service` dependency to :code:`mkl-fft` when building the wheel
Expand Down
14 changes: 13 additions & 1 deletion mkl_fft/_fft_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import numpy as np

__all__ = ["_check_norm", "_compute_fwd_scale"]
__all__ = ["_check_norm", "_compute_fwd_scale", "_swap_direction"]


def _check_norm(norm):
Expand All @@ -49,3 +49,15 @@ def _compute_fwd_scale(norm, n, shape):
return fsc
else: # norm == "ortho"
return np.sqrt(fsc)


def _swap_direction(norm):
_check_norm(norm)
_swap_direction_map = {
"backward": "forward",
None: "forward",
"ortho": "ortho",
"forward": "backward",
}

return _swap_direction_map[norm]
18 changes: 2 additions & 16 deletions mkl_fft/_numpy_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
import numpy as np

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


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


def _swap_direction(norm):
_check_norm(norm)
_swap_direction_map = {
"backward": "forward",
None: "forward",
"ortho": "ortho",
"forward": "backward",
}

return _swap_direction_map[norm]


def trycall(func, args, kwrds):
try:
res = func(*args, **kwrds)
Expand Down Expand Up @@ -604,7 +592,7 @@ def hfft(a, n=None, axis=-1, norm=None):

norm = _swap_direction(norm)
x = _downcast_float128_array(a)
x = np.array(x, copy=True, dtype=complex)
x = np.array(x, copy=True)
np.conjugate(x, out=x)
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))

Expand Down Expand Up @@ -671,10 +659,8 @@ def ihfft(a, n=None, axis=-1, norm=None):

"""

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

output = trycall(
Expand Down
Loading
Loading