pyepri.utils
This module contains standard functions, like operators usually involved in signal or image processing.
Functions
|
Gradient (= forward finite differences) of a mono-dimensional array with Neumann boundary condition. |
|
Discrete divergence of a mono-dimensional array (opposite adjoint of grad1d). |
|
Gradient (= forward finite differences) of a 2-dimensional array with Neumann boundary condition. |
|
Discrete divergence of a 2D field vector (opposite adjoint of grad2d). |
|
Gradient (= forward finite differences) of a 3-dimensional array with Neumann boundary condition. |
|
Discrete divergence of a 3D field vector (opposite adjoint of grad3d). |
|
Compute relative error between two arrays. |
|
Factorized consistency checks for functions in the |
Module Contents
- pyepri.utils.grad1d(u, backend=None, notest=False)[source]
Gradient (= forward finite differences) of a mono-dimensional array with Neumann boundary condition.
- Parameters:
u (array_like (with type backend.cls)) – Mono-dimensional array.
backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
u
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
G – Output array same shape as
u
corresponding to the forward finite differences ofu
.- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils.div1d(P, backend=None, notest=False)[source]
Discrete divergence of a mono-dimensional array (opposite adjoint of grad1d).
- Parameters:
P (array_like (with type backend.cls)) – Mono-dimensional input array.
backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
P
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
div – Mono-dimensional array with same shape as
u
corresponding to the discrete divergence (or opposite adjoint of thegrad1d
operator) of the input arrayP
.- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils.grad2d(u, backend=None, notest=False)[source]
Gradient (= forward finite differences) of a 2-dimensional array with Neumann boundary condition.
- Parameters:
u (array_like (with type backend.cls)) – Two-dimensional array.
backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
u
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
G – Output array with shape
(3,) + u.shape
such thatG[j]
correspond to the forward finite differences ofu
along its j-th dimension (forj in range(2)
).- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils.div2d(P, backend=None, notest=False)[source]
Discrete divergence of a 2D field vector (opposite adjoint of grad2d).
- Parameters:
P (array_like (with type backend.cls)) – Two-dimensional vector field array with shape
(2, Ny, Nx)
.backend (<class 'pyepri.backends.Backend'>or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
P
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
div – Two dimensional array with shape
(Ny, Nx)
corresponding to the discrete divergence (or opposite adjoint of thegrad2d
operator) of the input field vector arrayP
.- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils.grad3d(u, backend=None, notest=False)[source]
Gradient (= forward finite differences) of a 3-dimensional array with Neumann boundary condition.
- Parameters:
u (array_like (with type backend.cls)) – Three-dimensional array.
backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
u
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
G – Output array with shape
(3,) + u.shape
such thatG[j]
correspond to the forward finite differences ofu
along its j-th dimension (forj in range(3)
).- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils.div3d(P, backend=None, notest=False)[source]
Discrete divergence of a 3D field vector (opposite adjoint of grad3d).
- Parameters:
P (array_like (with type backend.cls)) – Three-dimensional vector field array with shape
(3, Ny, Nx, Nz)
.backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input array
P
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
div – Three dimensional array with shape
(Ny, Nx, Nz)
corresponding to the discrete divergence (or opposite adjoint of thegrad3d
operator) of the input field vector arrayP
.- Return type:
array_like (with type backend.cls)
See also
- pyepri.utils._relerr_(u, v, backend=None, nrm=None, notest=False)[source]
Compute relative error between two arrays.
- Parameters:
u (array_like (with type backend.cls)) – First input array.
v (array_like (with type backend.cls)) – Second input array.
backend (<class 'pyepri.backends.Backend'> or None, optional) –
A numpy, cupy or torch backend (see
pyepri.backends
module).When backend is None, a default backend is inferred from the input arrays
u
andv
.nrm (float, optional) – A normalization factor to be applied to both input array (useful to avoid underflow or overflow issues in the computation of the relative error). If not given,
nrm
will be taken equal to one over the infinite norm ofu
, i.e.,nrm = 1. / ||u||_inf
.notest (bool, optional) – Set
notest=True
to disable consistency checks.
- Returns:
rel – The relative error
||nrm * u - nrm * v|| / ||nrm * u||
where||.||
denotes the l2 norm.- Return type:
float
- pyepri.utils._check_nd_inputs_(ndims, backend, u=None, P=None)[source]
Factorized consistency checks for functions in the
pyepri.utils
submodule.