abracudabra.device.library ========================== .. py:module:: abracudabra.device.library .. autoapi-nested-parse:: Library import functions for device types. This module provides functions to import the appropriate library based on the device type. Since the NumPy/CuPy and Pandas/cuDF libraries share similar interfaces, being able to switch between them based on the device type is useful. Functions --------- .. autoapisummary:: abracudabra.device.library.get_np_or_cp abracudabra.device.library.get_pd_or_cudf Module Contents --------------- .. py:function:: get_np_or_cp(device_type = None) Get the numpy or cupy library based on the device type. * if ``device_type`` is ``"cpu"``, return the numpy library * if ``device_type`` is ``"cuda"``, return the cupy library If ``device_type`` is not specified, return the numpy library (default). .. rubric:: Examples >>> device_type = "cuda" # in some configuration for example >>> np_or_cp = get_np_or_cp(device_type) >>> np_or_cp.random.choice([1, 2, 3], size=1) # returns a cupy array array([3]) .. py:function:: get_pd_or_cudf(device_type = None) Get the pandas or cudf library based on the device type. * if ``device_type`` is ``"cpu"``, return the pandas library * if ``device_type`` is ``"cuda"``, return the cudf library If ``device_type`` is not specified, return the pandas library (default). .. rubric:: Examples >>> pd_or_cudf = get_pd_or_cudf("cpu") >>> pd_or_cudf.Series([1, 2, 3]) # returns a pandas series 0 1 1 2 2 3 dtype: int64