
    Ǆg7              	       @    d dl mZ d dlZd dlmZ 	 d	dedededefdZy)
    )AnyN)_get_device_indexdeviceoptional	allow_cpureturnc                    t        | t              r| S t        | t              rt        j                  |       } t        | t        j                        r;|r| j
                  dvr+t        d|        | j
                  dk7  rt        d|        t        j                  j                         s0t        | t        j                  j                        r| j                  S t        | ||      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 XPU device. Note that for a XPU device without a specified index,
    i.e., ``torch.device('xpu')``, this will return the current default XPU
    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 XPU
    device if :attr:`optional` is ``True``.
    )xpucpuz'Expected a xpu or cpu device, but got: r
   z Expected a xpu device, but got: )
isinstanceintstrtorchr   type
ValueErrorjitis_scriptingr
   idx_torch_get_device_index)r   r   r   s      X/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/xpu/_utils.pyr   r   	   s    " &#&#f%&%,,'{{.0 #J6(!STT[[E!?xHII99!!#feii../::"68Y??    )FF)typingr   r   torch._utilsr   r   boolr    r   r   <module>r      sA      F <A@@@48@@r   