Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12de45d

Browse files
committedJun 6, 2025·
replace fwd_scale with norm kwarg in mkl_fft
1 parent 14ea458 commit 12de45d

File tree

7 files changed

+77
-165
lines changed

7 files changed

+77
-165
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Changed
1212
* Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
1313
* Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
14+
* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189)
1415

1516
### Fixed
1617
* Fixed a bug for N-D FFTs when both `s` and `out` are given [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
@@ -26,15 +27,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2627
* NumPy interface `mkl_fft.interfaces.numpy_fft` is aligned with numpy-2.x.x [gh-139](https://github.com/IntelPython/mkl_fft/pull/139), [gh-157](https://github.com/IntelPython/mkl_fft/pull/157)
2728
* To set `mkl_fft` as the backend for SciPy is only possible through `mkl_fft.interfaces.scipy_fft` [gh-179](https://github.com/IntelPython/mkl_fft/pull/179)
2829
* 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)
29-
* Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
30-
* Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
3130

3231
### Fixed
3332
* 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)
3433
* Fixed a bug for a case when a zero-size array is passed to `mkl_fft.interfaces.numpy.fftn` [gh-139](https://github.com/IntelPython/mkl_fft/pull/139)
3534
* Fixed inconsistency of input and output arrays dtype for `irfft` function [gh-180](https://github.com/IntelPython/mkl_fft/pull/180)
3635
* Fixed issues with `set_workers` function in SciPy interface `mkl_fft.interfaces.scipy_fft` [gh-183](https://github.com/IntelPython/mkl_fft/pull/183)
37-
* Fixed a bug for N-D FFTs when both `s` and `out` are given [gh-185](https://github.com/IntelPython/mkl_fft/pull/185)
3836

3937
## [1.3.14] (04/10/2025)
4038

‎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)

‎mkl_fft/interfaces/_scipy_fft.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import mkl_fft
4141

42-
from .._fft_utils import _compute_fwd_scale, _swap_direction
42+
from .._fft_utils import _swap_direction
4343
from ._float_utils import _supported_array_or_not_implemented
4444

4545
__all__ = [
@@ -235,10 +235,9 @@ def fft(
235235
_check_plan(plan)
236236
x = _validate_input(x)
237237
out = _use_input_as_out(x, overwrite_x)
238-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
239238

240239
with _Workers(workers):
241-
return mkl_fft.fft(x, n=n, axis=axis, fwd_scale=fsc, out=out)
240+
return mkl_fft.fft(x, n=n, axis=axis, norm=norm, out=out)
242241

243242

244243
def ifft(
@@ -253,10 +252,9 @@ def ifft(
253252
_check_plan(plan)
254253
x = _validate_input(x)
255254
out = _use_input_as_out(x, overwrite_x)
256-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
257255

258256
with _Workers(workers):
259-
return mkl_fft.ifft(x, n=n, axis=axis, fwd_scale=fsc, out=out)
257+
return mkl_fft.ifft(x, n=n, axis=axis, norm=norm, out=out)
260258

261259

262260
def fft2(
@@ -333,10 +331,9 @@ def fftn(
333331
x = _validate_input(x)
334332
out = _use_input_as_out(x, overwrite_x)
335333
s, axes = _init_nd_shape_and_axes(x, s, axes)
336-
fsc = _compute_fwd_scale(norm, s, x.shape)
337334

338335
with _Workers(workers):
339-
return mkl_fft.fftn(x, s=s, axes=axes, fwd_scale=fsc, out=out)
336+
return mkl_fft.fftn(x, s=s, axes=axes, norm=norm, out=out)
340337

341338

342339
def ifftn(
@@ -359,10 +356,9 @@ def ifftn(
359356
x = _validate_input(x)
360357
out = _use_input_as_out(x, overwrite_x)
361358
s, axes = _init_nd_shape_and_axes(x, s, axes)
362-
fsc = _compute_fwd_scale(norm, s, x.shape)
363359

364360
with _Workers(workers):
365-
return mkl_fft.ifftn(x, s=s, axes=axes, fwd_scale=fsc, out=out)
361+
return mkl_fft.ifftn(x, s=s, axes=axes, norm=norm, out=out)
366362

367363

368364
def rfft(
@@ -376,11 +372,10 @@ def rfft(
376372
"""
377373
_check_plan(plan)
378374
x = _validate_input(x)
379-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
380375

381376
with _Workers(workers):
382377
# Note: overwrite_x is not utilized
383-
return mkl_fft.rfft(x, n=n, axis=axis, fwd_scale=fsc)
378+
return mkl_fft.rfft(x, n=n, axis=axis, norm=norm)
384379

385380

386381
def irfft(
@@ -394,11 +389,10 @@ def irfft(
394389
"""
395390
_check_plan(plan)
396391
x = _validate_input(x)
397-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
398392

399393
with _Workers(workers):
400394
# Note: overwrite_x is not utilized
401-
return mkl_fft.irfft(x, n=n, axis=axis, fwd_scale=fsc)
395+
return mkl_fft.irfft(x, n=n, axis=axis, norm=norm)
402396

403397

404398
def rfft2(
@@ -474,11 +468,10 @@ def rfftn(
474468
_check_plan(plan)
475469
x = _validate_input(x)
476470
s, axes = _init_nd_shape_and_axes(x, s, axes)
477-
fsc = _compute_fwd_scale(norm, s, x.shape)
478471

479472
with _Workers(workers):
480473
# Note: overwrite_x is not utilized
481-
return mkl_fft.rfftn(x, s, axes, fwd_scale=fsc)
474+
return mkl_fft.rfftn(x, s, axes, norm=norm)
482475

483476

484477
def irfftn(
@@ -500,11 +493,10 @@ def irfftn(
500493
_check_plan(plan)
501494
x = _validate_input(x)
502495
s, axes = _init_nd_shape_and_axes(x, s, axes, invreal=True)
503-
fsc = _compute_fwd_scale(norm, s, x.shape)
504496

505497
with _Workers(workers):
506498
# Note: overwrite_x is not utilized
507-
return mkl_fft.irfftn(x, s, axes, fwd_scale=fsc)
499+
return mkl_fft.irfftn(x, s, axes, norm=norm)
508500

509501

510502
def hfft(
@@ -522,11 +514,10 @@ def hfft(
522514
norm = _swap_direction(norm)
523515
x = np.array(x, copy=True)
524516
np.conjugate(x, out=x)
525-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
526517

527518
with _Workers(workers):
528519
# Note: overwrite_x is not utilized
529-
return mkl_fft.irfft(x, n=n, axis=axis, fwd_scale=fsc)
520+
return mkl_fft.irfft(x, n=n, axis=axis, norm=norm)
530521

531522

532523
def ihfft(
@@ -541,11 +532,10 @@ def ihfft(
541532
_check_plan(plan)
542533
x = _validate_input(x)
543534
norm = _swap_direction(norm)
544-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
545535

546536
with _Workers(workers):
547537
# Note: overwrite_x is not utilized
548-
result = mkl_fft.rfft(x, n=n, axis=axis, fwd_scale=fsc)
538+
result = mkl_fft.rfft(x, n=n, axis=axis, norm=norm)
549539

550540
np.conjugate(result, out=result)
551541
return result
@@ -628,11 +618,10 @@ def hfftn(
628618
x = np.array(x, copy=True)
629619
np.conjugate(x, out=x)
630620
s, axes = _init_nd_shape_and_axes(x, s, axes, invreal=True)
631-
fsc = _compute_fwd_scale(norm, s, x.shape)
632621

633622
with _Workers(workers):
634623
# Note: overwrite_x is not utilized
635-
return mkl_fft.irfftn(x, s, axes, fwd_scale=fsc)
624+
return mkl_fft.irfftn(x, s, axes, norm=norm)
636625

637626

638627
def ihfftn(
@@ -655,11 +644,10 @@ def ihfftn(
655644
x = _validate_input(x)
656645
norm = _swap_direction(norm)
657646
s, axes = _init_nd_shape_and_axes(x, s, axes)
658-
fsc = _compute_fwd_scale(norm, s, x.shape)
659647

660648
with _Workers(workers):
661649
# Note: overwrite_x is not utilized
662-
result = mkl_fft.rfftn(x, s, axes, fwd_scale=fsc)
650+
result = mkl_fft.rfftn(x, s, axes, norm=norm)
663651

664652
np.conjugate(result, out=result)
665653
return result

‎mkl_fft/tests/test_fftnd.py

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,13 @@ def test_matrix6(self):
152152
"""fftn with tuple, list and ndarray axes and s"""
153153
for ar in [self.md, self.mz, self.mf, self.mc]:
154154
d = ar.copy()
155-
for norm in ["forward", "backward", "ortho"]:
155+
for norm in [None, "forward", "backward", "ortho"]:
156156
for container in [tuple, list, np.array]:
157157
axes = container(range(d.ndim))
158158
s = container(d.shape)
159159
kwargs = dict(s=s, axes=axes, norm=norm)
160160
r_tol, a_tol = _get_rtol_atol(d)
161-
t = mkl_fft.interfaces.numpy_fft.fftn(
162-
mkl_fft.interfaces.numpy_fft.ifftn(d, **kwargs),
163-
**kwargs,
164-
)
161+
t = mkl_fft.fftn(mkl_fft.ifftn(d, **kwargs), **kwargs)
165162
assert_allclose(
166163
d,
167164
t,
@@ -194,7 +191,6 @@ def test_cf_contig(self):
194191
assert_allclose(f1, f2, rtol=r_tol, atol=a_tol)
195192

196193
def test_rfftn(self):
197-
"""Test that rfftn works as expected"""
198194
axes = [
199195
(0, 1, 2),
200196
(0, 2, 1),
@@ -211,80 +207,20 @@ def test_rfftn(self):
211207
assert_allclose(rfft_tr, tr_rfft, rtol=r_tol, atol=a_tol)
212208

213209
def test_gh64(self):
214-
"""Test example from #64"""
215210
a = np.arange(12).reshape((3, 4))
216211
x = a.astype(np.cdouble)
217-
# should executed successfully
218212
r1 = mkl_fft.fftn(a, s=None, axes=(-2, -1))
219213
r2 = mkl_fft.fftn(x)
220214
r_tol, a_tol = _get_rtol_atol(x)
221215
assert_allclose(r1, r2, rtol=r_tol, atol=a_tol)
222216

223217

224-
class Test_Scales(TestCase):
225-
def setUp(self):
226-
pass
227-
228-
def test_scale_1d_vector(self):
229-
X = np.ones(128, dtype="d")
230-
f1 = mkl_fft.fft(X, fwd_scale=0.25)
231-
f2 = mkl_fft.fft(X)
232-
r_tol, a_tol = _get_rtol_atol(X)
233-
assert_allclose(4 * f1, f2, rtol=r_tol, atol=a_tol)
234-
235-
X1 = mkl_fft.ifft(f1, fwd_scale=0.25)
236-
assert_allclose(X, X1, rtol=r_tol, atol=a_tol)
237-
238-
f3 = mkl_fft.rfft(X, fwd_scale=0.5)
239-
X2 = mkl_fft.irfft(f3, fwd_scale=0.5)
240-
assert_allclose(X, X2, rtol=r_tol, atol=a_tol)
241-
242-
def test_scale_1d_array(self):
243-
X = np.ones(
244-
(
245-
8,
246-
4,
247-
4,
248-
),
249-
dtype="d",
250-
)
251-
f1 = mkl_fft.fft(X, axis=1, fwd_scale=0.25)
252-
f2 = mkl_fft.fft(X, axis=1)
253-
r_tol, a_tol = _get_rtol_atol(X)
254-
assert_allclose(4 * f1, f2, rtol=r_tol, atol=a_tol)
255-
256-
X1 = mkl_fft.ifft(f1, axis=1, fwd_scale=0.25)
257-
assert_allclose(X, X1, rtol=r_tol, atol=a_tol)
258-
259-
f3 = mkl_fft.rfft(X, axis=0, fwd_scale=0.5)
260-
X2 = mkl_fft.irfft(f3, axis=0, fwd_scale=0.5)
261-
assert_allclose(X, X2, rtol=r_tol, atol=a_tol)
262-
263-
def test_scale_nd(self):
264-
X = np.empty((2, 4, 8, 16), dtype="d")
265-
X.flat[:] = np.cbrt(np.arange(0, X.size, dtype=X.dtype))
266-
f = mkl_fft.fftn(X)
267-
f_scale = mkl_fft.fftn(X, fwd_scale=0.2)
268-
269-
r_tol, a_tol = _get_rtol_atol(X)
270-
assert_allclose(f, 5 * f_scale, rtol=r_tol, atol=a_tol)
271-
272-
def test_scale_nd_axes(self):
273-
X = np.empty((4, 2, 16, 8), dtype="d")
274-
X.flat[:] = np.cbrt(np.arange(X.size, dtype=X.dtype))
275-
f = mkl_fft.fftn(X, axes=(0, 1, 2, 3))
276-
f_scale = mkl_fft.fftn(X, axes=(0, 1, 2, 3), fwd_scale=0.2)
277-
278-
r_tol, a_tol = _get_rtol_atol(X)
279-
assert_allclose(f, 5 * f_scale, rtol=r_tol, atol=a_tol)
280-
281-
282218
def test_gh109():
283219
b_int = np.array([[5, 7, 6, 5], [4, 6, 4, 8], [9, 3, 7, 5]], dtype=np.int64)
284220
b = np.asarray(b_int, dtype=np.float32)
285221

286-
r1 = mkl_fft.fftn(b, s=None, axes=(0,), fwd_scale=1 / 3)
287-
r2 = mkl_fft.fftn(b_int, s=None, axes=(0,), fwd_scale=1 / 3)
222+
r1 = mkl_fft.fftn(b, s=None, axes=(0,), norm="ortho")
223+
r2 = mkl_fft.fftn(b_int, s=None, axes=(0,), norm="ortho")
288224

289225
rtol, atol = _get_rtol_atol(b)
290226
assert_allclose(r1, r2, rtol=rtol, atol=atol)

0 commit comments

Comments
 (0)
Please sign in to comment.