abracudabra.device.base ======================= .. py:module:: abracudabra.device.base .. autoapi-nested-parse:: Define the base device class. Attributes ---------- .. autoapisummary:: abracudabra.device.base.DeviceType abracudabra.device.base.DEVICE_TYPES Classes ------- .. autoapisummary:: abracudabra.device.base.Device Functions --------- .. autoapisummary:: abracudabra.device.base.is_valid_device_type abracudabra.device.base._raise_invalid_device_type Module Contents --------------- .. py:data:: DeviceType The device type, e.g., ``"cpu"`` or ``"cuda"``. .. py:data:: DEVICE_TYPES :type: frozenset[DeviceType] The device types, e.g., ``{"cpu", "cuda"}``. .. py:function:: is_valid_device_type(device_type: str, /) -> TypeGuard[DeviceType] Check if a device name is valid. .. py:function:: _raise_invalid_device_type(device_type: str, /) -> NoReturn Raise an error for an invalid device type. .. py:class:: Device Bases: :py:obj:`NamedTuple` A device with a name and index. .. py:attribute:: type :type: DeviceType The device type, e.g., ``"cpu"`` or ``"cuda"``. .. py:attribute:: idx :type: int | None :value: None The device index, e.g., ``0`` or ``None``. .. py:method:: __str__() -> str Return the device name. .. py:method:: _validate_device(device: object, /) -> DeviceType :staticmethod: Validate a device name. .. py:method:: _validate_idx(idx: object | None, /) -> int | None :staticmethod: Validate a device index. .. py:method:: validate(device: object, idx: object | None = None) -> Device :classmethod: Return a device, validating the device name. .. py:method:: from_str(device: str, /) -> Device :classmethod: Return a device from a string. .. py:method:: parse(device: str | Device, /) -> Device :classmethod: Return a device from a string or device. .. py:method:: to_torch() -> torch.device Return a torch device.