(a, n, axis, is_real, is_forward, norm, out=None)
| 56 | # divisions by zero (or alternatively additional checks) in the case of |
| 57 | # zero-length axes during its computation. |
| 58 | def _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", |
no test coverage detected
searching dependent graphs…