@@ -151,12 +151,12 @@ cdef int _datacopied(cnp.ndarray arr, object orig):
151151 return 1 if (arr_obj .base is None ) else 0
152152
153153
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 )
156156
157157
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 )
160160
161161
162162cdef 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
403403 return f_arr
404404
405405
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 ):
407407 """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 )
409409
410410
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 ):
412412 """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 )
414414
415415
416416cdef 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):
788788 return f_arr
789789
790790
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 )
793793
794794
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 )
797797
798798
799799# ============================== ND ====================================== #
@@ -902,12 +902,12 @@ def _cook_nd_args(a, s=None, axes=None, invreal=0):
902902 return s , axes
903903
904904
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 ):
906906 a = np .asarray (a )
907907 s , axes = _init_nd_shape_and_axes (a , s , axes )
908908 ovwr = overwrite_arg
909909 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 ]) )
911911 ovwr = True
912912 return a
913913
@@ -1026,33 +1026,34 @@ def _fftnd_impl(x, shape=None, axes=None, overwrite_x=False, direction=+1, doubl
10261026 if _direct :
10271027 return _direct_fftnd (x , overwrite_arg = overwrite_x , direction = direction , fsc = fsc )
10281028 else :
1029+ sc = (< object > fsc )** (1 / x .ndim )
10291030 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 ,
10311032 function = fft if direction == 1 else ifft )
10321033
10331034
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 )
10361037
10371038
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 )
10401041
10411042
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 )
10441045
10451046
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 )
10481049
10491050
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 )
10521053
10531054
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 )
10561057
10571058
10581059def _remove_axis (s , axes , axis_to_remove ):
@@ -1107,7 +1108,7 @@ def _fix_dimensions(cnp.ndarray arr, object s, object axes):
11071108 return np .pad (arr , tuple (pad_widths ), 'constant' )
11081109
11091110
1110- def rfftn_numpy (x , s = None , axes = None ):
1111+ def rfftn_numpy (x , s = None , axes = None , forward_scale = 1.0 ):
11111112 a = np .asarray (x )
11121113 no_trim = (s is None ) and (axes is None )
11131114 s , axes = _cook_nd_args (a , s , axes )
@@ -1116,7 +1117,7 @@ def rfftn_numpy(x, s=None, axes=None):
11161117 # unnecessary computations
11171118 if not no_trim :
11181119 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 )
11201121 if len (s ) > 1 :
11211122 if not no_trim :
11221123 ss = list (s )
@@ -1140,7 +1141,7 @@ def rfftn_numpy(x, s=None, axes=None):
11401141 return a
11411142
11421143
1143- def irfftn_numpy (x , s = None , axes = None ):
1144+ def irfftn_numpy (x , s = None , axes = None , forward_scale = 1.0 ):
11441145 a = np .asarray (x )
11451146 no_trim = (s is None ) and (axes is None )
11461147 s , axes = _cook_nd_args (a , s , axes , invreal = True )
@@ -1169,5 +1170,5 @@ def irfftn_numpy(x, s=None, axes=None):
11691170 for ii in range (len (axes )- 1 ):
11701171 a = ifft (a , s [ii ], axes [ii ], overwrite_x = ovr_x )
11711172 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 )
11731174 return a
0 commit comments