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