
    9j|              	       4    d dl mZ d dlZ	 ddedededefdZy)	    )AnyNdeviceoptional	allow_cpureturnc                    |  |rt         j                  j                         S t        | t              r| S t         j
                  j                         s0t        | t         j                  j                        r| j                  S t        | t              rt        j                  |       } d}t        | t         j                        rX|s| j                  dk(  rt        d|        | j                  dvrt        d|        | j                  dk(  rdn| j                  }|0|r t         j                  j                         }|S 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       Q/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/mtia/_utils.py_get_device_indexr      s"   " ~(xx''))&#99!!#fejj//0::&#f%!J&%,,'V[[E1CF8LMM;;o-GxPQQ!;;%/RV\\
113J
  YZ`Yab      )FF)typingr   r   boolr   r    r   r   <module>r      s6      <A)))48))r   