U
    +Ç-e  ã                   @   s~   d dl mZmZ ddlmZ dddgZG dd„ dƒZedƒZedƒZ	G d	d„ de
ƒZd
D ]Zeeeefdd„ƒ qXeeƒZdS )é    )ÚAnyÚIterableé   )Ú__version__ÚTorchVersionÚVersionÚInvalidVersionc                   @   s8   e Zd ZdZeddœdd„Zdd„ Zdd	„ Zd
d„ ZdS )Ú_LazyImporta   Wraps around classes lazy imported from packaging.version
    Output of the function v in following snippets are identical:
       from packaging.version import Version
       def v():
           return Version('1.2.3')
    and
       Version = _LazyImport('Version')
       def v():
           return Version('1.2.3')
    The difference here is that in later example imports
    do not happen until v is called
    N)Úcls_nameÚreturnc                 C   s
   || _ d S ©N)Ú	_cls_name)Úselfr
   © r   úT/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/torch/torch_version.pyÚ__init__   s    z_LazyImport.__init__c                 C   s<   zdd l }W n  tk
r,   ddlm} Y nX t|j| jƒS )Nr   )Ú	packaging)Zpackaging.versionÚImportErrorÚpkg_resourcesr   ÚgetattrÚversionr   )r   r   r   r   r   Úget_cls   s
    z_LazyImport.get_clsc                 O   s   |   ¡ ||ŽS r   )r   )r   ÚargsÚkwargsr   r   r   Ú__call__   s    z_LazyImport.__call__c                 C   s   t ||  ¡ ƒS r   )Ú
isinstancer   )r   Úobjr   r   r   Ú__instancecheck__"   s    z_LazyImport.__instancecheck__)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r   r   r   r   r	      s
   	r	   c                       s:   e Zd ZdZeedœdd„Zeeedœ‡ fdd„Z‡  Z	S )r   ab  A string with magic powers to compare to both Version and iterables!
    Prior to 1.10.0 torch.__version__ was stored as a str and so many did
    comparisons against torch.__version__ as if it were a str. In order to not
    break them we have TorchVersion which masquerades as a str while also
    having the ability to compare against both packaging.version.Version as
    well as tuples of values, eg. (1, 2, 1)
    Examples:
        Comparing a TorchVersion object to a Version object
            TorchVersion('1.10.0a') > Version('1.10.0a')
        Comparing a TorchVersion object to a Tuple object
            TorchVersion('1.10.0a') > (1, 2)    # 1.2
            TorchVersion('1.10.0a') > (1, 2, 1) # 1.2.1
        Comparing a TorchVersion object against a string
            TorchVersion('1.10.0a') > '1.2'
            TorchVersion('1.10.0a') > '1.2.1'
    )Úinpr   c                 C   sR   t |t ¡ ƒr|S t |tƒr$t|ƒS t |tƒrFtd dd„ |D ƒ¡ƒS t|ƒ‚d S )NÚ.c                 s   s   | ]}t |ƒV  qd S r   )r"   )Ú.0Úitemr   r   r   Ú	<genexpr>G   s     z3TorchVersion._convert_to_version.<locals>.<genexpr>)r   r   r   r"   r   Újoinr   )r   r#   r   r   r   Ú_convert_to_version;   s    

z TorchVersion._convert_to_version)ÚcmpÚmethodr   c              
      sf   zt t| ƒ|ƒ|  |¡ƒW S  tk
r` } z(t|t ¡ ƒs<‚ t tƒ |ƒ|ƒ W Y ¢S d }~X Y nX d S r   )r   r   r)   ÚBaseExceptionr   r   r   Úsuper)r   r*   r+   Úe©Ú	__class__r   r   Ú_cmp_wrapperK   s    zTorchVersion._cmp_wrapper)
r   r   r    r!   r   r)   r"   Úboolr1   Ú__classcell__r   r   r/   r   r   )   s   )Ú__gt__Ú__lt__Ú__eq__Ú__ge__Ú__le__c                 C   s   |   ||¡S r   )r1   )ÚxÚyr+   r   r   r   Ú<lambda>W   ó    r;   N)Útypingr   r   r   r   Zinternal_versionÚ__all__r	   r   r   r"   r   Z
cmp_methodÚsetattrr   r   r   r   Ú<module>   s   
 -