@@ -681,20 +681,24 @@ def ihfft(a, n=None, axis=-1, norm=None):
681
681
682
682
def _cook_nd_args (a , s = None , axes = None , invreal = 0 ):
683
683
if s is None :
684
- shapeless = 1
684
+ shapeless = True
685
685
if axes is None :
686
686
s = list (a .shape )
687
687
else :
688
688
s = take (a .shape , axes )
689
689
else :
690
- shapeless = 0
690
+ shapeless = False
691
691
s = list (s )
692
692
if axes is None :
693
+ if not shapeless :
694
+ msg = "`axes` must not be `None` if `s` is not `None`."
695
+ raise ValueError (msg )
693
696
axes = list (range (- len (s ), 0 ))
694
697
if len (s ) != len (axes ):
695
698
raise ValueError ("Shape and axes have different lengths." )
696
699
if invreal and shapeless :
697
700
s [- 1 ] = (a .shape [axes [- 1 ]] - 1 ) * 2
701
+ s = [a .shape [_a ] if _s == - 1 else _s for _s , _a in zip (s , axes )]
698
702
return s , axes
699
703
700
704
@@ -730,9 +734,11 @@ def fftn(a, s=None, axes=None, norm=None):
730
734
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
731
735
This corresponds to ``n`` for ``fft(x, n)``.
732
736
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
737
+ the input is cropped. If it is larger, the input is padded with zeros.
738
+ If it is ``-1``, the whole input is used (no padding/trimming).
739
+ If `s` is not given, the shape of the input along the axes specified
735
740
by `axes` is used.
741
+ If `s` is not ``None``, `axes` must not be ``None`` either.
736
742
axes : sequence of ints, optional
737
743
Axes over which to compute the FFT. If not given, the last ``len(s)``
738
744
axes are used, or all axes if `s` is also not specified.
@@ -842,9 +848,11 @@ def ifftn(a, s=None, axes=None, norm=None):
842
848
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
843
849
This corresponds to ``n`` for ``ifft(x, n)``.
844
850
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.
851
+ the input is cropped. If it is larger, the input is padded with zeros.
852
+ If it is ``-1``, the whole input is used (no padding/trimming).
853
+ If `s` is not given, the shape of the input along the axes specified
854
+ by `axes` is used. See notes for issue on `ifft` zero padding.
855
+ If `s` is not ``None``, `axes` must not be ``None`` either.
848
856
axes : sequence of ints, optional
849
857
Axes over which to compute the IFFT. If not given, the last ``len(s)``
850
858
axes are used, or all axes if `s` is also not specified.
@@ -937,8 +945,9 @@ def fft2(a, s=None, axes=(-2, -1), norm=None):
937
945
(``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.).
938
946
This corresponds to ``n`` for ``fft(x, n)``.
939
947
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
948
+ the input is cropped. If it is larger, the input is padded with zeros.
949
+ If it is ``-1``, the whole input is used (no padding/trimming).
950
+ If `s` is not given, the shape of the input along the axes specified
942
951
by `axes` is used.
943
952
axes : sequence of ints, optional
944
953
Axes over which to compute the FFT. If not given, the last two
@@ -1040,8 +1049,9 @@ def ifft2(a, s=None, axes=(-2, -1), norm=None):
1040
1049
Shape (length of each axis) of the output (``s[0]`` refers to axis 0,
1041
1050
``s[1]`` to axis 1, etc.). This corresponds to `n` for ``ifft(x, n)``.
1042
1051
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
1052
+ the input is cropped. If it is larger, the input is padded with zeros.
1053
+ If it is ``-1``, the whole input is used (no padding/trimming).
1054
+ If `s` is not given, the shape of the input along the axes specified
1045
1055
by `axes` is used. See notes for issue on `ifft` zero padding.
1046
1056
axes : sequence of ints, optional
1047
1057
Axes over which to compute the FFT. If not given, the last two
@@ -1128,9 +1138,11 @@ def rfftn(a, s=None, axes=None, norm=None):
1128
1138
The final element of `s` corresponds to `n` for ``rfft(x, n)``, while
1129
1139
for the remaining axes, it corresponds to `n` for ``fft(x, n)``.
1130
1140
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
1141
+ the input is cropped. If it is larger, the input is padded with zeros.
1142
+ If it is ``-1``, the whole input is used (no padding/trimming).
1143
+ If `s` is not given, the shape of the input along the axes specified
1133
1144
by `axes` is used.
1145
+ If `s` is not ``None``, `axes` must not be ``None`` either.
1134
1146
axes : sequence of ints, optional
1135
1147
Axes over which to compute the FFT. If not given, the last ``len(s)``
1136
1148
axes are used, or all axes if `s` is also not specified.
@@ -1284,9 +1296,12 @@ def irfftn(a, s=None, axes=None, norm=None):
1284
1296
where ``s[-1]//2+1`` points of the input are used.
1285
1297
Along any axis, if the shape indicated by `s` is smaller than that of
1286
1298
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
1299
+ with zeros.
1300
+ If it is ``-1``, the whole input is used (no padding/trimming).
1301
+ If `s` is not given, the shape of the input along the axes
1288
1302
specified by axes is used. Except for the last axis which is taken to
1289
1303
be ``2*(m-1)`` where ``m`` is the length of the input along that axis.
1304
+ If `s` is not ``None``, `axes` must not be ``None`` either.
1290
1305
axes : sequence of ints, optional
1291
1306
Axes over which to compute the inverse FFT. If not given, the last
1292
1307
`len(s)` axes are used, or all axes if `s` is also not specified.
0 commit comments