spectral_galerkin_heat.backends.base
Container pairing an array module with its physics kernels.
Classes
Hold the array module and physics kernels for one execution target. |
Functions
|
Return arr as a |
Module Contents
- spectral_galerkin_heat.backends.base.to_host(arr)
Return arr as a
numpy.ndarrayon the host.Calls
numpy.asarrayif arr is already a host array, orarr.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.xpand callsxp.zeros(...)directly. Host transfer is the only operation that differs between the two, which is whyto_numpy()is the only method.- Parameters:
name (str) – Backend identifier,
"numpy"or"cupy".xp (module) –
numpyorcupy.kernels (module) – Kernel module matching xp (
spectral_cpu_kernelsorspectral_gpu_kernels).
- to_numpy(arr)
Return arr as a
numpy.ndarrayon the host.Calls
numpy.asarrayif arr is already a host array, orarr.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