spectral_galerkin_heat.backends.base

Container pairing an array module with its physics kernels.

Classes

MathBackend

Hold the array module and physics kernels for one execution target.

Functions

to_host(arr)

Return arr as a numpy.ndarray on the host.

Module Contents

spectral_galerkin_heat.backends.base.to_host(arr)

Return arr as a numpy.ndarray on the host.

Calls numpy.asarray if arr is already a host array, or arr.get() if it is a CuPy device array.

class spectral_galerkin_heat.backends.base.MathBackend(name, xp, kernels)

Hold the array module and physics kernels for one execution target.

NumPy and CuPy share the same API, so the solver sets xp = backend.xp and calls xp.zeros(...) directly. Host transfer is the only operation that differs between the two, which is why to_numpy() is the only method.

Parameters:
  • name (str) – Backend identifier, "numpy" or "cupy".

  • xp (module) – numpy or cupy.

  • kernels (module) – Kernel module matching xp (spectral_cpu_kernels or spectral_gpu_kernels).

to_numpy(arr)

Return arr as a numpy.ndarray on the host.

Calls numpy.asarray if arr is already a host array, or arr.get() if it is a CuPy device array.

Parameters:

arr (ndarray) – A NumPy or CuPy array.

Returns:

The array on the host.

Return type:

numpy.ndarray