
    Gj|              	       6    d dl mZ d dlZ	 d	dedededefdZdS )
    )AnyNFdeviceoptional	allow_cpureturnc                    |  |rt           j                                        S t          | t                    r| S t           j                                        s&t          | t           j        j                  r| j	        S t          | t                    rt          j        |           } d}t          | t           j                  rN|s| j        dk    rt          d|            | j        dvrt          d|            | j        dk    rdn| j        }|3|rt           j                                        }nt          d|            |S )a  Get the device index from :attr:`device`, which can be a torch.device object, a Python integer, or ``None``.

    If :attr:`device` is a torch.device object, returns the device index if it
    is a MTIA device. Note that for a MTIA device without a specified index,
    i.e., ``torch.device('mtia')``, this will return the current default MTIA
    device if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``,
    CPU devices will be accepted and ``-1`` will be returned in this case.

    If :attr:`device` is a Python integer, it is returned as is.

    If :attr:`device` is ``None``, this will return the current default MTIA
    device if :attr:`optional` is ``True``.
    Ncpuz$Expected a non cpu device, but got: )mtiar	   z(Expected a mtia or cpu device, but got: zGExpected a torch.device with a specified index or an integer, but got: )torch_C_mtia_getDevice
isinstanceintjitis_scriptingr
   r   idxstrtype
ValueErrorindex)r   r   r   
device_idxs       T/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/torch/mtia/_utils.py_get_device_indexr      sX   " ~(~x'')))&# 9!!## fej/00 	:&# &f%%!J&%,'' B 	NV[E11LFLLMMM;o--PPPQQQ!;%//RRV\
 	1133JJbZ`bb       )FF)typingr   r   boolr   r    r   r   <module>r      si           <A) )))48)) ) ) ) ) )r   