Skip to content

Commit 46c8b3f

Browse files
authored
replace fwd_scale with norm kwarg in mkl_fft (#189)
1 parent 156dce7 commit 46c8b3f

File tree

7 files changed

+87
-158
lines changed

7 files changed

+87
-158
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 & 24 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,8 @@ 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])
124-
125123
return _trycall(
126-
mkl_fft.fft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
124+
mkl_fft.fft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
127125
)
128126

129127

@@ -135,10 +133,8 @@ def ifft(a, n=None, axis=-1, norm=None, out=None):
135133
136134
"""
137135
x = _downcast_float128_array(a)
138-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
139-
140136
return _trycall(
141-
mkl_fft.ifft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
137+
mkl_fft.ifft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
142138
)
143139

144140

@@ -171,10 +167,9 @@ def fftn(a, s=None, axes=None, norm=None, out=None):
171167
"""
172168
x = _downcast_float128_array(a)
173169
s, axes = _cook_nd_args(x, s, axes)
174-
fsc = _compute_fwd_scale(norm, s, x.shape)
175170

176171
return _trycall(
177-
mkl_fft.fftn, (x,), {"s": s, "axes": axes, "fwd_scale": fsc, "out": out}
172+
mkl_fft.fftn, (x,), {"s": s, "axes": axes, "norm": norm, "out": out}
178173
)
179174

180175

@@ -187,12 +182,11 @@ def ifftn(a, s=None, axes=None, norm=None, out=None):
187182
"""
188183
x = _downcast_float128_array(a)
189184
s, axes = _cook_nd_args(x, s, axes)
190-
fsc = _compute_fwd_scale(norm, s, x.shape)
191185

192186
return _trycall(
193187
mkl_fft.ifftn,
194188
(x,),
195-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
189+
{"s": s, "axes": axes, "norm": norm, "out": out},
196190
)
197191

198192

@@ -204,10 +198,9 @@ def rfft(a, n=None, axis=-1, norm=None, out=None):
204198
205199
"""
206200
x = _downcast_float128_array(a)
207-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
208201

209202
return _trycall(
210-
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
203+
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
211204
)
212205

213206

@@ -219,12 +212,11 @@ def irfft(a, n=None, axis=-1, norm=None, out=None):
219212
220213
"""
221214
x = _downcast_float128_array(a)
222-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
223215

224216
return _trycall(
225217
mkl_fft.irfft,
226218
(x,),
227-
{"n": n, "axis": axis, "fwd_scale": fsc, "out": out},
219+
{"n": n, "axis": axis, "norm": norm, "out": out},
228220
)
229221

230222

@@ -257,12 +249,11 @@ def rfftn(a, s=None, axes=None, norm=None, out=None):
257249
"""
258250
x = _downcast_float128_array(a)
259251
s, axes = _cook_nd_args(x, s, axes)
260-
fsc = _compute_fwd_scale(norm, s, x.shape)
261252

262253
return _trycall(
263254
mkl_fft.rfftn,
264255
(x,),
265-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
256+
{"s": s, "axes": axes, "norm": norm, "out": out},
266257
)
267258

268259

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

277268
x = _downcast_float128_array(a)
278269
s, axes = _cook_nd_args(x, s, axes, invreal=True)
279-
fsc = _compute_fwd_scale(norm, s, x.shape)
280270

281271
return _trycall(
282272
mkl_fft.irfftn,
283273
(x,),
284-
{"s": s, "axes": axes, "fwd_scale": fsc, "out": out},
274+
{"s": s, "axes": axes, "norm": norm, "out": out},
285275
)
286276

287277

@@ -295,12 +285,10 @@ def hfft(a, n=None, axis=-1, norm=None, out=None):
295285
"""
296286
norm = _swap_direction(norm)
297287
x = _downcast_float128_array(a)
298-
fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1))
299-
300288
return _trycall(
301289
mkl_fft.irfft,
302290
(np.conjugate(x),),
303-
{"n": n, "axis": axis, "fwd_scale": fsc, "out": out},
291+
{"n": n, "axis": axis, "norm": norm, "out": out},
304292
)
305293

306294

@@ -313,10 +301,9 @@ def ihfft(a, n=None, axis=-1, norm=None, out=None):
313301
"""
314302
norm = _swap_direction(norm)
315303
x = _downcast_float128_array(a)
316-
fsc = _compute_fwd_scale(norm, n, x.shape[axis])
317304

318305
result = _trycall(
319-
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}
306+
mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out}
320307
)
321308

322309
np.conjugate(result, out=result)

0 commit comments

Comments
 (0)