|
62 | 62 | from . import _pydfti as mkl_fft |
63 | 63 | from . import _float_utils |
64 | 64 | import re |
| 65 | +import warnings |
65 | 66 |
|
66 | 67 | def _check_norm(norm): |
67 | 68 | if norm not in (None, "ortho", "forward", "backward"): |
@@ -691,22 +692,42 @@ def ihfft(a, n=None, axis=-1, norm=None): |
691 | 692 | return output |
692 | 693 |
|
693 | 694 |
|
694 | | -def _cook_nd_args(a, s=None, axes=None, invreal=0): |
| 695 | +# copied from: https://github.com/numpy/numpy/blob/main/numpy/fft/_pocketfft.py |
| 696 | +def _cook_nd_args(a, s=None, axes=None, invreal=False): |
695 | 697 | if s is None: |
696 | | - shapeless = 1 |
| 698 | + shapeless = True |
697 | 699 | if axes is None: |
698 | 700 | s = list(a.shape) |
699 | 701 | else: |
700 | 702 | s = take(a.shape, axes) |
701 | 703 | else: |
702 | | - shapeless = 0 |
| 704 | + shapeless = False |
703 | 705 | s = list(s) |
704 | 706 | if axes is None: |
| 707 | + if not shapeless: |
| 708 | + msg = ("`axes` should not be `None` if `s` is not `None` " |
| 709 | + "(Deprecated in NumPy 2.0). In a future version of NumPy, " |
| 710 | + "this will raise an error and `s[i]` will correspond to " |
| 711 | + "the size along the transformed axis specified by " |
| 712 | + "`axes[i]`. To retain current behaviour, pass a sequence " |
| 713 | + "[0, ..., k-1] to `axes` for an array of dimension k.") |
| 714 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
705 | 715 | axes = list(range(-len(s), 0)) |
706 | 716 | if len(s) != len(axes): |
707 | 717 | raise ValueError("Shape and axes have different lengths.") |
708 | 718 | if invreal and shapeless: |
709 | 719 | s[-1] = (a.shape[axes[-1]] - 1) * 2 |
| 720 | + if None in s: |
| 721 | + msg = ("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 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
| 728 | + # use the whole input array along axis `i` if `s[i] == -1 or None` |
| 729 | + s = [a.shape[_a] if _s in [-1, None] else _s for _s, _a in zip(s, axes)] |
| 730 | + |
710 | 731 | return s, axes |
711 | 732 |
|
712 | 733 |
|
@@ -811,6 +832,7 @@ def fftn(a, s=None, axes=None, norm=None): |
811 | 832 | """ |
812 | 833 | _check_norm(norm) |
813 | 834 | x = _float_utils.__downcast_float128_array(a) |
| 835 | + s, axes = _cook_nd_args(x, s, axes) |
814 | 836 |
|
815 | 837 | if norm in (None, "backward"): |
816 | 838 | fsc = 1.0 |
@@ -927,6 +949,7 @@ def ifftn(a, s=None, axes=None, norm=None): |
927 | 949 | """ |
928 | 950 | _check_norm(norm) |
929 | 951 | x = _float_utils.__downcast_float128_array(a) |
| 952 | + s, axes = _cook_nd_args(x, s, axes) |
930 | 953 |
|
931 | 954 | if norm in (None, "backward"): |
932 | 955 | fsc = 1.0 |
@@ -1224,16 +1247,15 @@ def rfftn(a, s=None, axes=None, norm=None): |
1224 | 1247 | """ |
1225 | 1248 | _check_norm(norm) |
1226 | 1249 | x = _float_utils.__downcast_float128_array(a) |
| 1250 | + s, axes = _cook_nd_args(x, s, axes) |
1227 | 1251 |
|
1228 | 1252 | if (norm in (None, "backward")): |
1229 | 1253 | fsc = 1.0 |
1230 | 1254 | elif norm == "forward": |
1231 | 1255 | x = asanyarray(x) |
1232 | | - s, axes = _cook_nd_args(x, s, axes) |
1233 | 1256 | fsc = frwd_sc_nd(s, axes, x.shape) |
1234 | 1257 | else: |
1235 | 1258 | x = asanyarray(x) |
1236 | | - s, axes = _cook_nd_args(x, s, axes) |
1237 | 1259 | fsc = sqrt(frwd_sc_nd(s, axes, x.shape)) |
1238 | 1260 |
|
1239 | 1261 | return trycall( |
@@ -1380,17 +1402,15 @@ def irfftn(a, s=None, axes=None, norm=None): |
1380 | 1402 | """ |
1381 | 1403 | _check_norm(norm) |
1382 | 1404 | x = _float_utils.__downcast_float128_array(a) |
1383 | | - |
| 1405 | + s, axes = _cook_nd_args(x, s, axes, invreal=True) |
1384 | 1406 |
|
1385 | 1407 | if (norm in (None, "backward")): |
1386 | 1408 | fsc = 1.0 |
1387 | 1409 | elif norm == "forward": |
1388 | 1410 | x = asanyarray(x) |
1389 | | - s, axes = _cook_nd_args(x, s, axes, invreal=1) |
1390 | 1411 | fsc = frwd_sc_nd(s, axes, x.shape) |
1391 | 1412 | else: |
1392 | 1413 | x = asanyarray(x) |
1393 | | - s, axes = _cook_nd_args(x, s, axes, invreal=1) |
1394 | 1414 | fsc = sqrt(frwd_sc_nd(s, axes, x.shape)) |
1395 | 1415 |
|
1396 | 1416 | return trycall( |
|
0 commit comments