abracudabra.device.library

abracudabra.device.library#

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#

get_np_or_cp([device_type])

Get the numpy or cupy library based on the device type.

get_pd_or_cudf([device_type])

Get the pandas or cudf library based on the device type.

Module Contents#

abracudabra.device.library.get_np_or_cp(device_type=None)[source]#

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).

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])
Parameters:

device_type (abracudabra.device.base.DeviceType | None)

Return type:

types.ModuleType

abracudabra.device.library.get_pd_or_cudf(device_type=None)[source]#

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).

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
Parameters:

device_type (abracudabra.device.base.DeviceType | None)

Return type:

types.ModuleType