Skip to content

Commit 0baa8b8

Browse files
committed
replace fwd_scale with norm kwarg in mkl_fft
1 parent 31e17ab commit 0baa8b8

File tree

7 files changed

+78
-163
lines changed

7 files changed

+78
-163
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [2.0.0] (05/DD/2025)
7+
## [2.0.0] (06/DD/2025)
88

99
### Added
1010
* Added Hermitian FFT functions to SciPy interface `mkl_fft.interfaces.scipy_fft`: `hfft`, `ihfft`, `hfftn`, `ihfftn`, `hfft2`, and `ihfft2` [gh-161](https://github.com/IntelPython/mkl_fft/pull/161)
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* SciPy interface `mkl_fft.interfaces.scipy_fft` uses the same function from SciPy for handling `s` and `axes` for N-D FFTs [gh-181](https://github.com/IntelPython/mkl_fft/pull/181)
1818
* Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
1919
* Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
20+
* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189)
2021

2122
### Fixed
2223
* Fixed a bug in `mkl_fft.interfaces.numpy.fftn` when an empty tuple is passed for `axes` [gh-139](https://github.com/IntelPython/mkl_fft/pull/139)

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ While using the interfaces module is the recommended way to leverage `mk_fft`, o
5252

5353
### complex-to-complex (c2c) transforms:
5454

55-
`fft(x, n=None, axis=-1, fwd_scale=1.0, out=None)` - 1D FFT, similar to `numpy.fft.fft`
55+
`fft(x, n=None, axis=-1, norm=None, out=None)` - 1D FFT, similar to `numpy.fft.fft`
5656

57-
`fft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None)` - 2D FFT, similar to `numpy.fft.fft2`
57+
`fft2(x, s=None, axes=(-2, -1), norm=None, out=None)` - 2D FFT, similar to `numpy.fft.fft2`
5858

59-
`fftn(x, s=None, axes=None, fwd_scale=1.0, out=None)` - ND FFT, similar to `numpy.fft.fftn`
59+
`fftn(x, s=None, axes=None, norm=None, out=None)` - ND FFT, similar to `numpy.fft.fftn`
6060

6161
and similar inverse FFT (`ifft*`) functions.
6262

6363
### real-to-complex (r2c) and complex-to-real (c2r) transforms:
6464

65-
`rfft(x, n=None, axis=-1, fwd_scale=1.0, out=None)` - r2c 1D FFT, similar to `numpy.fft.rfft`
65+
`rfft(x, n=None, axis=-1, norm=None, out=None)` - r2c 1D FFT, similar to `numpy.fft.rfft`
6666

67-
`rfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None)` - r2c 2D FFT, similar to `numpy.fft.rfft2`
67+
`rfft2(x, s=None, axes=(-2, -1), norm=None, out=None)` - r2c 2D FFT, similar to `numpy.fft.rfft2`
6868

69-
`rfftn(x, s=None, axes=None, fwd_scale=1.0, out=None)` - r2c ND FFT, similar to `numpy.fft.rfftn`
69+
`rfftn(x, s=None, axes=None, norm=None, out=None)` - r2c ND FFT, similar to `numpy.fft.rfftn`
7070

7171
and similar inverse c2r FFT (`irfft*`) functions.
7272

mkl_fft/_fft_utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,12 @@ def _init_nd_shape_and_axes(x, shape, axes):
198198
raise ValueError("when given, shape values must be integers")
199199
if axes.shape != shape.shape:
200200
raise ValueError(
201-
"when given, axes and shape arguments"
202-
" have to be of the same length"
201+
"when given, axes and shape arguments have to be of the same length"
203202
)
204203

205204
shape = np.where(shape == -1, np.array(x.shape)[axes], shape)
206-
207205
if shape.size != 0 and (shape < 1).any():
208-
raise ValueError(
209-
"invalid number of data points ({0}) specified".format(shape)
210-
)
206+
raise ValueError(f"invalid number of data points ({shape}) specified")
211207

212208
return shape, axes
213209

@@ -319,7 +315,7 @@ def _pad_array(arr, s, axes):
319315
try:
320316
shp_i = arr_shape[ai]
321317
except IndexError:
322-
raise ValueError("Invalid axis (%d) specified" % ai)
318+
raise ValueError(f"Invalid axis {ai} specified")
323319
if si > shp_i:
324320
no_padding = False
325321
pad_widths[ai] = (0, si - shp_i)
@@ -355,7 +351,7 @@ def _trim_array(arr, s, axes):
355351
try:
356352
shp_i = arr_shape[ai]
357353
except IndexError:
358-
raise ValueError("Invalid axis (%d) specified" % ai)
354+
raise ValueError(f"Invalid axis {ai} specified")
359355
if si < shp_i:
360356
no_trim = False
361357
ind[ai] = slice(None, si, None)

mkl_fft/_mkl_fft.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
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-
from ._fft_utils import _c2c_fftnd_impl, _c2r_fftnd_impl, _r2c_fftnd_impl
27+
from ._fft_utils import (
28+
_c2c_fftnd_impl,
29+
_c2r_fftnd_impl,
30+
_compute_fwd_scale,
31+
_r2c_fftnd_impl,
32+
)
2833

2934
# pylint: disable=no-name-in-module
3035
from ._pydfti import _c2c_fft1d_impl, _c2r_fft1d_impl, _r2c_fft1d_impl
@@ -45,57 +50,57 @@
4550
]
4651

4752

48-
def fft(x, n=None, axis=-1, fwd_scale=1.0, out=None):
49-
return _c2c_fft1d_impl(
50-
x, n=n, axis=axis, out=out, direction=+1, fsc=fwd_scale
51-
)
53+
def fft(x, n=None, axis=-1, norm=None, out=None):
54+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
55+
return _c2c_fft1d_impl(x, n=n, axis=axis, out=out, direction=+1, fsc=fsc)
5256

5357

54-
def ifft(x, n=None, axis=-1, fwd_scale=1.0, out=None):
55-
return _c2c_fft1d_impl(
56-
x, n=n, axis=axis, out=out, direction=-1, fsc=fwd_scale
57-
)
58+
def ifft(x, n=None, axis=-1, norm=None, out=None):
59+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
60+
return _c2c_fft1d_impl(x, n=n, axis=axis, out=out, direction=-1, fsc=fsc)
5861

5962

60-
def fft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None):
61-
return fftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
63+
def fft2(x, s=None, axes=(-2, -1), norm=None, out=None):
64+
return fftn(x, s=s, axes=axes, norm=norm, out=out)
6265

