|
71 | 71 | ]
|
72 | 72 |
|
73 | 73 | import re
|
| 74 | +import warnings |
74 | 75 |
|
75 | 76 | from numpy import array, asanyarray, conjugate, prod, sqrt, take
|
76 | 77 |
|
@@ -688,22 +689,46 @@ def ihfft(a, n=None, axis=-1, norm=None):
|
688 | 689 | return output
|
689 | 690 |
|
690 | 691 |
|
691 |
| -def _cook_nd_args(a, s=None, axes=None, invreal=0): |
| 692 | +# copied from: https://github.com/numpy/numpy/blob/main/numpy/fft/_pocketfft.py |
| 693 | +def _cook_nd_args(a, s=None, axes=None, invreal=False): |
692 | 694 | if s is None:
|
693 |
| - shapeless = 1 |
| 695 | + shapeless = True |
694 | 696 | if axes is None:
|
695 | 697 | s = list(a.shape)
|
696 | 698 | else:
|
697 | 699 | s = take(a.shape, axes)
|
698 | 700 | else:
|
699 |
| - shapeless = 0 |
| 701 | + shapeless = False |
700 | 702 | s = list(s)
|
701 | 703 | if axes is None:
|
| 704 | + if not shapeless: |
| 705 | + msg = ( |
| 706 | + "`axes` should not be `None` if `s` is not `None` " |
| 707 | + "(Deprecated in NumPy 2.0). In a future version of NumPy, " |
| 708 | + "this will raise an error and `s[i]` will correspond to " |
| 709 | + "the size along the transformed axis specified by " |
| 710 | + "`axes[i]`. To retain current behaviour, pass a sequence " |
| 711 | + "[0, ..., k-1] to `axes` for an array of dimension k." |
| 712 | + ) |
| 713 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
702 | 714 | axes = list(range(-len(s), 0))
|
703 | 715 | if len(s) != len(axes):
|
704 | 716 | raise ValueError("Shape and axes have different lengths.")
|
705 | 717 | if invreal and shapeless:
|
706 | 718 | s[-1] = (a.shape[axes[-1]] - 1) * 2
|
| 719 | + if None in s: |
| 720 | + msg = ( |
| 721 | + "Passing an array containing `None` values to `s` is " |
| 722 | + "deprecated in NumPy 2.0 and will raise an error in " |
| 723 | + "a future version of NumPy. To use the default behaviour " |
| 724 | + "of the corresponding 1-D transform, pass the value matching " |
| 725 | + "the default for its `n` parameter. To use the default " |
| 726 | + "behaviour for every axis, the `s` argument can be omitted." |
| 727 | + ) |
| 728 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
| 729 | + # use the whole input array along axis `i` if `s[i] == -1 or None` |
| 730 | + s = [a.shape[_a] if _s in [-1, None] else _s for _s, _a in zip(s, axes)] |
| 731 | + |
707 | 732 | return s, axes
|
708 | 733 |
|
709 | 734 |
|
@@ -808,6 +833,7 @@ def fftn(a, s=None, axes=None, norm=None):
|
808 | 833 | """
|
809 | 834 | _check_norm(norm)
|
810 | 835 | x = _float_utils.__downcast_float128_array(a)
|
| 836 | + s, axes = _cook_nd_args(x, s, axes) |
811 | 837 |
|
812 | 838 | if norm in (None, "backward"):
|
813 | 839 | fsc = 1.0
|
@@ -920,6 +946,7 @@ def ifftn(a, s=None, axes=None, norm=None):
|
920 | 946 | """
|
921 | 947 | _check_norm(norm)
|
922 | 948 | x = _float_utils.__downcast_float128_array(a)
|
| 949 | + s, axes = _cook_nd_args(x, s, axes) |
923 | 950 |
|
924 | 951 | if norm in (None, "backward"):
|
925 | 952 | fsc = 1.0
|
@@ -1215,6 +1242,7 @@ def rfftn(a, s=None, axes=None, norm=None):
|
1215 | 1242 | """
|
1216 | 1243 | _check_norm(norm)
|
1217 | 1244 | x = _float_utils.__downcast_float128_array(a)
|
| 1245 | + s, axes = _cook_nd_args(x, s, axes) |
1218 | 1246 |
|
1219 | 1247 | if norm in (None, "backward"):
|
1220 | 1248 | fsc = 1.0
|
@@ -1369,16 +1397,15 @@ def irfftn(a, s=None, axes=None, norm=None):
|
1369 | 1397 | """
|
1370 | 1398 | _check_norm(norm)
|
1371 | 1399 | x = _float_utils.__downcast_float128_array(a)
|
| 1400 | + s, axes = _cook_nd_args(x, s, axes, invreal=True) |
1372 | 1401 |
|
1373 | 1402 | if norm in (None, "backward"):
|
1374 | 1403 | fsc = 1.0
|
1375 | 1404 | elif norm == "forward":
|
1376 | 1405 | x = asanyarray(x)
|
1377 |
| - s, axes = _cook_nd_args(x, s, axes, invreal=1) |
1378 | 1406 | fsc = frwd_sc_nd(s, x.shape)
|
1379 | 1407 | else:
|
1380 | 1408 | x = asanyarray(x)
|
1381 |
| - s, axes = _cook_nd_args(x, s, axes, invreal=1) |
1382 | 1409 | fsc = sqrt(frwd_sc_nd(s, x.shape))
|
1383 | 1410 |
|
1384 | 1411 | return trycall(
|
|
0 commit comments