a
    NSic5  ã                   @   sJ   d dl Z d dlmZ d dlmZ deeeedœdd„Zee	dœd	d
„Z
dS )é    N)ÚAny)Ú_get_device_indexF)ÚdeviceÚoptionalÚ	allow_cpuÚreturnc                 C   s€   t | tƒrt | ¡} t | tjƒrV|r>| jdvrVtd | ¡ƒ‚n| jdkrVtd | ¡ƒ‚tj ¡ stt | tj	jƒrt| j
S t| ||ƒS )a¶  Gets 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 CUDA device. Note that for a CUDA device without a specified index,
    i.e., ``torch.device('cuda')``, this will return the current default CUDA
    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 CUDA
    device if :attr:`optional` is ``True``.
    )ÚcudaÚcpuz*Expected a cuda or cpu device, but got: {}r   z#Expected a cuda device, but got: {})Ú
isinstanceÚstrÚtorchr   ÚtypeÚ
ValueErrorÚformatÚjitÚis_scriptingr   ÚidxÚ_torch_get_device_index)r   r   r   © r   úM/var/www/html/django/DPS/env/lib/python3.9/site-packages/torch/cuda/_utils.pyr      s    




r   )Únamer   c                 C   s   dd„ }t | tfd|iƒS )Nc                 S   s   | j j}td |¡ƒ‚d S )Nz(Tried to instantiate dummy base class {})Ú	__class__Ú__name__ÚRuntimeErrorr   )ÚselfÚ
class_namer   r   r   Úinit_err&   s    ÿz_dummy_type.<locals>.init_errÚ__init__)r   Úobject)r   r   r   r   r   Ú_dummy_type%   s    r   )FF)r   Útypingr   Ztorch._utilsr   r   ÚboolÚintr   r   r   r   r   r   r   Ú<module>   s     ÿÿ