@@ -883,249 +883,3 @@ def _direct_fftnd(
883
883
return out
884
884
else :
885
885
return f_arr
886
-
887
-
888
- # ========================= deprecated functions ==============================
889
- cdef object _rc_to_rr(cnp.ndarray rc_arr, int n, int axis, int xnd, int x_type):
890
- cdef object res
891
- inp = < object > rc_arr
892
-
893
- slice_ = [slice (None , None , None )] * xnd
894
- sl_0 = list (slice_)
895
- sl_0[axis] = 0
896
-
897
- sl_1 = list (slice_)
898
- sl_1[axis] = 1
899
- if (inp.flags[" C" ] and inp.strides[axis] == inp.itemsize):
900
- res = inp
901
- res = res.view(
902
- dtype = np.single if x_type == cnp.NPY_FLOAT else np.double
903
- )
904
- res[tuple (sl_1)] = res[tuple (sl_0)]
905
-
906
- slice_[axis] = slice (1 , n + 1 , None )
907
-
908
- return res[tuple (slice_)]
909
- else :
910
- res_shape = list (inp.shape)
911
- res_shape[axis] = n
912
- res = np.empty(
913
- tuple (res_shape),
914
- dtype = np.single if x_type == cnp.NPY_FLOAT else np.double,
915
- )
916
-
917
- res[tuple (sl_0)] = inp[tuple (sl_0)].real
918
- sl_dst_real = list (slice_)
919
- sl_dst_real[axis] = slice (1 , None , 2 )
920
- sl_src_real = list (slice_)
921
- sl_src_real[axis] = slice (1 , None , None )
922
- res[tuple (sl_dst_real)] = inp[tuple (sl_src_real)].real
923
- sl_dst_imag = list (slice_)
924
- sl_dst_imag[axis] = slice (2 , None , 2 )
925
- sl_src_imag = list (slice_)
926
- sl_src_imag[axis] = slice (
927
- 1 , inp.shape[axis] if (n & 1 ) else inp.shape[axis] - 1 , None
928
- )
929
- res[tuple (sl_dst_imag)] = inp[tuple (sl_src_imag)].imag
930
-
931
- return res[tuple (slice_)]
932
-
933
-
934
- cdef object _rr_to_rc(cnp.ndarray rr_arr, int n, int axis, int xnd, int x_type):
935
-
936
- inp = < object > rr_arr
937
-
938
- rc_shape = list (inp.shape)
939
- rc_shape[axis] = (n // 2 + 1 )
940
- rc_shape = tuple (rc_shape)
941
-
942
- rc_dtype = np.cdouble if x_type == cnp.NPY_DOUBLE else np.csingle
943
- rc = np.empty(rc_shape, dtype = rc_dtype, order = " C" )
944
-
945
- slice_ = [slice (None , None , None )] * xnd
946
- sl_src_real = list (slice_)
947
- sl_src_imag = list (slice_)
948
- sl_src_real[axis] = slice (1 , n, 2 )
949
- sl_src_imag[axis] = slice (2 , n, 2 )
950
-
951
- sl_dest_real = list (slice_)
952
- sl_dest_real[axis] = slice (1 , None , None )
953
- sl_dest_imag = list (slice_)
954
- sl_dest_imag[axis] = slice (1 , (n+ 1 )// 2 , None )
955
-
956
- sl_0 = list (slice_)
957
- sl_0[axis] = 0
958
-
959
- rc_real = rc.real
960
- rc_imag = rc.imag
961
-
962
- rc_real[tuple (sl_dest_real)] = inp[tuple (sl_src_real)]
963
- rc_imag[tuple (sl_dest_imag)] = inp[tuple (sl_src_imag)]
964
- rc_real[tuple (sl_0)] = inp[tuple (sl_0)]
965
- rc_imag[tuple (sl_0)] = 0
966
- if (n & 1 == 0 ):
967
- sl_last = list (slice_)
968
- sl_last[axis] = - 1
969
- rc_imag[tuple (sl_last)] = 0
970
-
971
- return rc
972
-
973
-
974
- def _rr_fft1d_impl (x , n = None , axis = - 1 , overwrite_x = False , double fsc = 1.0 ):
975
- """
976
- Uses MKL to perform real packed 1D FFT on the input array x
977
- along the given axis.
978
-
979
- This done by using rfft and post-processing the result.
980
- Thus overwrite_x is effectively discarded.
981
-
982
- Functionally equivalent to scipy.fftpack.rfft
983
- """
984
- cdef cnp.ndarray x_arr " x_arrayObject"
985
- cdef cnp.ndarray f_arr " f_arrayObject"
986
- cdef int xnd, in_place, dir_
987
- cdef long n_, axis_
988
- cdef int HALF_HARMONICS = 0 # give only positive index harmonics
989
- cdef int x_type, status, f_type
990
- cdef char * c_error_msg = NULL
991
- cdef bytes py_error_msg
992
- cdef DftiCache * _cache
993
-
994
- x_arr = _process_arguments(x, n, axis, overwrite_x, < object > (+ 1 ),
995
- & axis_, & n_, & in_place, & xnd, & dir_, 1 )
996
-
997
- x_type = cnp.PyArray_TYPE(x_arr)
998
-
999
- if x_type is cnp.NPY_FLOAT or x_type is cnp.NPY_DOUBLE:
1000
- in_place = 0
1001
- elif x_type is cnp.NPY_CFLOAT or x_type is cnp.NPY_CDOUBLE:
1002
- raise TypeError (" 1st argument must be a real sequence" )
1003
- else :
1004
- try :
1005
- x_arr = < cnp.ndarray> cnp.PyArray_FROM_OTF(
1006
- x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY)
1007
- except :
1008
- raise TypeError (" 1st argument must be a real sequence" )
1009
- x_type = cnp.PyArray_TYPE(x_arr)
1010
- in_place = 0
1011
-
1012
- f_type = cnp.NPY_CFLOAT if x_type is cnp.NPY_FLOAT else cnp.NPY_CDOUBLE
1013
- f_arr = _allocate_result(x_arr, n_ // 2 + 1 , axis_, f_type)
1014
-
1015
- _cache_capsule = _tls_dfti_cache_capsule()
1016
- _cache = < DftiCache * > cpython.pycapsule.PyCapsule_GetPointer(
1017
- _cache_capsule, capsule_name
1018
- )
1019
- if x_type is cnp.NPY_DOUBLE:
1020
- status = double_cdouble_mkl_fft1d_out(
1021
- x_arr, n_, < int > axis_, f_arr, HALF_HARMONICS, fsc, _cache
1022
- )
1023
- else :
1024
- status = float_cfloat_mkl_fft1d_out(
1025
- x_arr, n_, < int > axis_, f_arr, HALF_HARMONICS, fsc, _cache
1026
- )
1027
-
1028
- if (status):
1029
- c_error_msg = mkl_dfti_error(status)
1030
- py_error_msg = c_error_msg
1031
- raise ValueError (" Internal error occurred: {}" .format(py_error_msg))
1032
-
1033
- # post-process and return
1034
- return _rc_to_rr(f_arr, n_, axis_, xnd, x_type)
1035
-
1036
-
1037
- def _rr_ifft1d_impl (x , n = None , axis = - 1 , overwrite_x = False , double fsc = 1.0 ):
1038
- """
1039
- Uses MKL to perform real packed 1D FFT on the input array x along
1040
- the given axis.
1041
-
1042
- This done by using rfft and post-processing the result.
1043
- Thus overwrite_x is effectively discarded.
1044
-
1045
- Functionally equivalent to scipy.fftpack.irfft
1046
- """
1047
- cdef cnp.ndarray x_arr " x_arrayObject"
1048
- cdef cnp.ndarray f_arr " f_arrayObject"
1049
- cdef int xnd, in_place, dir_
1050
- cdef long n_, axis_
1051
- cdef int x_type, rc_type, status
1052
- cdef char * c_error_msg = NULL
1053
- cdef bytes py_error_msg
1054
- cdef DftiCache * _cache
1055
-
1056
- x_arr = _process_arguments(x, n, axis, overwrite_x, < object > (- 1 ),
1057
- & axis_, & n_, & in_place, & xnd, & dir_, 1 )
1058
-
1059
- x_type = cnp.PyArray_TYPE(x_arr)
1060
-
1061
- if x_type is cnp.NPY_FLOAT or x_type is cnp.NPY_DOUBLE:
1062
- pass
1063
- else :
1064
- # we must cast the input and allocate the output,
1065
- # so we cast to complex double and operate in place
1066
- try :
1067
- x_arr = < cnp.ndarray> cnp.PyArray_FROM_OTF(
1068
- x_arr, cnp.NPY_DOUBLE, cnp.NPY_BEHAVED | cnp.NPY_ENSURECOPY)
1069
- except :
1070
- raise ValueError (
1071
- " First argument should be a real "
1072
- " or a complex sequence of single or double precision"
1073
- )
1074
- x_type = cnp.PyArray_TYPE(x_arr)
1075
- in_place = 1
1076
-
1077
- # need to convert this into complex array
1078
- rc_obj = _rr_to_rc(x_arr, n_, axis_, xnd, x_type)
1079
- rc_arr = < cnp.ndarray> rc_obj
1080
-
1081
- rc_type = cnp.NPY_CFLOAT if x_type is cnp.NPY_FLOAT else cnp.NPY_CDOUBLE
1082
- in_place = False
1083
- if in_place:
1084
- f_arr = x_arr
1085
- else :
1086
- f_arr = _allocate_result(x_arr, n_, axis_, x_type)
1087
-
1088
- # call out-of-place FFT
1089
- if rc_type is cnp.NPY_CFLOAT:
1090
- _cache_capsule = _tls_dfti_cache_capsule()
1091
- _cache = < DftiCache * > cpython.pycapsule.PyCapsule_GetPointer(
1092
- _cache_capsule, capsule_name
1093
- )
1094
- status = cfloat_float_mkl_irfft_out(
1095
- rc_arr, n_, < int > axis_, f_arr, fsc, _cache
1096
- )
1097
- elif rc_type is cnp.NPY_CDOUBLE:
1098
- _cache_capsule = _tls_dfti_cache_capsule()
1099
- _cache = < DftiCache * > cpython.pycapsule.PyCapsule_GetPointer(
1100
- _cache_capsule, capsule_name
1101
- )
1102
- status = cdouble_double_mkl_irfft_out(
1103
- rc_arr, n_, < int > axis_, f_arr, fsc, _cache
1104
- )
1105
- else :
1106
- raise ValueError (
1107
- " Internal mkl_fft error occurred: Unrecognized rc_type"
1108
- )
1109
-
1110
- if (status):
1111
- c_error_msg = mkl_dfti_error(status)
1112
- py_error_msg = c_error_msg
1113
- raise ValueError (
1114
- " Internal error occurred: {}" .format(str (py_error_msg))
1115
- )
1116
-
1117
- return f_arr
1118
-
1119
-
1120
- def rfftpack (x , n = None , axis = - 1 , overwrite_x = False , fwd_scale = 1.0 ):
1121
- """ Packed real-valued harmonics of FFT of a real sequence x"""
1122
- return _rr_fft1d_impl(
1123
- x, n = n, axis = axis, overwrite_x = overwrite_x, fsc = fwd_scale
1124
- )
1125
-
1126
-
1127
- def irfftpack (x , n = None , axis = - 1 , overwrite_x = False , fwd_scale = 1.0 ):
1128
- """ IFFT of a real sequence, takes packed real-valued harmonics of FFT"""
1129
- return _rr_ifft1d_impl(
1130
- x, n = n, axis = axis, overwrite_x = overwrite_x, fsc = fwd_scale
1131
- )
0 commit comments