MCPcopy
hub / github.com/numpy/numpy / _raw_fft

Function _raw_fft

numpy/fft/_pocketfft.py:58–101  ·  view source on GitHub ↗
(a, n, axis, is_real, is_forward, norm, out=None)

Source from the content-addressed store, hash-verified

56# divisions by zero (or alternatively additional checks) in the case of
57# zero-length axes during its computation.
58def _raw_fft(a, n, axis, is_real, is_forward, norm, out=None):
59 if n < 1:
60 raise ValueError(f"Invalid number of FFT data points ({n}) specified.")
61
62 # Calculate the normalization factor, passing in the array dtype to
63 # avoid precision loss in the possible sqrt or reciprocal.
64 if not is_forward:
65 norm = _swap_direction(norm)
66
67 real_dtype = result_type(a.real.dtype, 1.0)
68 if norm is None or norm == "backward":
69 fct = 1
70 elif norm == "ortho":
71 fct = reciprocal(sqrt(n, dtype=real_dtype))
72 elif norm == "forward":
73 fct = reciprocal(n, dtype=real_dtype)
74 else:
75 raise ValueError(f'Invalid norm value {norm}; should be "backward",'
76 '"ortho" or "forward".')
77
78 n_out = n
79 if is_real:
80 if is_forward:
81 ufunc = pfu.rfft_n_even if n % 2 == 0 else pfu.rfft_n_odd
82 n_out = n // 2 + 1
83 else:
84 ufunc = pfu.irfft
85 else:
86 ufunc = pfu.fft if is_forward else pfu.ifft
87
88 axis = normalize_axis_index(axis, a.ndim)
89
90 if out is None:
91 if is_real and not is_forward: # irfft, complex in, real output.
92 out_dtype = real_dtype
93 else: # Others, complex output.
94 out_dtype = result_type(a.dtype, 1j)
95 out = empty_like(a, shape=a.shape[:axis] + (n_out,) + a.shape[axis + 1:],
96 dtype=out_dtype)
97 elif ((shape := getattr(out, "shape", None)) is not None
98 and (len(shape) != a.ndim or shape[axis] != n_out)):
99 raise ValueError("output array has wrong shape.")
100
101 return ufunc(a, fct, axes=[(axis,), (), (axis,)], out=out)
102
103
104_SWAP_DIRECTION_MAP = {"backward": "forward", None: "forward",

Callers 4

fftFunction · 0.85
ifftFunction · 0.85
rfftFunction · 0.85
irfftFunction · 0.85

Calls 4

result_typeFunction · 0.90
empty_likeFunction · 0.90
_swap_directionFunction · 0.85
sqrtFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…