The LIB
module variable¶
The LIB
variable specifies the default library to use by the module. The Numpy
library is used by default with LIB
sets to "numpy"
. Possible values are
"numpy"
to use Numpy, or"fftw"
to use pyFFTW, if installed.
The variable can be changed globally
udft.LIB = "numpy"
In addition, each function has a parameter to change the library used at call
time. A ValueError
is raided if the value is not recognized.
Discrete Fourier Transform¶
dftn¶
-
udft.
dftn
(inarray, ndim=None, lib=None)¶ ND unitary discrete Fourier transform.
- Parameters
inarray (array-like) – The array to transform.
ndim (int, optional) – The ndim last axes along which to compute the transform. All axes by default.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The DFT of inarray with same shape.
- Return type
array-like
idftn¶
-
udft.
idftn
(inarray, ndim=None, lib=None)¶ ND unitary inverse discrete Fourier transform.
- Parameters
inarray (array-like) – The array to transform.
ndim (int, optional) – The ndim last axes along wich to compute the transform. All axes by default.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The IDFT of inarray with same shape.
- Return type
array-like
dft¶
-
udft.
dft
(inarray, lib=None)¶ 1D unitary discrete Fourier transform.
Compute the unitary DFT on the last axis.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The DFT of inarray with same shape.
- Return type
array-like
idft¶
-
udft.
idft
(inarray, lib=None)¶ 1D unitary inverse discrete Fourier transform.
Compute the unitary inverse DFT transform on the last axis.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The DFT of inarray with same shape.
- Return type
array-like
dft2¶
-
udft.
dft2
(inarray, lib=None)¶ 2D unitary discrete Fourier transform.
Compute the unitary DFT on the last 2 axes.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The DFT of inarray with same shape.
- Return type
array-like
idft2¶
-
udft.
idft2
(inarray, lib=None)¶ 2D unitary inverse discrete Fourier transform.
Compute the unitary IDFT on the last 2 axes.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The IDFT of inarray with same shape.
- Return type
array-like
Real Discrete Fourier Transform¶
The transforms here suppose input of real values. In direct transform, the last
transformed axis has length N // 2 + 1
.
Note
The exact output shape for real transform can’t be guessed from input shape.
Therefor, only one inverse transform irdftn()
is provided and that
function ask for the output shape. The dimension ndim corresponds to the
length of shape.
rdftn¶
-
udft.
rdftn
(inarray, ndim=None, lib=None)¶ ND real unitary discrete Fourier transform.
Consider the Hermitian property of output with input having real values.
- Parameters
inarray (array-like) – The array of real values to transform.
ndim (int, optional) – The ndim last axes along which to compute the transform. All axes by default.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The real DFT of inarray (the last axe as N // 2 + 1 length).
- Return type
array-like
irdftn¶
-
udft.
irdftn
(inarray, shape, lib=None)¶ ND real unitary inverse discrete Fourier transform.
Consider the Hermitian property of input and return real values.
- Parameters
inarray (array-like) – The array of complex values to transform.
shape (tuple of int) – The output shape of the len(shape) last axes. The transform is applied on the n=len(shape) axes.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The real IDFT of inarray.
- Return type
array-like
rdft¶
-
udft.
rdft
(inarray, lib=None)¶ 1D real unitary discrete Fourier transform.
Compute the unitary real DFT on the last axis. Consider the Hermitian property of output with input having real values.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The real DFT of inarray, where the last dim has length N//2+1.
- Return type
array-like
rdft2¶
-
udft.
rdft2
(inarray, lib=None)¶ 2D real unitary discrete Fourier transform.
Compute the unitary real DFT on the last 2 axes. Consider the Hermitian property of output when input has real values.
- Parameters
inarray (array-like) – The array to transform.
lib (str, optional) – Specify the library to compute the Fourier transform. See set_lib get_lib functions for the default.
- Returns
outarray – The real DFT of inarray, where the last dim has length N//2+1.
- Return type
array-like
Other¶
hnorm¶
-
udft.
hnorm
(inarray, inshape)¶ Hermitian l2-norm of array in discrete Fourier space.
Compute the l2-norm of complex array
\[\|x\|_2 = \sqrt{\sum_{n=1}^{N} |x_n|^2}\]considering the Hermitian property. Must be used with rdftn. Equivalent of np.linalg.norm for array applied on full Fourier space array (those obtained with dftn).
- Parameters
inarray (array-like of shape (.. + inshape)) – The input array with half of the Fourier plan.
inshape (tuple of int) – The shape of the original array oarr where inarray=rdft(oarr).
- Returns
norm
- Return type
float
crandn¶
Warning
At that time, this function does not respect the hermitian property, this is planned.
-
udft.
crandn
(shape)¶ Draw from white complex Normal.
Draw unitary DFT of real white Gaussian field of zero mean and unit variance. Does not consider hermitian property, shape is supposed to consider half of the frequency plane already.
- Return type
ndarray