spectral_galerkin_heat.backends.base ==================================== .. py:module:: spectral_galerkin_heat.backends.base .. autoapi-nested-parse:: Container pairing an array module with its physics kernels. Classes ------- .. autoapisummary:: spectral_galerkin_heat.backends.base.MathBackend Functions --------- .. autoapisummary:: spectral_galerkin_heat.backends.base.to_host Module Contents --------------- .. py:function:: to_host(arr) Return *arr* as a :class:`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. .. py:class:: 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 :meth:`to_numpy` is the only method. :param name: Backend identifier, ``"numpy"`` or ``"cupy"``. :type name: str :param xp: :mod:`numpy` or :mod:`cupy`. :type xp: module :param kernels: Kernel module matching *xp* (``spectral_cpu_kernels`` or ``spectral_gpu_kernels``). :type kernels: module .. py:method:: to_numpy(arr) Return *arr* as a :class:`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. :param arr: A NumPy or CuPy array. :type arr: ndarray :returns: The array on the host. :rtype: numpy.ndarray