6366

64-
def ifft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None):
65-
return ifftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
67+
def ifft2(x, s=None, axes=(-2, -1), norm=None, out=None):
68+
return ifftn(x, s=s, axes=axes, norm=norm, out=out)
6669

6770

68-
def fftn(x, s=None, axes=None, fwd_scale=1.0, out=None):
69-
return _c2c_fftnd_impl(
70-
x, s=s, axes=axes, out=out, direction=+1, fsc=fwd_scale
71-
)
71+
def fftn(x, s=None, axes=None, norm=None, out=None):
72+
fsc = _compute_fwd_scale(norm, s, x.shape)
73+
return _c2c_fftnd_impl(x, s=s, axes=axes, out=out, direction=+1, fsc=fsc)
7274

7375

74-
def ifftn(x, s=None, axes=None, fwd_scale=1.0, out=None):
75-
return _c2c_fftnd_impl(
76-
x, s=s, axes=axes, out=out, direction=-1, fsc=fwd_scale
77-
)
76+
def ifftn(x, s=None, axes=None, norm=None, out=None):
77+
fsc = _compute_fwd_scale(norm, s, x.shape)
78+
return _c2c_fftnd_impl(x, s=s, axes=axes, out=out, direction=-1, fsc=fsc)
7879

7980

80-
def rfft(x, n=None, axis=-1, fwd_scale=1.0, out=None):
81-
return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale)
81+
def rfft(x, n=None, axis=-1, norm=None, out=None):
82+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
83+
return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc)
8284

8385

84-
def irfft(x, n=None, axis=-1, fwd_scale=1.0, out=None):
85-
return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale)
86+
def irfft(x, n=None, axis=-1, norm=None, out=None):
87+
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
88+
return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc)
8689

8790

88-
def rfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None):
89-
return rfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
91+
def rfft2(x, s=None, axes=(-2, -1), norm=None, out=None):
92+
return rfftn(x, s=s, axes=axes, norm=norm, out=out)
9093

9194

92-
def irfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None):
93-
return irfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
95+
def irfft2(x, s=None, axes=(-2, -1), norm=None, out=None):
96+
return irfftn(x, s=s, axes=axes, norm=norm, out=out)
9497

9598

96-
def rfftn(x, s=None, axes=None, fwd_scale=1.0, out=None):
97-
return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale)
99+
def rfftn(x, s=None, axes=None, norm=None, out=None):
100+
fsc = _compute_fwd_scale(norm, s, x.shape)
101+
return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fsc)
98102

99103

100-
def irfftn(x, s=None, axes=None, fwd_scale=1.0, out=None):
101-
return _c2r_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale)
104+
def irfftn(x, s=None, axes=None, norm=None, out=None):
105+
fsc = _compute_fwd_scale(norm, s, x.shape)
106+
return _c2r_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fsc)

