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
aNDArrayInput array, can be complex.
nint?Length of the transformed axis of the output. Cropped/zero-padded from the input; defaults to
a.shape[axis].axisintAxis over which to compute the FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output of the appropriate shape.
Returns
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
aNDArrayInput array, can be complex.
sint[]Shape (length of each transformed axis) of the output;
-1uses the full input length. Defaults to the input shape alongaxes.axesint[]Axes over which to compute the FFT. Default
(-2, -1).normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output.
Returns
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
ndoubleWindow length (a floating value — always rejected).
ddoubleSample spacing.
devicestringArray-API device (unreached — the integer check throws first).
Returns
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
nintWindow length.
ddoubleSample spacing (inverse of the sampling rate). Default 1.
devicestringArray-API device; must be
nullor"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
Returns
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
aNDArrayInput array, can be complex.
sint[]Per-axis output lengths;
-1uses the full input length. Defaults to the input shape alongaxes.axesint[]Axes over which to compute the FFT (default: all axes, or the last
len(s)when onlysis given).normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output.
Returns
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
Returns
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
Returns
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
aNDArrayInput array.
nint?Length of the transformed axis of the output (default
2*(m-1)).axisintAxis over which to compute the FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayAccepted for signature parity; NumPy passes
out=Noneinto irfft.
Returns
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
aNDArrayInput array, can be complex.
nint?Length of the transformed axis of the output (default
a.shape[axis]).axisintAxis over which to compute the inverse FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output of the appropriate shape.
Returns
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
aNDArrayInput array, can be complex.
sint[]Per-axis output lengths;
-1uses the full input length.axesint[]Axes over which to compute the inverse FFT. Default
(-2, -1).normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayAccepted for signature parity; NumPy passes
out=Noneinternally.
Returns
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
aNDArrayInput array, can be complex.
sint[]Per-axis output lengths;
-1uses the full input length.axesint[]Axes over which to compute the inverse FFT (default: all axes).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output.
Returns
Remarks
ifftshift(NDArray, int)
The inverse of fftshift(NDArray, int), over a single axis.
public NDArray ifftshift(NDArray x, int axes)
Parameters
Returns
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
Returns
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
aNDArrayInput array.
nint?Length of the inverse FFT along the transform axis (default
a.shape[axis]).axisintAxis over which to compute the inverse FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output (threaded into rfft and the conjugate).
Returns
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
aNDArrayInput array (the non-negative-frequency half-spectrum).
nint?Length of the transformed (real) axis of the output. Default
2*(m-1).axisintAxis over which to compute the inverse FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated real (float64) output of length
non the axis.
Returns
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
aNDArrayInput array.
sint[]Per-axis output lengths;
-1uses the full input length.axesint[]Axes over which to compute the inverse FFT. Default
(-2, -1).normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayAccepted for signature parity; NumPy passes
out=Noneinternally.
Returns
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
aNDArrayInput array.
sint[]Per-axis output lengths;
-1uses the full input length.axesint[]Axes over which to compute the inverse FFT (default: all axes).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated real (float64) output for the final transform.
Returns
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
aNDArrayInput array (taken to be real).
nint?Number of points along the transform axis to use (default
a.shape[axis]).axisintAxis over which to compute the FFT (default the last axis).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output of shape
(..., n//2+1, ...).
Returns
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
aNDArrayInput array (taken to be real).
sint[]Per-axis output lengths;
-1uses the full input length.axesint[]Axes over which to compute the FFT. Default
(-2, -1).normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output.
Returns
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
ndoubleWindow length (a floating value — always rejected).
ddoubleSample spacing.
devicestringArray-API device (unreached — the integer check throws first).
Returns
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
nintWindow length.
ddoubleSample spacing (inverse of the sampling rate). Default 1.
devicestringArray-API device; must be
nullor"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
Returns
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
aNDArrayInput array (taken to be real).
sint[]Per-axis output lengths; the final element is
nforrfft, the rest arenforfft.-1uses the full input length.axesint[]Axes over which to compute the FFT (default: all axes).
normstringNormalization mode:
null/"backward"/"ortho"/"forward".outNDArrayOptional pre-allocated complex output.