|
31 | 31 | 'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
|
32 | 32 |
|
33 | 33 | import functools
|
| 34 | +import warnings |
34 | 35 |
|
35 | 36 | from numpy.lib.array_utils import normalize_axis_index
|
36 | 37 | from numpy._core import asarray, zeros, swapaxes, conjugate, take, sqrt
|
@@ -681,20 +682,38 @@ def ihfft(a, n=None, axis=-1, norm=None):
|
681 | 682 |
|
682 | 683 | def _cook_nd_args(a, s=None, axes=None, invreal=0):
|
683 | 684 | if s is None:
|
684 |
| - shapeless = 1 |
| 685 | + shapeless = True |
685 | 686 | if axes is None:
|
686 | 687 | s = list(a.shape)
|
687 | 688 | else:
|
688 | 689 | s = take(a.shape, axes)
|
689 | 690 | else:
|
690 |
| - shapeless = 0 |
| 691 | + shapeless = False |
691 | 692 | s = list(s)
|
692 | 693 | if axes is None:
|
| 694 | + if not shapeless: |
| 695 | + msg = ("`axes` should not be `None` if `s` is not `None` " |
| 696 | + "(Deprecated in NumPy 2.0). In a future version of NumPy, " |
| 697 | + "this will raise an error
8000
and `s[i]` will correspond to " |
| 698 | + "the size along the transformed axis specified by " |
| 699 | + "`axes[i]`. To retain current behaviour, pass a sequence " |
| 700 | + "[0, ..., k-1] to `axes` for an array of dimension k.") |
| 701 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
693 | 702 | axes = list(range(-len(s), 0))
|
694 | 703 | if len(s) != len(axes):
|
695 | 704 | raise ValueError("Shape and axes have different lengths.")
|
696 | 705 | if invreal and shapeless:
|
697 | 706 | s[-1] = (a.shape[axes[-1]] - 1) * 2
|
| 707 | + if None in s: |
| 708 | + msg = ("Passing an array containing `None` values to `s` is " |
| 709 | + "deprecated in NumPy 2.0 and will raise an error in " |
| 710 | + "a future version of NumPy. To use the default behaviour " |
| 711 | + "of the corresponding 1-D transform, pass the value matching " |
| 712 | + "the default for its `n` parameter. To use the default " |
| 713 | + "behaviour for every axis, the `s` argument can be omitted.") |
| 714 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
| 715 | + # use the whole input array along axis `i` if `s[i] == -1` |
| 716 | + s = [a.shape[_a] if _s == -1 else _s for _s, _a in zip(s, axes)] |
698 | 717 | return s, axes
|
699 | 718 |
|
700 | 719 |
|
@@ -730,14 +749,30 @@ def fftn(a, s=None, axes=None, norm=None):
|
730 | 749 | (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
731 | 750 | This corresponds to ``n`` for ``fft(x, n)``.
|
732 | 751 | Along any axis, if the given shape is smaller than that of the input,
|
733 |
| - the input is cropped. If it is larger, the input is padded with zeros. |
734 |
| - if `s` is not given, the shape of the input along the axes specified |
| 752 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 753 | +
|
| 754 | + .. versionchanged:: 2.0 |
| 755 | +
|
| 756 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 757 | +
|
| 758 | + If `s` is not given, the shape of the input along the axes specified |
735 | 759 | by `axes` is used.
|
| 760 | +
|
| 761 | + .. deprecated:: 2.0 |
| 762 | +
|
| 763 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 764 | +
|
736 | 765 | axes : sequence of ints, optional
|
737 | 766 | Axes over which to compute the FFT. If not given, the last ``len(s)``
|
738 | 767 | axes are used, or all axes if `s` is also not specified.
|
739 | 768 | Repeated indices in `axes` means that the transform over that axis is
|
740 | 769 | performed multiple times.
|
| 770 | +
|
| 771 | + .. deprecated:: 2.0 |
| 772 | +
|
| 773 | + If `s` is specified, the corresponding `axes` to be transformed |
| 774 | + must be explicitly specified too. |
| 775 | +
|
741 | 776 | norm : {"backward", "ortho", "forward"}, optional
|
742 | 777 | .. versionadded:: 1.10.0
|
743 | 778 |
|
@@ -842,14 +877,30 @@ def ifftn(a, s=None, axes=None, norm=None):
|
842 | 877 | (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
843 | 878 | This corresponds to ``n`` for ``ifft(x, n)``.
|
844 | 879 | Along any axis, if the given shape is smaller than that of the input,
|
845 |
| - the input is cropped. If it is larger, the input is padded with zeros. |
846 |
| - if `s` is not given, the shape of the input along the axes specified |
847 |
| - by `axes` is used. See notes for issue on `ifft` zero padding. |
| 880 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 881 | +
|
| 882 | + .. versionchanged:: 2.0 |
| 883 | +
|
| 884 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 885 | +
|
| 886 | + If `s` is not given, the shape of the input along the axes specified |
| 887 | + by `axes` is used. See notes for issue on `ifft` zero padding. |
| 888 | +
|
| 889 | + .. deprecated:: 2.0 |
| 890 | +
|
| 891 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 892 | +
|
848 | 893 | axes : sequence of ints, optional
|
849 | 894 | Axes over which to compute the IFFT. If not given, the last ``len(s)``
|
850 | 895 | axes are used, or all axes if `s` is also not specified.
|
851 | 896 | Repeated indices in `axes` means that the inverse transform over that
|
852 | 897 | axis is performed multiple times.
|
| 898 | +
|
| 899 | + .. deprecated:: 2.0 |
| 900 | +
|
| 901 | + If `s` is specified, the corresponding `axes` to be transformed |
| 902 | + must be explicitly specified too. |
| 903 | +
|
853 | 904 | norm : {"backward", "ortho", "forward"}, optional
|
854 | 905 | .. versionadded:: 1.10.0
|
855 | 906 |
|
@@ -937,8 +988,13 @@ def fft2(a, s=None, axes=(-2, -1), norm=None):
|
937 | 988 | (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
938 | 989 | This corresponds to ``n`` for ``fft(x, n)``.
|
939 | 990 | Along each axis, if the given shape is smaller than that of the input,
|
940 |
| - the input is cropped. If it is larger, the input is padded with zeros. |
941 |
| - if `s` is not given, the shape of the input along the axes specified |
| 991 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 992 | +
|
| 993 | + .. versionchanged:: 2.0 |
| 994 | +
|
| 995 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 996 | +
|
| 997 | + If `s` is not given, the shape of the input along the axes specified |
942 | 998 | by `axes` is used.
|
943 | 999 | axes : sequence of ints, optional
|
944 | 1000 | Axes over which to compute the FFT. If not given, the last two
|
@@ -1040,8 +1096,13 @@ def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
1040 | 1096 | Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
|
1041 | 1097 | ``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
|
1042 | 1098 | Along each axis, if the given shape is smaller than that of the input,
|
1043 |
| - the input is cropped. If it is larger, the input is padded with zeros. |
1044 |
| - if `s` is not given, the shape of the input along the axes specified |
| 1099 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 1100 | +
|
| 1101 | + .. versionchanged:: 2.0 |
| 1102 | +
|
| 1103 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1104 | +
|
| 1105 | + If `s` is not given, the shape of the input along the axes specified |
1045 | 1106 | by `axes` is used. See notes for issue on `ifft` zero padding.
|
1046 | 1107 | axes : sequence of ints, optional
|
1047 | 1108 | Axes over which to compute the FFT. If not given, the last two
|
@@ -1128,12 +1189,28 @@ def rfftn(a, s=None, axes=None, norm=None):
|
1128 | 1189 | The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
|
1129 | 1190 | for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
|
1130 | 1191 | Along any axis, if the given shape is smaller than that of the input,
|
1131 |
| - the input is cropped. If it is larger, the input is padded with zeros. |
1132 |
| - if `s` is not given, the shape of the input along the axes specified |
| 1192 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 1193 | +
|
| 1194 | + .. versionchanged:: 2.0 |
| 1195 | +
|
| 1196 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1197 | +
|
| 1198 | + If `s` is not given, the shape of the input along the axes specified |
1133 | 1199 | by `axes` is used.
|
| 1200 | +
|
| 1201 | + .. deprecated:: 2.0 |
| 1202 | +
|
| 1203 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1204 | +
|
1134 | 1205 | axes : sequence of ints, optional
|
1135 | 1206 | Axes over which to compute the FFT. If not given, the last ``len(s)``
|
1136 | 1207 | axes are used, or all axes if `s` is also not specified.
|
| 1208 | +
|
| 1209 | + .. deprecated:: 2.0 |
| 1210 | +
|
| 1211 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1212 | + must be explicitly specified too. |
| 1213 | +
|
1137 | 1214 | norm : {"backward", "ortho", "forward"}, optional
|
1138 | 1215 | .. versionadded:: 1.10.0
|
1139 | 1216 |
|
@@ -1284,14 +1361,31 @@ def irfftn(a, s=None, axes=None, norm=None):
|
1284 | 1361 | where ``s[-1]//2+1`` points of the input are used.
|
1285 | 1362 | Along any axis, if the shape indicated by `s` is smaller than that of
|
1286 | 1363 | the input, the input is cropped. If it is larger, the input is padded
|
1287 |
| - with zeros. If `s` is not given, the shape of the input along the axes |
| 1364 | + with zeros. |
| 1365 | +
|
| 1366 | + .. versionchanged:: 2.0 |
| 1367 | +
|
| 1368 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1369 | +
|
| 1370 | + If `s` is not given, the shape of the input along the axes |
1288 | 1371 | specified by axes is used. Except for the last axis which is taken to
|
1289 | 1372 | be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
|
| 1373 | +
|
| 1374 | + .. deprecated:: 2.0 |
| 1375 | +
|
| 1376 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1377 | +
|
1290 | 1378 | axes : sequence of ints, optional
|
1291 | 1379 | Axes over which to compute the inverse FFT. If not given, the last
|
1292 | 1380 | `len(s)` axes are used, or all axes if `s` is also not specified.
|
1293 | 1381 | Repeated indices in `axes` means that the inverse transform over that
|
1294 | 1382 | axis is performed multiple times.
|
| 1383 | +
|
| 1384 | + .. deprecated:: 2.0 |
| 1385 | +
|
| 1386 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1387 | + must be explicitly specified too. |
| 1388 | +
|
1295 | 1389 | norm : {"backward", "ortho", "forward"}, optional
|
1296 | 1390 | .. versionadded:: 1.10.0
|
1297 | 1391 |
|
|
0 commit comments