@@ -151,12 +151,12 @@ cdef int _datacopied(cnp.ndarray arr, object orig):
151
151
return 1 if (arr_obj .base is None ) else 0
152
152
153
153
154
- def fft (x , n = None , axis = - 1 , overwrite_x = False ):
155
- return _fft1d_impl (x , n = n , axis = axis , overwrite_arg = overwrite_x , direction = + 1 )
154
+ def fft (x , n = None , axis = - 1 , overwrite_x = False , forward_scale = 1.0 ):
155
+ return _fft1d_impl (x , n = n , axis = axis , overwrite_arg = overwrite_x , direction = + 1 , fsc = forward_scale )
156
156
157
157
158
- def ifft (x , n = None , axis = - 1 , overwrite_x = False ):
159
- return _fft1d_impl (x , n = n , axis = axis , overwrite_arg = overwrite_x , direction = - 1 )
158
+ def ifft (x , n = None , axis = - 1 , overwrite_x = False , forward_scale = 1.0 ):
159
+ return _fft1d_impl (x , n = n , axis = axis , overwrite_arg = overwrite_x , direction = - 1 , fsc = forward_scale )
160
160
161
161
162
162
cdef cnp .ndarray pad_array (cnp .ndarray x_arr , cnp .npy_intp n , int axis , int realQ ):
@@ -403,14 +403,14 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1, double fs
403
403
return f_arr
404
404
405
405
406
- def rfft (x , n = None , axis = - 1 , overwrite_x = False ):
406
+ def rfft (x , n = None , axis = - 1 , overwrite_x = False , forward_scale = 1.0 ):
407
407
"""Packed real-valued harmonics of FFT of a real sequence x"""
408
- return _rr_fft1d_impl2 (x , n = n , axis = axis , overwrite_arg = overwrite_x )
408
+ return _rr_fft1d_impl2 (x , n = n , axis = axis , overwrite_arg = overwrite_x , fsc = forward_scale )
409
409
410
410
411
- def irfft (x , n = None , axis = - 1 , overwrite_x = False ):
411
+ def irfft (x , n = None , axis = - 1 , overwrite_x = False , forward_scale = 1.0 ):
412
412
"""Inverse FFT of a real sequence, takes packed real-valued harmonics of FFT"""
413
- return _rr_ifft1d_impl2 (x , n = n , axis = axis , overwrite_arg = overwrite_x )
413
+ return _rr_ifft1d_impl2 (x , n = n , axis = axis , overwrite_arg = overwrite_x , fsc = forward_scale )
414
414
415
415
416
416
cdef object _rc_to_rr (cnp .ndarray rc_arr , int n , int axis , int xnd , int x_type ):
@@ -788,12 +788,12 @@ def _rc_ifft1d_impl(x, n=None, axis=-1, overwrite_arg=False, double fsc=1.0):
788
788
return f_arr
789
789
790
790
791
- def rfft_numpy (x , n = None , axis = - 1 ):
792
- return _rc_fft1d_impl (x , n = n , axis = axis )
791
+ def rfft_numpy (x , n = None , axis = - 1 , forward_scale = 1.0 ):
792
+ return _rc_fft1d_impl (x , n = n , axis = axis , fsc = forward_scale )
793
793
794
794
795
- def irfft_numpy (x , n = None , axis = - 1 ):
796
- return _rc_ifft1d_impl (x , n = n , axis = axis )
795
+ def irfft_numpy (x , n = None , axis = - 1 , forward_scale = 1.0 ):
796
+ return _rc_ifft1d_impl (x , n = n , axis = axis , fsc = forward_scale )
797
797
798
798
799
799
# ============================== ND ====================================== #
@@ -902,12 +902,12 @@ def _cook_nd_args(a, s=None, axes=None, invreal=0):
902
902
return s , axes
903
903
904
904
905
- def _iter_fftnd (a , s = None , axes = None , function = fft , overwrite_arg = False ):
905
+ def _iter_fftnd (a , s = None , axes = None , function = fft , overwrite_arg = False , scale_function = lambda n : 1.0 ):
906
906
a = np .asarray (a )
907
907
s , axes = _init_nd_shape_and_axes (a , s , axes )
908
908
ovwr = overwrite_arg
909
909
for ii in reversed (range (len (axes ))):
910
- a = function (a , n = s [ii ], axis = axes [ii ], overwrite_x = ovwr )
910
+ a = function (a , n = s [ii ], axis = axes [ii ], overwrite_x = ovwr , forward_scale = scale_function ( s [ ii ]) )
911
911
ovwr = True
912
912
return a
913
913
@@ -1026,33 +1026,34 @@ def _fftnd_impl(x, shape=None, axes=None, overwrite_x=False, direction=+1, doubl
1026
1026
if _direct :
1027
1027
return _direct_fftnd (x , overwrite_arg = overwrite_x , direction = direction , fsc = fsc )
1028
1028
else :
1029
+ sc = (< object > fsc )** (1 / x .ndim )
1029
1030
return _iter_fftnd (x , s = shape , axes = axes ,
1030
- overwrite_arg = overwrite_x , fsc = fsc ,
1031
+ overwrite_arg = overwrite_x , scale_function = lambda n : sc ,
1031
1032
function = fft if direction == 1 else ifft )
1032
1033
1033
1034
1034
- def fft2 (x , shape = None , axes = (- 2 ,- 1 ), overwrite_x = False ):
1035
- return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = + 1 )
1035
+ def fft2 (x , shape = None , axes = (- 2 ,- 1 ), overwrite_x = False , forward_scale = 1.0 ):
1036
+ return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = + 1 , fsc = forward_scale )
1036
1037
1037
1038
1038
- def ifft2 (x , shape = None , axes = (- 2 ,- 1 ), overwrite_x = False ):
1039
- return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = - 1 )
1039
+ def ifft2 (x , shape = None , axes = (- 2 ,- 1 ), overwrite_x = False , forward_scale = 1.0 ):
1040
+ return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = - 1 , fsc = forward_scale )
1040
1041
1041
1042
1042
- def fftn (x , shape = None , axes = None , overwrite_x = False ):
1043
- return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = + 1 )
1043
+ def fftn (x , shape = None , axes = None , overwrite_x = False , forward_scale = 1.0 ):
1044
+ return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = + 1 , fsc = forward_scale )
1044
1045
1045
1046
1046
- def ifftn (x , shape = None , axes = None , overwrite_x = False ):
1047
- return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = - 1 )
1047
+ def ifftn (x , shape = None , axes = None , overwrite_x = False , forward_scale = 1.0 ):
1048
+ return _fftnd_impl (x , shape = shape , axes = axes , overwrite_x = overwrite_x , direction = - 1 , fsc = forward_scale )
1048
1049
1049
1050
1050
- def rfft2_numpy (x , s = None , axes = (- 2 ,- 1 )):
1051
- return rfftn_numpy (x , s = s , axes = axes )
1051
+ def rfft2_numpy (x , s = None , axes = (- 2 ,- 1 ), forward_scale = 1.0 ):
1052
+ return rfftn_numpy (x , s = s , axes = axes , fsc = forward_scale )
1052
1053
1053
1054
1054
- def irfft2_numpy (x , s = None , axes = (- 2 ,- 1 )):
1055
- return irfftn_numpy (x , s = s , axes = axes )
1055
+ def irfft2_numpy (x , s = None , axes = (- 2 ,- 1 ), forward_scale = 1.0 ):
1056
+ return irfftn_numpy (x , s = s , axes = axes , fsc = forward_scale )
1056
1057
1057
1058
1058
1059
def _remove_axis (s , axes , axis_to_remove ):
@@ -1107,7 +1108,7 @@ def _fix_dimensions(cnp.ndarray arr, object s, object axes):
1107
1108
return np .pad (arr , tuple (pad_widths ), 'constant' )
1108
1109
1109
1110
1110
- def rfftn_numpy (x , s = None , axes = None ):
1111
+ def rfftn_numpy (x , s = None , axes = None , forward_scale = 1.0 ):
1111
1112
a = np .asarray (x )
1112
1113
no_trim = (s is None ) and (axes is None )
1113
1114
s , axes = _cook_nd_args (a , s , axes )
@@ -1116,7 +1117,7 @@ def rfftn_numpy(x, s=None, axes=None):
1116
1117
# unnecessary computations
1117
1118
if not no_trim :
1118
1119
a = _trim_array (a , s , axes )
1119
- a = rfft_numpy (a , n = s [- 1 ], axis = la )
1120
+ a = rfft_numpy (a , n = s [- 1 ], axis = la , forward_scale = forward_scale )
1120
1121
if len (s ) > 1 :
1121
1122
if not no_trim :
1122
1123
ss = list (s )
@@ -1140,7 +1141,7 @@ def rfftn_numpy(x, s=None, axes=None):
1140
1141
return a
1141
1142
1142
1143
1143
- def irfftn_numpy (x , s = None , axes = None ):
1144
+ def irfftn_numpy (x , s = None , axes = None , forward_scale = 1.0 ):
1144
1145
a = np .asarray (x )
1145
1146
no_trim = (s is None ) and (axes is None )
1146
1147
s , axes = _cook_nd_args (a , s , axes , invreal = True )
@@ -1169,5 +1170,5 @@ def irfftn_numpy(x, s=None, axes=None):
1169
1170
for ii in range (len (axes )- 1 ):
1170
1171
a = ifft (a , s [ii ], axes [ii ], overwrite_x = ovr_x )
1171
1172
ovr_x = True
1172
- a = irfft_numpy (a , n = s [- 1 ], axis = la )
1173
+ a = irfft_numpy (a , n = s [- 1 ], axis = la , forward_scale = forward_scale )
1173
1174
return a
0 commit comments