pyepri.utils

This module contains standard functions, like operators usually involved in signal or image processing.

Functions

grad1d(u[, backend, notest])

Gradient (= forward finite differences) of a mono-dimensional array with Neumann boundary condition.

div1d(P[, backend, notest])

Discrete divergence of a mono-dimensional array (opposite adjoint of grad1d).

grad2d(u[, backend, notest])

Gradient (= forward finite differences) of a 2-dimensional array with Neumann boundary condition.

div2d(P[, backend, notest])

Discrete divergence of a 2D field vector (opposite adjoint of grad2d).

grad3d(u[, backend, notest])

Gradient (= forward finite differences) of a 3-dimensional array with Neumann boundary condition.

div3d(P[, backend, notest])

Discrete divergence of a 3D field vector (opposite adjoint of grad3d).

_relerr_(u, v[, backend, nrm, notest])

Compute relative error between two arrays.

_check_nd_inputs_(ndims, backend[, u, P])

Factorized consistency checks for functions in the pyepri.utils submodule.

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 of u.

Return type:

array_like (with type backend.cls)

See also

div1d

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 the grad1d operator) of the input array P.

Return type:

array_like (with type backend.cls)

See also

grad2d

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 that G[j] correspond to the forward finite differences of u along its j-th dimension (for j in range(2)).

Return type:

array_like (with type backend.cls)

See also

div2d

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 the grad2d operator) of the input field vector array P.

Return type:

array_like (with type backend.cls)

See also

grad2d

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 that G[j] correspond to the forward finite differences of u along its j-th dimension (for j in range(3)).

Return type:

array_like (with type backend.cls)

See also

div3d

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 the grad3d operator) of the input field vector array P.

Return type:

array_like (with type backend.cls)

See also

grad3d

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 and v.

  • 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 of u, 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.