pyshqg.backend.abstract module

Submodule dedicated to abstract backend.

class pyshqg.backend.abstract.Backend(floatx)

Bases: ABC

Abstract backend.

floatx

Precision for real numbers.

Type:

str

__init__(floatx)

Constructor for the backend.

Parameters:

floatx (str) – Precision for real numbers.

abstract from_numpy(array)

Converts an array from numpy into backend format.

Parameters:

array (numpy.ndarray) – Array in numpy format.

Returns:

array – Array in backend format.

Return type:

backend array

abstract static to_numpy(array)

Converts an array from backend into numpy format.

Parameters:

array (backend array) – Array in backend format.

Returns:

array – Array in numpy format.

Return type:

numpy.ndarray

abstract static expand_dims(*args, **kwargs)

Backend equivalent of numpy.expand_dims.

abstract static pad(*args, **kwargs)

Backend equivalent of numpy.pad.

abstract static einsum(*args, **kwargs)

Backend equivalent of numpy.einsum.

abstract range(*args, **kwargs)

Backend equivalent of numpy.arange using real numbers.

abstract static concatenate(*args, **kwargs)

Backend equivalent of numpy.concatenate.

abstract static repeat(*args, **kwargs)

Backend equivalent of numpy.repeat.

abstract static apply_fft(T, T_grid, leg_x)

Forward Fourier transformation for the spectral harmonics.

Notes

For the Gauss–Legendre grid used here, we have $N_{mathsf{lat}}=T_{mathsf{grid}}+1$ and $N_{mathsf{lon}}=2N_{mathsf{lat}}=2times(T_{mathsf{grid}}+1)$.

Parameters:
  • T (int) – Truncature of the data in spectral space.

  • T_grid (int) – Truncature of the Gauss–Legendre grid.

  • leg_x (backend array, shape (..., 2, Nlat, T+1)) – Legendre transform of $hat{x}$.

Returns:

x – Variable $x$ in grid space.

Return type:

backend array, shape (…, Nlat, Nlon)

abstract static apply_ifft(T, T_grid, x)

Inverse Fourier transformation for the spectral harmonics.

Notes

For the Gauss–Legendre grid used here, we have $N_{mathsf{lat}}=T_{mathsf{grid}}+1$ and $N_{mathsf{lon}}=2N_{mathsf{lat}}=2times(T_{mathsf{grid}}+1)$.

Parameters:
  • T (int) – Truncature of the data in spectral space.

  • T_grid (int) – Truncature of the Gauss–Legendre grid.

  • x (backend array, shape (..., Nlat, Nlon)) – Variable $x$ in grid space.

Returns:

leg_x – Legendre transform of $hat{x}$.

Return type:

backend array, shape (…, 2, Nlat, T+1)