Table of Contents

Class FourierModule

Namespace
NumSharp
Assembly
NumSharp.dll

The numpy.fft module surface, reachable as fft. Holds the 18 public transforms/helpers (standard fft/ifft/fft2/ifft2/fftn/ifftn, real rfft/irfft/rfft2/irfft2/rfftn/irfftn, hermitian hfft/ihfft, and helpers fftfreq/rfftfreq/fftshift/ifftshift).

The helpers (fftfreq/rfftfreq/fftshift/ifftshift) are pure compositions of existing np.* functions. The transforms validate and resolve everything NumPy's Python layer does — n/axis/norm/shape/dtype and the N-D→1-D decomposition — then compute through PocketFFTDriver.Execute, the managed port of pocketfft's 1-D engine (bit-identical to NumPy 2.4.2 on the double/complex128 path). The N-D wrappers are pure compositions of the 1-D transforms.

[ModuleName("np.fft")]
public class FourierModule
Inheritance
FourierModule
Inherited Members

Remarks

Methods

fft(NDArray, int?, int, string, NDArray)

Compute the one-dimensional discrete Fourier Transform.

public NDArray fft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

n int?

Length of the transformed axis of the output. Cropped/zero-padded from the input; defaults to a.shape[axis].

axis int

Axis over which to compute the FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output of the appropriate shape.

Returns

NDArray

Remarks

fft2(NDArray, int[], int[], string, NDArray)

Compute the 2-dimensional discrete Fourier Transform (over the last two axes by default). fft2 is fftn with a different default for axes.

