Skip to content

Commit 6bfa629

Browse files
committed
replace fwd_scale with norm kwarg in mkl_fft
1 parent 156dce7 commit 6bfa629

File tree

7 files changed

+87
-156
lines changed

7 files changed

+87
-156
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
* Enabled support of Python 3.13 [gh-164](https://github.com/IntelPython/mkl_fft/pull/164)
1111

1212
### Changed
13+
* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189)
1314

1415
### Fixed
1516

README.md

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

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

54-
`fft(x, n=None, axis=-1, overwrite_x=False, fwd_scale=1.0, out=None)` - 1D FFT, similar to `scipy.fft.fft`
54+
`fft(x, n=None, axis=-1, overwrite_x=False, norm=None, out=None)` - 1D FFT, similar to `scipy.fft.fft`
5555

56-
`fft2(x, s=None, axes=(-2, -1), overwrite_x=False, fwd_scale=1.0, out=None)` - 2D FFT, similar to `scipy.fft.fft2`
56+
`fft2(x, s=None, axes=(-2, -1), overwrite_x=False, norm=None, out=None)` - 2D FFT, similar to `scipy.fft.fft2`
5757

58-
`fftn(x, s=None, axes=None, overwrite_x=False, fwd_scale=1.0, out=None)` - ND FFT, similar to `scipy.fft.fftn`
58+
`fftn(x, s=None, axes=None, overwrite_x=False, norm=None, out=None)` - ND FFT, similar to `scipy.fft.fftn`
5959

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

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

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

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

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

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

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

@@ -299,7 +295,7 @@ def _pad_array(arr, s, axes):
299295
try:
300296
shp_i = arr_shape[ai]
301297
except IndexError:
302-
raise ValueError("Invalid axis (%d) specified" % ai)
298+
raise ValueError(f"Invalid axis {ai} specified")
303299
if si > shp_i:
304300
no_padding = False
305301
pad_widths[ai] = (0, si - shp_i)
@@ -335,7 +331,7 @@ def _trim_array(arr, s, axes):
335331
try:
336332
shp_i = arr_shape[ai]
337333
except IndexError:
338-
raise ValueError("Invalid axis (%d) specified" % ai)
334+
raise ValueError(f"Invalid axis {ai} specified")
339335
if si < shp_i:
340336
no_trim = False
341337
ind[ai] = slice(None, si, None)

mkl_fft/_mkl_fft.py

Lines changed: 48 additions & 25 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,85 +50,103 @@
4550
]
4651

4752

48-
def fft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0):
53+
def fft(x, n=None, axis=-1, norm=None, out=None, overwrite_x=False):
54+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
4955
return _c2c_fft1d_impl(
5056
x,
5157
n=n,
5258
axis=axis,
5359
out=out,
5460
overwrite_x=overwrite_x,
5561
direction=+1,
56-
fsc=fwd_scale,
62+
fsc=fsc,
5763
)
5864

5965

60-
def ifft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0):
66+
def ifft(x, n=None, axis=-1, norm=None, out=None, overwrite_x=False):
67+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
6168
return _c2c_fft1d_impl(
6269
x,
6370
n=n,
6471
axis=axis,
6572
out=out,
6673
overwrite_x=overwrite_x,
6774
direction=-1,
68-
fsc=fwd_scale,
75+
fsc=fsc,
6976
)
7077

7178

72-
def fft2(x, s=None, axes=(-2, -1), out=None, overwrite_x=False, fwd_scale=1.0):
79+
def fft2(x, s=None, axes=(-2, -1), norm=None, out=None, overwrite_x=False):
7380
return fftn(
74-
x, s=s, axes=axes, out=out, overwrite_x=overwrite_x, fwd_scale=fwd_scale
81+
x,
82+
s=s,
83+
axes=axes,
84+
norm=norm,
85+
out=out,
86+
overwrite_x=overwrite_x,
7587
)
7688

7789

78-
def ifft2(x, s=None, axes=(-2, -1), out=None, overwrite_x=False, fwd_scale=1.0):
90+
def ifft2(x, s=None, axes=(-2, -1), norm=None, out=None, overwrite_x=False):
7991
return ifftn(
80-
x, s=s, axes=axes, out=out, overwrite_x=overwrite_x, fwd_scale=fwd_scale
92+
x,
93+
s=s,
94+
axes=axes,
95+
norm=norm,
96+
out=out,
97+
overwrite_x=overwrite_x,
8198
)
8299

83100

84-
def fftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0):
101+
def fftn(x, s=None, axes=None, norm=None, out=None, overwrite_x=False):
102+
fsc = _compute_fwd_scale(norm, s, x.shape)
85103
return _c2c_fftnd_impl(
86104
x,
87105
s=s,
88106
axes=axes,
89107
out=out,
90108
overwrite_x=overwrite_x,
91109
direction=+1,
92-
fsc=fwd_scale,
110+
fsc=fsc,
93111
)
94112

95113

96-
def ifftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0):
114+
def ifftn(x, s=None, axes=None, norm=None, out=None, overwrite_x=False):
115+
fsc = _compute_fwd_scale(norm, s, x.shape)
97116
return _c2c_fftnd_impl(
98117
x,
99118
s=s,
100119
axes=axes,
101120
out=out,
102121
overwrite_x=overwrite_x,
103122
direction=-1,
104-
fsc=fwd_scale,
123+
fsc=fsc,
105124
)
106125

107126

108-
def rfft(x, n=None, axis=-1, out=None, fwd_scale=1.0):
109-
return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale)
127+
def rfft(x, n=None, axis=-1, norm=None, out=None):
128+
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
129+
return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc)
110130

111131

112-
def irfft(x, n=None, axis=-1, out=None, fwd_scale=1.0):
113-
return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale)
132+
def irfft(x, n=None, axis=-1, norm=None, out=None):
133+
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
134+
return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc)
114135

115136

116-
def rfft2(x, s=None, axes=(-2, -1), out=None, fwd_scale=1.0):
117-
return rfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
137+
def rfft2(x, s=None, axes=(-2, -1), norm=None, out=None):
138+
return rfftn(x, s=s, axes=axes, norm=norm, out=out)
118139

119140

120-
def irfft2(x, s=None, axes=(-2, -1), out=None, fwd_scale=1.0):
121-
return irfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale)
141+
def irfft2(x, s=None, axes=(-2, -1), norm=None, out=None):
142+
return irfftn(x, s=s, axes=axes, norm=norm, out=out)
122143

123144

124-
def rfftn(x, s=None, axes=None, out=None, fwd_scale=1.0):
125-
return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale)
145+
def rfftn(x, s=None, axes=None, norm=None, out=None):
146+
fsc = _compute_fwd_scale(norm, s, x.shape)
147+
return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fsc)
126148

127149

128-
def irfftn(x, s=None, axes=None, out=None, fwd_scale=1.0):
129-
return _c2r_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale)
150+
def irfftn(x, s=None, axes=None, norm=None, out=None):
151+
fsc = _compute_fwd_scale(norm, s, x.shape)
152+
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)