maybe_cupy#
- deeptrack.image.maybe_cupy(array: ndarray | List | Tuple) ndarray #
Convert an array to a CuPy array if GPU is available and enabled.
This function checks if GPU computation is enabled in the configuration. If enabled, it converts the input array to a CuPy array for GPU-based acceleration. Otherwise, it returns the input array unchanged.
The function relies on the gpu_enabled flag in the config module to determine whether GPU acceleration should be used.
Parameters#
- arraynp.ndarray or List or Tuple
The input array to be potentially converted to a CuPy array.
Returns#
- cupy.ndarray or np.ndarray
A CuPy array if GPU is enabled, otherwise the original array.
Raises#
- ImportError
If GPU is enabled but the cupy library is not installed.
Example#
>>> import numpy as np >>> from deeptrack.image import maybe_cupy
If GPU is enabled:
>>> array = np.array([1, 2, 3]) >>> gpu_array = maybe_cupy(array) >>> type(gpu_array) <class 'cupy.ndarray'>
If GPU is not enabled:
>>> array = np.array([1, 2, 3]) >>> numpy_array = maybe_cupy(array) >>> type(numpy_array) <class 'numpy.ndarray'>