Skip to content

Commit ec1f74f

Browse files
committed
drop support for scipy.fftpack
1 parent 44d10a0 commit ec1f74f

File tree

4 files changed

+0
-369
lines changed

4 files changed

+0
-369
lines changed

mkl_fft/__init__.py

Lines changed: 0 additions & 3 deletions
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

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

mkl_fft/interfaces/_scipy_fftpack.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

mkl_fft/tests/test_fft1d.py

Lines changed: 0 additions & 49 deletions
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)