Skip to content

Commit 22c7913

Browse files
authored
BUG: fftn axis bug (numpy#27466)
* rfftn axis bug * added test on shapes and fixed the linter issue * linter length
1 parent 55d5fca commit 22c7913

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/fft/_pocketfft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ def rfftn(a, s=None, axes=None, norm=None, out=None):
13791379
a = asarray(a)
13801380
s, axes = _cook_nd_args(a, s, axes)
13811381
a = rfft(a, s[-1], axes[-1], norm, out=out)
1382-
for ii in range(len(axes)-1):
1382+
for ii in range(len(axes)-2, -1, -1):
13831383
a = fft(a, s[ii], axes[ii], norm, out=out)
13841384
return a
13851385

numpy/fft/tests/test_pocketfft.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ def test_rfftn(self):
307307
np.fft.rfftn(x, norm="ortho"), atol=1e-6)
308308
assert_allclose(np.fft.rfftn(x) / (30. * 20. * 10.),
309309
np.fft.rfftn(x, norm="forward"), atol=1e-6)
310+
# Regression test for gh-27159
311+
x = np.ones((2, 3))
312+
result = np.fft.rfftn(x, axes=(0, 0, 1), s=(10, 20, 40))
313+
assert result.shape == (10, 21)
314+
expected = np.fft.fft(np.fft.fft(np.fft.rfft(x, axis=1, n=40),
315+
axis=0, n=20), axis=0, n=10)
316+
assert expected.shape == (10, 21)
317+
assert_allclose(result, expected, atol=1e-6)
310318

311319
def test_irfftn(self):
312320
x = random((30, 20, 10))

0 commit comments

Comments
 (0)