U
    1þjg¿	  ã                   @   sl   d dl mZmZ ddlmZmZ ddlmZ dgZ	G dd„ de
ƒZdD ]Zeeeefdd	„ƒ qFeeƒZd
S )é    )ÚAnyÚIterableé   )ÚInvalidVersionÚVersion)Ú__version__ÚTorchVersionc                       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'
    )ÚinpÚreturnc                 C   sN   t |tƒr|S t |tƒr t|ƒS t |tƒrBtd dd„ |D ƒ¡ƒS t|ƒ‚d S )NÚ.c                 s   s   | ]}t |ƒV  qd S ©N)Ústr)Ú.0Úitem© r   ú7/tmp/pip-unpacked-wheel-ttp2cnii/torch/torch_version.pyÚ	<genexpr>*   s     z3TorchVersion._convert_to_version.<locals>.<genexpr>)Ú
isinstancer   r   r   Újoinr   )Úselfr	   r   r   r   Ú_convert_to_version   s    


z TorchVersion._convert_to_version)ÚcmpÚmethodr
   c              
      sb   zt t| ƒ|ƒ|  |¡ƒW S  tk
r\ } z$t|tƒs8‚ t tƒ |ƒ|ƒ W Y ¢S d }~X Y nX d S r   )Úgetattrr   r   ÚBaseExceptionr   r   Úsuper)r   r   r   Úe©Ú	__class__r   r   Ú_cmp_wrapper.   s    
zTorchVersion._cmp_wrapper)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úboolr   Ú__classcell__r   r   r   r   r      s   )Ú__gt__Ú__lt__Ú__eq__Ú__ge__Ú__le__c                 C   s   |   ||¡S r   )r   )ÚxÚyr   r   r   r   Ú<lambda>=   ó    r-   N)Útypingr   r   Z_vendor.packaging.versionr   r   Úversionr   Zinternal_versionÚ__all__r   r   Z
cmp_methodÚsetattrr   r   r   r   Ú<module>   s   .
ý