abracudabra.device.query#

Query the device of a numpy/cupy array, series or torch tensor.

Functions#

_cupy_get_device(→ abracudabra.device.base.Device)

Get the device of a cupy array.

frame_get_device_type(…)

Get the device type of a pandas or cudf series or dataframe.

_torch_get_device(→ abracudabra.device.base.Device)

Get the device of a torch tensor.

get_device(…)

Get the device of a numpy/cupy array or series.

guess_device(→ abracudabra.device.base.Device)

Guess the device of a numpy/cupy array or series.

Module Contents#

abracudabra.device.query._cupy_get_device(array: object, /) abracudabra.device.base.Device[source]#

Get the device of a cupy array.

Parameters:

array – The array to check.

Returns:

The device of the array.

abracudabra.device.query.frame_get_device_type(frame: abracudabra.annotations.Series | abracudabra.annotations.DataFrame, /, *, raise_if_unknown: Literal[True] = ...) abracudabra.device.base.DeviceType[source]#
abracudabra.device.query.frame_get_device_type(frame: abracudabra.annotations.Series | abracudabra.annotations.DataFrame, /, *, raise_if_unknown: bool = ...) abracudabra.device.base.DeviceType | None

Get the device type of a pandas or cudf series or dataframe.

abracudabra.device.query._torch_get_device(tensor: torch.Tensor, /) abracudabra.device.base.Device[source]#

Get the device of a torch tensor.

Parameters:

tensor – The tensor to check.

Returns:

The device of the tensor.

abracudabra.device.query.get_device(element: abracudabra.annotations.Array | torch.Tensor, /, *, raise_if_unknown: Literal[True] = ...) abracudabra.device.base.Device[source]#
abracudabra.device.query.get_device(element: abracudabra.annotations.Array | torch.Tensor, /, *, raise_if_unknown: bool = ...) abracudabra.device.base.Device | None

Get the device of a numpy/cupy array or series.

Parameters:
  • element – The element to check.

  • raise_if_unknown – Whether to raise an error if the element is not a known array or tensor.

Returns:

The device of the element.

abracudabra.device.query.guess_device(*elements: abracudabra.annotations.Array | torch.Tensor, skip_unknown: bool = True) abracudabra.device.base.Device[source]#

Guess the device of a numpy/cupy array or series.

Parameters:
  • *elements – The elements to check.

  • skip_unknown – Whether to skip elements that are not known arrays or tensors.

Returns:

The device of the elements.

Raises:
  • ValueError – If no elements are given.

  • ValueError – If the elements are on different devices.