backends

backends

Backend abstraction for CPU/GPU computation.

This module provides a unified interface for array operations that can use either NumPy (CPU) or CuPy (GPU) as the backend. The backend is selected automatically based on availability and user configuration.

Usage

from conformalpy.backends import get_array_module, to_numpy xp = get_array_module() # Returns numpy or cupy arr = xp.array([1, 2, 3]) result = to_numpy(arr) # Always returns numpy array

Configuration

from conformalpy.backends import set_backend, get_backend set_backend(“gpu”) # Use GPU if available set_backend(“cpu”) # Force CPU set_backend(“auto”) # Auto-detect (default) print(get_backend()) # Check current backend

Notes

CuPy is an optional dependency. Install with: pip install conformalpy[gpu] # or pip install cupy-cuda12x # For CUDA 12.x pip install cupy-cuda11x # For CUDA 11.x