mkl_fft/interfaces/_numpy_fft.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import mkl_fft
3838

39-
from .._fft_utils import _compute_fwd_scale, _swap_direction
39+
from .._fft_utils import _swap_direction
4040
from ._float_utils import _downcast_float128_array
4141

4242
__all__ = [
@@ -120,10 +120,9 @@ def fft(a, n=None, axis=-1, norm=None, out=None):
120120
121121
"""
122122
x = _downcast_float128_array(a)
123-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
124123

125124
return _trycall(
126-
mkl_fft.fft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
125+
mkl_fft.fft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
127126
)
128127

129128

@@ -135,10 +134,9 @@ def ifft(a, n=None, axis=-1, norm=None, out=None):
135134
136135
"""
137136
x = _downcast_float128_array(a)
138-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
139137

140138
return _trycall(
141-
mkl_fft.ifft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
139+
mkl_fft.ifft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
142140
)
143141

144142

@@ -171,10 +169,9 @@ def fftn(a, s=None, axes=None, norm=None, out=None):
171169
"""
172170
x = _downcast_float128_array(a)
173171
s, axes = _cook_nd_args(x, s, axes)
174-
fsc = _compute_fwd_scale(norm, s, x.shape)
175172

176173
return _trycall(
177-
mkl_fft.fftn, (x,), {"s": s, "axes": axes, "fwd_scale": fsc, "out": out}
174+
mkl_fft.fftn, (x,), {"s": s, "axes": axes, "norm": norm, "out": out}
178175
)
179176

180177

@@ -187,12 +184,11 @@ def ifftn(a, s=None, axes=None, norm=None, out=None):
187184
"""
188185
x = _downcast_float128_array(a)
189186
s, axes = _cook_nd_args(x, s, axes)
190-
fsc = _compute_fwd_scale(norm, s, x.shape)
191187

192188
return _trycall(
193189
mkl_fft.ifftn,
194190
(x,),
195-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
191+
{"s": s, "axes": axes, "norm": norm, "out": out},
196192
)
197193

198194

@@ -204,10 +200,9 @@ def rfft(a, n=None, axis=-1, norm=None, out=None):
204200
205201
"""
206202
x = _downcast_float128_array(a)
207-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
208203

209204
return _trycall(
210-
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
205+
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
211206
)
212207

213208

@@ -219,12 +214,11 @@ def irfft(a, n=None, axis=-1, norm=None, out=None):
219214
220215
"""
221216
x = _downcast_float128_array(a)
222-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
223217

224218
return _trycall(
225219
mkl_fft.irfft,
226220
(x,),
227-
{"n": n, "axis": axis, "fwd_scale": fsc, "out": out},
221+
{"n": n, "axis": axis, "norm": norm, "out": out},
228222
)
229223

230224

@@ -257,12 +251,11 @@ def rfftn(a, s=None, axes=None, norm=None, out=None):
257251
"""
258252
x = _downcast_float128_array(a)
259253
s, axes = _cook_nd_args(x, s, axes)
260-
fsc = _compute_fwd_scale(norm, s, x.shape)
261254

262255
return _trycall(
263256
mkl_fft.rfftn,
264257
(x,),
265-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
258+
{"s": s, "axes": axes, "norm": norm, "out": out},
266259
)
267260

268261

@@ -276,12 +269,11 @@ def irfftn(a, s=None, axes=None, norm=None, out=None):
276269

277270
x = _downcast_float128_array(a)
278271
s, axes = _cook_nd_args(x, s, axes, invreal=True)
279-
fsc = _compute_fwd_scale(norm, s, x.shape)
280272

281273
return _trycall(
282274
mkl_fft.irfftn,
283275
(x,),
284-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
276+
{"s": s, "axes": axes, "norm": norm, "out": out},
285277
)
286278

287279

@@ -295,12 +287,10 @@ def hfft(a, n=None, axis=-1, norm=None, out=None):
295287
"""
296288
norm = _swap_direction(norm)
297289
x = _downcast_float128_array(a)
298-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
299-
300290
return _trycall(
301291
mkl_fft.irfft,
302292
(np.conjugate(x),),
303-
{"n": n, "axis": axis, "fwd_scale": fsc, "out": out},
293+
{"n": n, "axis": axis, "norm": norm, "out": out},
304294
)
305295

306296

@@ -313,10 +303,9 @@ def ihfft(a, n=None, axis=-1, norm=None, out=None):
313303
"""
314304
norm = _swap_direction(norm)
315305
x = _downcast_float128_array(a)
316-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
317306

318307
result = _trycall(
319-
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
308+
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
320309
)
321310

322311
np.conjugate(result, out=result)

0 commit comments

Comments
 (0)