Skip to content

Commit 1503f18

Browse files
committed
drop support for scipy.fftpack
1 parent 6bde33e commit 1503f18

File tree

4 files changed

+0
-369
lines changed

4 files changed

+0
-369
lines changed

mkl_fft/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
rfft2,
4040
rfftn,
4141
)
42-
from ._pydfti import irfftpack, rfftpack # pylint: disable=no-name-in-module
4342
from ._version import __version__
4443

4544
import mkl_fft.interfaces # isort: skip
@@ -51,8 +50,6 @@
5150
"ifft2",
5251
"fftn",
5352
"ifftn",
54-
"rfftpack",
55-
"irfftpack",
5653
"rfft",
5754
"irfft",
5855
"rfft2",

mkl_fft/_pydfti.pyx

-246
Original file line numberDiff line numberDiff line change
@@ -883,249 +883,3 @@ def _direct_fftnd(
883883
return out
884884
else:
885885
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-
)

mkl_fft/interfaces/_scipy_fftpack.py

-71
This file was deleted.

mkl_fft/tests/test_fft1d.py

-49
Original file line numberDiff line numberDiff line change
@@ -352,55 +352,6 @@ def test_array6(self):
352352
assert_allclose(y1, y2, atol=2e-15)
353353

354354

355-
class Test_mklfft_rfftpack(TestCase):
356-
def setUp(self):
357-
rnd.seed(1234567)
358-
self.v1 = rnd.randn(16)
359-
self.m2 = rnd.randn(5, 7)
360-
self.t3 = rnd.randn(5, 7, 11)
361-
362-
def test1(self):
363-
x = self.v1.copy()
364-
f1 = mkl_fft.rfftpack(x)
365-
f2 = mkl_fft.irfftpack(f1)
366-
assert_allclose(f2, x)
367-
368-
def test2(self):
369-
x = self.v1.copy()
370-
f1 = mkl_fft.irfftpack(x)
371-
f2 = mkl_fft.rfftpack(f1)
372-
assert_allclose(f2, x)
373-
374-
def test3(self):
375-
for a in range(0, 2):
376-
for ovwr_x in [True, False]:
377-
for dt, atol in zip([np.float32, np.float64], [2e-7, 2e-15]):
378-
x = self.m2.copy().astype(dt)
379-
f1 = mkl_fft.rfftpack(x, axis=a, overwrite_x=ovwr_x)
380-
f2 = mkl_fft.irfftpack(f1, axis=a, overwrite_x=ovwr_x)
381-
assert_allclose(
382-
f2, self.m2.astype(dt), atol=atol, err_msg=(a, ovwr_x)
383-
)
384-
385-
def test4(self):
386-
for a in range(0, 2):
387-
for ovwr_x in [True, False]:
388-
for dt, atol in zip([np.float32, np.float64], [2e-7, 2e-15]):
389-
x = self.m2.copy().astype(dt)
390-
f1 = mkl_fft.irfftpack(x, axis=a, overwrite_x=ovwr_x)
391-
f2 = mkl_fft.rfftpack(f1, axis=a, overwrite_x=ovwr_x)
392-
assert_allclose(f2, self.m2.astype(dt), atol=atol)
393-
394-
def test5(self):
395-
for a in range(0, 3):
396-
for ovwr_x in [True, False]:
397-
for dt, atol in zip([np.float32, np.float64], [4e-7, 4e-15]):
398-
x = self.t3.copy().astype(dt)
399-
f1 = mkl_fft.irfftpack(x, axis=a, overwrite_x=ovwr_x)
400-
f2 = mkl_fft.rfftpack(f1, axis=a, overwrite_x=ovwr_x)
401-
assert_allclose(f2, self.t3.astype(dt), atol=atol)
402-
403-
404355
@requires_numpy_2
405356
@pytest.mark.parametrize("axis", [0, 1, 2])
406357
@pytest.mark.parametrize("func", ["fft", "ifft"])

0 commit comments

Comments
 (0)