public NDArray fft2(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

s int[]

Shape (length of each transformed axis) of the output; -1 uses the full input length. Defaults to the input shape along axes.

axes int[]

Axes over which to compute the FFT. Default (-2, -1).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output.

Returns

NDArray

Remarks

fftfreq(double, double, string)

Non-integer n is rejected exactly like NumPy (which requires an int-typed window length): ValueError("n should be an integer") — and this fires BEFORE the device/spacing checks, matching NumPy's isinstance guard at the top.

public NDArray fftfreq(double n, double d = 1, string device = null)

Parameters

n double

Window length (a floating value — always rejected).

d double

Sample spacing.

device string

Array-API device (unreached — the integer check throws first).

Returns

NDArray

Remarks

fftfreq(int, double, string)

Return the Discrete Fourier Transform sample frequencies. f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (dn) (n even); f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (dn) (n odd).

public NDArray fftfreq(int n, double d = 1, string device = null)

Parameters

n int

Window length.

d double

Sample spacing (inverse of the sampling rate). Default 1.

device string

Array-API device; must be null or "cpu".

Returns

NDArray

A float64 array of length n.

Remarks

fftfreq(long, double, string)

fftfreq(int, double, string) for a 64-bit window length. NumPy accepts ANY integer type (Python int / np.integer), so a C# long must compute rather than fall to the float-rejecting overload.

public NDArray fftfreq(long n, double d = 1, string device = null)

Parameters

n long
d double
device string

Returns

NDArray

fftn(NDArray, int[], int[], string, NDArray)

Compute the N-dimensional discrete Fourier Transform over the given axes (all axes by default). Pure composition of 1-D fft(NDArray, int?, int, string, NDArray) per axis.

public NDArray fftn(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

s int[]

Per-axis output lengths; -1 uses the full input length. Defaults to the input shape along axes.

axes int[]

Axes over which to compute the FFT (default: all axes, or the last len(s) when only s is given).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output.

Returns

NDArray

Remarks

fftshift(NDArray, int)

Shift the zero-frequency component to the center of the spectrum, over a single axis.

public NDArray fftshift(NDArray x, int axes)

Parameters

x NDArray

Input array.

axes int

Axis over which to shift (NumPy's axes also accepts a single int).

Returns

NDArray

Remarks

fftshift(NDArray, int[])

Shift the zero-frequency component to the center of the spectrum. Rolls every axis by shape[axis] // 2. (All-axes form; axes defaults to all.)

public NDArray fftshift(NDArray x, int[] axes = null)

Parameters

x NDArray

Input array.

axes int[]

Axes over which to shift; null shifts all axes.

Returns

NDArray

Remarks

hfft(NDArray, int?, int, string, NDArray)

Compute the FFT of a signal that has Hermitian symmetry (a real spectrum). Defined as irfft(conjugate(a), n, axis, norm=_swap_direction(norm)). The output is real; its length along the axis is n, or 2*(m-1) when n is omitted.

public NDArray hfft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array.

n int?

Length of the transformed axis of the output (default 2*(m-1)).

axis int

Axis over which to compute the FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Accepted for signature parity; NumPy passes out=None into irfft.

Returns

NDArray

Remarks

ifft(NDArray, int?, int, string, NDArray)

Compute the one-dimensional inverse discrete Fourier Transform (ifft(fft(a)) == a).

public NDArray ifft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

n int?

Length of the transformed axis of the output (default a.shape[axis]).

axis int

Axis over which to compute the inverse FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output of the appropriate shape.

Returns

NDArray

Remarks

ifft2(NDArray, int[], int[], string, NDArray)

Compute the 2-dimensional inverse discrete Fourier Transform (over the last two axes by default). ifft2 is ifftn with a different default for axes. Like NumPy, the provided out is not threaded through the composition.

public NDArray ifft2(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

s int[]

Per-axis output lengths; -1 uses the full input length.

axes int[]

Axes over which to compute the inverse FFT. Default (-2, -1).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Accepted for signature parity; NumPy passes out=None internally.

Returns

NDArray

Remarks

ifftn(NDArray, int[], int[], string, NDArray)

Compute the N-dimensional inverse discrete Fourier Transform (ifftn(fftn(a)) == a). Pure composition of 1-D ifft(NDArray, int?, int, string, NDArray) per axis.

public NDArray ifftn(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array, can be complex.

s int[]

Per-axis output lengths; -1 uses the full input length.

axes int[]

Axes over which to compute the inverse FFT (default: all axes).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output.

Returns

NDArray

Remarks

ifftshift(NDArray, int)

The inverse of fftshift(NDArray, int), over a single axis.

public NDArray ifftshift(NDArray x, int axes)

Parameters

x NDArray

Input array.

axes int

Axis over which to shift (NumPy's axes also accepts a single int).

Returns

NDArray

Remarks

ifftshift(NDArray, int[])

The inverse of fftshift(NDArray, int[]). Rolls every axis by -(shape[axis] // 2) (identical to fftshift for even lengths; differs by one sample for odd lengths). (All-axes form; axes defaults to all.)

public NDArray ifftshift(NDArray x, int[] axes = null)

Parameters

x NDArray

Input array.

axes int[]

Axes over which to shift; null shifts all axes.

Returns

NDArray

Remarks

ihfft(NDArray, int?, int, string, NDArray)

Compute the inverse FFT of a signal that has Hermitian symmetry. Defined as conjugate(rfft(a, n, axis, norm=_swap_direction(norm)), out=out). The output is complex; its length along the axis is n//2 + 1.

public NDArray ihfft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array.

n int?

Length of the inverse FFT along the transform axis (default a.shape[axis]).

axis int

Axis over which to compute the inverse FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output (threaded into rfft and the conjugate).

Returns

NDArray

Remarks

irfft(NDArray, int?, int, string, NDArray)

Compute the inverse of rfft(NDArray, int?, int, string, NDArray) — a real-valued output. For n output points, n//2+1 input points are used; when n is omitted it defaults to 2*(m-1) where m is the input length along the axis.

public NDArray irfft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array (the non-negative-frequency half-spectrum).

n int?

Length of the transformed (real) axis of the output. Default 2*(m-1).

axis int

Axis over which to compute the inverse FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated real (float64) output of length n on the axis.

Returns

NDArray

Remarks

irfft2(NDArray, int[], int[], string, NDArray)

Compute the inverse of rfft2(NDArray, int[], int[], string, NDArray). irfft2 is irfftn with the default axes of (-2, -1). Like NumPy, the provided out is not threaded through the composition.

public NDArray irfft2(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array.

s int[]

Per-axis output lengths; -1 uses the full input length.

axes int[]

Axes over which to compute the inverse FFT. Default (-2, -1).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Accepted for signature parity; NumPy passes out=None internally.

Returns

NDArray

Remarks

irfftn(NDArray, int[], int[], string, NDArray)

Compute the inverse of rfftn(NDArray, int[], int[], string, NDArray): ifft(NDArray, int?, int, string, NDArray) over all axes but the last, then irfft(NDArray, int?, int, string, NDArray) over the last axis (real output). The last-axis default length is 2*(m-1) (see CookNdArgs(NDArray, int[], int[], bool) with invreal).

public NDArray irfftn(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array.

s int[]

Per-axis output lengths; -1 uses the full input length.

axes int[]

Axes over which to compute the inverse FFT (default: all axes).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated real (float64) output for the final transform.

Returns

NDArray

Remarks

rfft(NDArray, int?, int, string, NDArray)

Compute the one-dimensional discrete Fourier Transform for real input. The output length along the axis is n//2 + 1 (the non-negative-frequency half).

public NDArray rfft(NDArray a, int? n = null, int axis = -1, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array (taken to be real).

n int?

Number of points along the transform axis to use (default a.shape[axis]).

axis int

Axis over which to compute the FFT (default the last axis).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output of shape (..., n//2+1, ...).

Returns

NDArray

Remarks

rfft2(NDArray, int[], int[], string, NDArray)

Compute the 2-dimensional FFT of a real array. rfft2 is rfftn with the default axes of (-2, -1).

public NDArray rfft2(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array (taken to be real).

s int[]

Per-axis output lengths; -1 uses the full input length.

axes int[]

Axes over which to compute the FFT. Default (-2, -1).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output.

Returns

NDArray

Remarks

rfftfreq(double, double, string)

Non-integer n is rejected exactly like NumPy: ValueError("n should be an integer") (fires before the device/spacing checks).

public NDArray rfftfreq(double n, double d = 1, string device = null)

Parameters

n double

Window length (a floating value — always rejected).

d double

Sample spacing.

device string

Array-API device (unreached — the integer check throws first).

Returns

NDArray

Remarks

rfftfreq(int, double, string)

Return the Discrete Fourier Transform sample frequencies (for usage with rfft, irfft). f = [0, 1, ..., n/2] / (d*n) — the Nyquist component is positive.

public NDArray rfftfreq(int n, double d = 1, string device = null)

Parameters

n int

Window length.

d double

Sample spacing (inverse of the sampling rate). Default 1.

device string

Array-API device; must be null or "cpu".

Returns

NDArray

A float64 array of length n//2 + 1.

Remarks

rfftfreq(long, double, string)

rfftfreq(int, double, string) for a 64-bit window length (see the long rationale on fftfreq(long, double, string)).

public NDArray rfftfreq(long n, double d = 1, string device = null)

Parameters

n long
d double
device string

Returns

NDArray

rfftn(NDArray, int[], int[], string, NDArray)

Compute the N-dimensional discrete Fourier Transform for real input: rfft(NDArray, int?, int, string, NDArray) over the LAST transformed axis, then fft(NDArray, int?, int, string, NDArray) over the remaining axes.

public NDArray rfftn(NDArray a, int[] s = null, int[] axes = null, string norm = null, NDArray @out = null)

Parameters

a NDArray

Input array (taken to be real).

s int[]

Per-axis output lengths; the final element is n for rfft, the rest are n for fft. -1 uses the full input length.

axes int[]

Axes over which to compute the FFT (default: all axes).

norm string

Normalization mode: null/"backward"/"ortho"/"forward".

out NDArray

Optional pre-allocated complex output.

Returns

NDArray

Remarks