Skip to content

Commit 5c7b7b6

Browse files
authored
Merge pull request numpy#26795 from vahidmech/fix_issue_26777
BUG: add order to out array of `numpy.fft`
2 parents 7050e26 + 0c36d55 commit 5c7b7b6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

numpy/fft/_pocketfft.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import warnings
3535

3636
from numpy.lib.array_utils import normalize_axis_index
37-
from numpy._core import (asarray, empty, zeros, swapaxes, result_type,
37+
from numpy._core import (asarray, empty_like, result_type,
3838
conjugate, take, sqrt, reciprocal)
3939
from . import _pocketfft_umath as pfu
4040
from numpy._core import overrides
@@ -85,8 +85,8 @@ def _raw_fft(a, n, axis, is_real, is_forward, norm, out=None):
8585
out_dtype = real_dtype
8686
else: # Others, complex output.
8787
out_dtype = result_type(a.dtype, 1j)
88-
out = empty(a.shape[:axis] + (n_out,) + a.shape[axis+1:],
89-
dtype=out_dtype)
88+
out = empty_like(a, shape=a.shape[:axis] + (n_out,) + a.shape[axis+1:],
89+
dtype=out_dtype)
9090
elif ((shape := getattr(out, "shape", None)) is not None
9191
and (len(shape) != a.ndim or shape[axis] != n_out)):
9292
raise ValueError("output array has wrong shape.")

numpy/fft/tests/test_pocketfft.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,16 @@ def test_fft_with_order(dtype, order, fft):
497497
raise ValueError()
498498

499499

500+
@pytest.mark.parametrize("order", ["F", "C"])
501+
@pytest.mark.parametrize("n", [None, 7, 12])
502+
def test_fft_output_order(order, n):
503+
rng = np.random.RandomState(42)
504+
x = rng.rand(10)
505+
x = np.asarray(x, dtype=np.complex64, order=order)
506+
res = np.fft.fft(x, n=n)
507+
assert res.flags.c_contiguous == x.flags.c_contiguous
508+
assert res.flags.f_contiguous == x.flags.f_contiguous
509+
500510
@pytest.mark.skipif(IS_WASM, reason="Cannot start thread")
501511
class TestFFTThreadSafe:
502512
threads = 16

0 commit comments

Comments
 (0)