|
61 | 61 |
|
62 | 62 | import numpy
|
63 | 63 | from . import _pydfti as mkl_fft
|
| 64 | +from . import _float_utils |
64 | 65 |
|
65 | 66 |
|
66 | 67 | def _unitary(norm):
|
@@ -155,7 +156,8 @@ def fft(a, n=None, axis=-1, norm=None):
|
155 | 156 | the `numpy.fft` documentation.
|
156 | 157 |
|
157 | 158 | """
|
158 |
| - output = mkl_fft.fft(a, n, axis) |
| 159 | + x = _float_utils.__downcast_float128_array(a) |
| 160 | + output = mkl_fft.fft(x, n, axis) |
159 | 161 | if _unitary(norm):
|
160 | 162 | output *= 1 / sqrt(output.shape[axis])
|
161 | 163 | return output
|
@@ -241,7 +243,8 @@ def ifft(a, n=None, axis=-1, norm=None):
|
241 | 243 |
|
242 | 244 | """
|
243 | 245 | unitary = _unitary(norm)
|
244 |
| - output = mkl_fft.ifft(a, n, axis) |
| 246 | + x = _float_utils.__downcast_float128_array(a) |
| 247 | + output = mkl_fft.ifft(x, n, axis) |
245 | 248 | if unitary:
|
246 | 249 | output *= sqrt(output.shape[axis])
|
247 | 250 | return output
|
@@ -325,10 +328,11 @@ def rfft(a, n=None, axis=-1, norm=None):
|
325 | 328 |
|
326 | 329 | """
|
327 | 330 | unitary = _unitary(norm)
|
| 331 | + x = _float_utils.__downcast_float128_array(a) |
328 | 332 | if unitary and n is None:
|
329 |
| - a = asarray(a) |
330 |
| - n = a.shape[axis] |
331 |
| - output = mkl_fft.rfft_numpy(a, n=n, axis=axis) |
| 333 | + x = asarray(x) |
| 334 | + n = x.shape[axis] |
| 335 | + output = mkl_fft.rfft_numpy(x, n=n, axis=axis) |
332 | 336 | if unitary:
|
333 | 337 | output *= 1 / sqrt(n)
|
334 | 338 | return output
|
@@ -413,7 +417,8 @@ def irfft(a, n=None, axis=-1, norm=None):
|
413 | 417 | specified, and the output array is purely real.
|
414 | 418 |
|
415 | 419 | """
|
416 |
| - output = mkl_fft.irfft_numpy(a, n=n, axis=axis) |
| 420 | + x = _float_utils.__downcast_float128_array(a) |
| 421 | + output = mkl_fft.irfft_numpy(x, n=n, axis=axis) |
417 | 422 | if _unitary(norm):
|
418 | 423 | output *= sqrt(output.shape[axis])
|
419 | 424 | return output
|
@@ -488,12 +493,12 @@ def hfft(a, n=None, axis=-1, norm=None):
|
488 | 493 | [ 2., -2.]])
|
489 | 494 |
|
490 | 495 | """
|
491 |
| - # The copy may be required for multithreading. |
492 |
| - a = array(a, copy=True, dtype=complex) |
| 496 | + x = _float_utils.__downcast_float128_array(a) |
| 497 | + x = array(x, copy=True, dtype=complex) |
493 | 498 | if n is None:
|
494 |
| - n = (a.shape[axis] - 1) * 2 |
| 499 | + n = (x.shape[axis] - 1) * 2 |
495 | 500 | unitary = _unitary(norm)
|
496 |
| - return irfft(conjugate(a), n, axis) * (sqrt(n) if unitary else n) |
| 501 | + return irfft(conjugate(x), n, axis) * (sqrt(n) if unitary else n) |
497 | 502 |
|
498 | 503 |
|
499 | 504 | def ihfft(a, n=None, axis=-1, norm=None):
|
@@ -547,11 +552,12 @@ def ihfft(a, n=None, axis=-1, norm=None):
|
547 | 552 |
|
548 | 553 | """
|
549 | 554 | # The copy may be required for multithreading.
|
550 |
| - a = array(a, copy=True, dtype=float) |
| 555 | + x = _float_utils.__downcast_float128_array(a) |
| 556 | + x = array(x, copy=True, dtype=float) |
551 | 557 | if n is None:
|
552 |
| - n = a.shape[axis] |
| 558 | + n = x.shape[axis] |
553 | 559 | unitary = _unitary(norm)
|
554 |
| - output = conjugate(rfft(a, n, axis)) |
| 560 | + output = conjugate(rfft(x, n, axis)) |
555 | 561 | return output * (1 / (sqrt(n) if unitary else n))
|
556 | 562 |
|
557 | 563 |
|
@@ -673,7 +679,8 @@ def fftn(a, s=None, axes=None, norm=None):
|
673 | 679 | >>> plt.show()
|
674 | 680 |
|
675 | 681 | """
|
676 |
| - output = mkl_fft.fftn(a, s, axes) |
| 682 | + x = _float_utils.__downcast_float128_array(a) |
| 683 | + output = mkl_fft.fftn(x, s, axes) |
677 | 684 | if _unitary(norm):
|
678 | 685 | output *= 1 / sqrt(_tot_size(output, axes))
|
679 | 686 | return output
|
@@ -772,7 +779,8 @@ def ifftn(a, s=None, axes=None, norm=None):
|
772 | 779 |
|
773 | 780 | """
|
774 | 781 | unitary = _unitary(norm)
|
775 |
| - output = mkl_fft.ifftn(a, s, axes) |
| 782 | + x = _float_utils.__downcast_float128_array(a) |
| 783 | + output = mkl_fft.ifftn(x, s, axes) |
776 | 784 | if unitary:
|
777 | 785 | output *= sqrt(_tot_size(output, axes))
|
778 | 786 | return output
|
@@ -863,8 +871,8 @@ def fft2(a, s=None, axes=(-2, -1), norm=None):
|
863 | 871 | 0.0 +0.j , 0.0 +0.j ]])
|
864 | 872 |
|
865 | 873 | """
|
866 |
| - |
867 |
| - return fftn(a, s=s, axes=axes, norm=norm) |
| 874 | + x = _float_utils.__downcast_float128_array(a) |
| 875 | + return fftn(x, s=s, axes=axes, norm=norm) |
868 | 876 |
|
869 | 877 |
|
870 | 878 | def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
@@ -949,8 +957,8 @@ def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
949 | 957 | [ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]])
|
950 | 958 |
|
951 | 959 | """
|
952 |
| - |
953 |
| - return ifftn(a, s=s, axes=axes, norm=norm) |
| 960 | + x = _float_utils.__downcast_float128_array(a) |
| 961 | + return ifftn(x, s=s, axes=axes, norm=norm) |
954 | 962 |
|
955 | 963 |
|
956 | 964 | def rfftn(a, s=None, axes=None, norm=None):
|
@@ -1036,11 +1044,12 @@ def rfftn(a, s=None, axes=None, norm=None):
|
1036 | 1044 |
|
1037 | 1045 | """
|
1038 | 1046 | unitary = _unitary(norm)
|
| 1047 | + x = _float_utils.__downcast_float128_array(a) |
1039 | 1048 | if unitary:
|
1040 |
| - a = asarray(a) |
1041 |
| - s, axes = _cook_nd_args(a, s, axes) |
| 1049 | + x = asarray(x) |
| 1050 | + s, axes = _cook_nd_args(x, s, axes) |
1042 | 1051 |
|
1043 |
| - output = mkl_fft.rfftn_numpy(a, s, axes) |
| 1052 | + output = mkl_fft.rfftn_numpy(x, s, axes) |
1044 | 1053 | if unitary:
|
1045 | 1054 | n_tot = prod(asarray(s, dtype=output.dtype))
|
1046 | 1055 | output *= 1 / sqrt(n_tot)
|
@@ -1079,8 +1088,8 @@ def rfft2(a, s=None, axes=(-2, -1), norm=None):
|
1079 | 1088 | For more details see `rfftn`.
|
1080 | 1089 |
|
1081 | 1090 | """
|
1082 |
| - |
1083 |
| - return rfftn(a, s, axes, norm) |
| 1091 | + x = _float_utils.__downcast_float128_array(a) |
| 1092 | + return rfftn(x, s, axes, norm) |
1084 | 1093 |
|
1085 | 1094 |
|
1086 | 1095 | def irfftn(a, s=None, axes=None, norm=None):
|
@@ -1167,7 +1176,8 @@ def irfftn(a, s=None, axes=None, norm=None):
|
1167 | 1176 | [ 1., 1.]]])
|
1168 | 1177 |
|
1169 | 1178 | """
|
1170 |
| - output = mkl_fft.irfftn_numpy(a, s, axes) |
| 1179 | + x = _float_utils.__downcast_float128_array(a) |
| 1180 | + output = mkl_fft.irfftn_numpy(x, s, axes) |
1171 | 1181 | if _unitary(norm):
|
1172 | 1182 | output *= sqrt(_tot_size(output, axes))
|
1173 | 1183 | return output
|
@@ -1205,6 +1215,6 @@ def irfft2(a, s=None, axes=(-2, -1), norm=None):
|
1205 | 1215 | For more details see `irfftn`.
|
1206 | 1216 |
|
1207 | 1217 | """
|
1208 |
| - |
1209 |
| - return irfftn(a, s, axes, norm) |
| 1218 | + x = _float_utils.__downcast_float128_array(a) |
| 1219 | + return irfftn(x, s, axes, norm) |
1210 | 1220 |
|
0 commit comments