backend
sorix.backend ¶
Backend utilities for Sorix
Provides a thin abstraction over NumPy and CuPy, selecting the appropriate module based on a Tensor's device and CuPy availability.
get_xp ¶
Return the array module (NumPy or CuPy) to use for args.
This is the single array-module selector used across the library: it is
resolved once per operation instead of scattering device == 'cuda'
conditionals through every call site.
Parameters:
-
*args(Any, default:()) –Objects to inspect, typically :class:
sorix.tensor.Tensorinstances. Anything without a CUDAdeviceis ignored, so raw NumPy arrays and scalars can be passed freely.
Returns:
-
Any(Any) –cpif any argument lives on a CUDA device and CuPy is -
Any–available; otherwise
np.