pygwtf.backend#

Attributes#

Classes#

Backend

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy)

CPUBackend

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy)

GPUBackend

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy)

Functions#

get_backend(→ Backend)

Factory function to get the appropriate backend instance based on the provided backend name.

Module Contents#

pygwtf.backend.gpu_available = True#
class pygwtf.backend.Backend#

Bases: abc.ABC

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy) and any other backend-specific functionality (such as kernel selection).

property xp: Any#
Abstractmethod:

Returns the array module to be used for computations. This will be numpy for CPU computations and cupy for GPU computations.

property uses_gpu: bool#

Returns True if the backend uses GPU computations, False otherwise.

asnumpy(array: Any) numpy.ndarray#

Converts the given array to a NumPy array. For CPU backend, this can be a no-op. For GPU backend, this will transfer the array from GPU to CPU.

class pygwtf.backend.CPUBackend#

Bases: Backend

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy) and any other backend-specific functionality (such as kernel selection).

property xp#

Returns the array module to be used for computations. This will be numpy for CPU computations and cupy for GPU computations.

class pygwtf.backend.GPUBackend#

Bases: Backend

Backend base class. Defines the interface for the array module to be used for computations (e.g. numpy or cupy) and any other backend-specific functionality (such as kernel selection).

property xp#

Returns the array module to be used for computations. This will be numpy for CPU computations and cupy for GPU computations.

property uses_gpu: bool#

Returns True if the backend uses GPU computations, False otherwise.

asnumpy(array: Any) numpy.ndarray#

Converts the given array to a NumPy array. For CPU backend, this can be a no-op. For GPU backend, this will transfer the array from GPU to CPU.

pygwtf.backend.get_backend(backend_name: str) Backend#

Factory function to get the appropriate backend instance based on the provided backend name.