|
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 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,37 @@ 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 | +
|
| 765 | + .. deprecated:: 2.0 |
| 766 | +
|
| 767 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 768 | + values currently mean that the default value for ``n`` is used |
| 769 | + in the corresponding 1-D transform, but this behaviour is |
| 770 | + deprecated. |
| 771 | +
|
736 | 772 | axes : sequence of ints, optional
|
737 | 773 | Axes over which to compute the FFT. If not given, the last ``len(s)``
|
738 | 774 | axes are used, or all axes if `s` is also not specified.
|
739 | 775 | Repeated indices in `axes` means that the transform over that axis is
|
740 | 776 | performed multiple times.
|
| 777 | +
|
| 778 | + .. deprecated:: 2.0 |
| 779 | +
|
| 780 | + If `s` is specified, the corresponding `axes` to be transformed |
| 781 | + must be explicitly specified too. |
| 782 | +
|
741 | 783 | norm : {"backward", "ortho", "forward"}, optional
|
742 | 784 | .. versionadded:: 1.10.0
|
743 | 785 |
|
@@ -842,14 +884,37 @@ def ifftn(a, s=None, axes=None, norm=None):
|
842 | 884 | (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
843 | 885 | This corresponds to ``n`` for ``ifft(x, n)``.
|
844 | 886 | 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. |
| 887 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 888 | +
|
| 889 | + .. versionchanged:: 2.0 |
| 890 | +
|
| 891 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 892 | +
|
| 893 | + If `s` is not given, the shape of the input along the axes specified |
| 894 | + by `axes` is used. See notes for issue on `ifft` zero padding. |
| 895 | +
|
| 896 | + .. deprecated:: 2.0 |
| 897 | +
|
| 898 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 899 | +
|
| 900 | + .. deprecated:: 2.0 |
| 901 | +
|
| 902 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 903 | + values currently mean that the default value for ``n`` is used |
| 904 | + in the corresponding 1-D transform, but this behaviour is |
| 905 | + deprecated. |
| 906 | +
|
848 | 907 | axes : sequence of ints, optional
|
849 | 908 | Axes over which to compute the IFFT. If not given, the last ``len(s)``
|
850 | 909 | axes are used, or all axes if `s` is also not specified.
|
851 | 910 | Repeated indices in `axes` means that the inverse transform over that
|
852 | 911 | axis is performed multiple times.
|
| 912 | +
|
| 913 | + .. deprecated:: 2.0 |
| 914 | +
|
| 915 | + If `s` is specified, the corresponding `axes` to be transformed |
| 916 | + must be explicitly specified too. |
| 917 | +
|
853 | 918 | norm : {"backward", "ortho", "forward"}, optional
|
854 | 919 | .. versionadded:: 1.10.0
|
855 | 920 |
|
@@ -937,14 +1002,37 @@ def fft2(a, s=None, axes=(-2, -1), norm=None):
|
937 | 1002 | (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
|
938 | 1003 | This corresponds to ``n`` for ``fft(x, n)``.
|
939 | 1004 | 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 |
| 1005 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 1006 | +
|
| 1007 | + .. versionchanged:: 2.0 |
| 1008 | +
|
| 1009 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1010 | +
|
| 1011 | + If `s` is not given, the shape of the input along the axes specified |
942 | 1012 | by `axes` is used.
|
| 1013 | +
|
| 1014 | + .. deprecated:: 2.0 |
| 1015 | +
|
| 1016 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1017 | +
|
| 1018 | + .. deprecated:: 2.0 |
| 1019 | +
|
| 1020 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 1021 | + values currently mean that the default value for ``n`` is used |
| 1022 | + in the corresponding 1-D transform, but this behaviour is |
| 1023 | + deprecated. |
| 1024 | +
|
943 | 1025 | axes : sequence of ints, optional
|
944 | 1026 | Axes over which to compute the FFT. If not given, the last two
|
945 | 1027 | axes are used. A repeated index in `axes` means the transform over
|
946 | 1028 | that axis is performed multiple times. A one-element sequence means
|
947 | 1029 | that a one-dimensional FFT is performed.
|
| 1030 | +
|
| 1031 | + .. deprecated:: 2.0 |
| 1032 | +
|
| 1033 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1034 | + must be explicitly specified too. |
| 1035 | +
|
948 | 1036 | norm : {"backward", "ortho", "forward"}, optional
|
949 | 1037 | .. versionadded:: 1.10.0
|
950 | 1038 |
|
@@ -1040,14 +1128,37 @@ def ifft2(a, s=None, axes=(-2, -1), norm=None):
|
1040 | 1128 | Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
|
1041 | 1129 | ``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
|
1042 | 1130 | 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 |
| 1131 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 1132 | +
|
| 1133 | + .. versionchanged:: 2.0 |
| 1134 | +
|
| 1135 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1136 | +
|
| 1137 | + If `s` is not given, the shape of the input along the axes specified |
1045 | 1138 | by `axes` is used. See notes for issue on `ifft` zero padding.
|
| 1139 | +
|
| 1140 | + .. deprecated:: 2.0 |
| 1141 | +
|
| 1142 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1143 | +
|
| 1144 | + .. deprecated:: 2.0 |
| 1145 | +
|
| 1146 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 1147 | + values currently mean that the default value for ``n`` is used |
| 1148 | + in the corresponding 1-D transform, but this behaviour is |
| 1149 | + deprecated. |
| 1150 | +
|
1046 | 1151 | axes : sequence of ints, optional
|
1047 | 1152 | Axes over which to compute the FFT. If not given, the last two
|
1048 | 1153 | axes are used. A repeated index in `axes` means the transform over
|
1049 | 1154 | that axis is performed multiple times. A one-element sequence means
|
1050 | 1155 | that a one-dimensional FFT is performed.
|
| 1156 | +
|
| 1157 | + .. deprecated:: 2.0 |
| 1158 | +
|
| 1159 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1160 | + must be explicitly specified too. |
| 1161 | +
|
1051 | 1162 | norm : {"backward", "ortho", "forward"}, optional
|
1052 | 1163 | .. versionadded:: 1.10.0
|
1053 | 1164 |
|
@@ -1128,12 +1239,35 @@ def rfftn(a, s=None, axes=None, norm=None):
|
1128 | 1239 | The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
|
1129 | 1240 | for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
|
1130 | 1241 | 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 |
| 1242 | + the input is cropped. If it is larger, the input is padded with zeros. |
| 1243 | +
|
| 1244 | + .. versionchanged:: 2.0 |
| 1245 | +
|
| 1246 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1247 | +
|
| 1248 | + If `s` is not given, the shape of the input along the axes specified |
1133 | 1249 | by `axes` is used.
|
| 1250 | +
|
| 1251 | + .. deprecated:: 2.0 |
| 1252 | +
|
| 1253 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1254 | +
|
| 1255 | + .. deprecated:: 2.0 |
| 1256 | +
|
| 1257 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 1258 | + values currently mean that the default value for ``n`` is used |
| 1259 | + in the corresponding 1-D transform, but this behaviour is |
| 1260 | + deprecated. |
| 1261 | +
|
1134 | 1262 | axes : sequence of ints, optional
|
1135 | 1263 | Axes over which to compute the FFT. If not given, the last ``len(s)``
|
1136 | 1264 | axes are used, or all axes if `s` is also not specified.
|
| 1265 | +
|
| 1266 | + .. deprecated:: 2.0 |
| 1267 | +
|
| 1268 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1269 | + must be explicitly specified too. |
| 1270 | +
|
1137 | 1271 | norm : {"backward", "ortho", "forward"}, optional
|
1138 | 1272 | .. versionadded:: 1.10.0
|
1139 | 1273 |
|
@@ -1284,14 +1418,38 @@ def irfftn(a, s=None, axes=None, norm=None):
|
1284 | 1418 | where ``s[-1]//2+1`` points of the input are used.
|
1285 | 1419 | Along any axis, if the shape indicated by `s` is smaller than that of
|
1286 | 1420 | 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 |
| 1421 | + with zeros. |
| 1422 | +
|
| 1423 | + .. versionchanged:: 2.0 |
| 1424 | +
|
| 1425 | + If it is ``-1``, the whole input is used (no padding/trimming). |
| 1426 | +
|
| 1427 | + If `s` is not given, the shape of the input along the axes |
1288 | 1428 | specified by axes is used. Except for the last axis which is taken to
|
1289 | 1429 | be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
|
| 1430 | +
|
| 1431 | + .. deprecated:: 2.0 |
| 1432 | +
|
| 1433 | + If `s` is not ``None``, `axes` must not be ``None`` either. |
| 1434 | +
|
| 1435 | + .. deprecated:: 2.0 |
| 1436 | +
|
| 1437 | + `s` must contain only ``int``s, not ``None`` values. ``None`` |
| 1438 | + values currently mean that the default value for ``n`` is used |
| 1439 | + in the corresponding 1-D transform, but this behaviour is |
| 1440 | + deprecated. |
| 1441 | +
|
1290 | 1442 | axes : sequence of ints, optional
|
1291 | 1443 | Axes over which to compute the inverse FFT. If not given, the last
|
1292 | 1444 | `len(s)` axes are used, or all axes if `s` is also not specified.
|
1293 | 1445 | Repeated indices in `axes` means that the inverse transform over that
|
1294 | 1446 | axis is performed multiple times.
|
| 1447 | +
|
| 1448 | + .. deprecated:: 2.0 |
| 1449 | +
|
| 1450 | + If `s` is specified, the corresponding `axes` to be transformed |
| 1451 | + must be explicitly specified too. |
| 1452 | +
|
1295 | 1453 | norm : {"backward", "ortho", "forward"}, optional
|
1296 | 1454 | .. versionadded:: 1.10.0
|
1297 | 1455 |
|
|
0 commit comments