a
    –¥»aŒ  ã                   @   sT   d dl mZmZ d dlmZ ejjZejjZddlmZ	 G dd„ de
ƒZee	ƒZdS )é    )ÚIterableÚUnion)Ú	packagingé   )Ú__version__c                       sr   e Zd ZdZeejjee	f ejjdœdd„Z
‡ fdd„Z‡ fdd„Z‡ fd	d
„Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚTorchVersionab  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   úM/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/torch_version.pyÚ	<genexpr>)   ó    z3TorchVersion._convert_to_version.<locals>.<genexpr>)Ú
isinstanceÚVersionr   r   ÚjoinÚInvalidVersion)Úselfr   r   r   r   Ú_convert_to_version   s    


z TorchVersion._convert_to_versionc                    s:   zt | ƒ |  |¡¡W S  ty4   tƒ  |¡ Y S 0 d S r   )r   Ú__gt__r   r   Úsuper©r   Úcmp©Ú	__class__r   r   r   -   s    zTorchVersion.__gt__c                    s:   zt | ƒ |  |¡¡W S  ty4   tƒ  |¡ Y S 0 d S r   )r   Ú__lt__r   r   r   r   r   r   r   r   5   s    zTorchVersion.__lt__c                    s:   zt | ƒ |  |¡¡W S  ty4   tƒ  |¡ Y S 0 d S r   )r   Ú__eq__r   r   r   r   r   r   r   r    =   s    zTorchVersion.__eq__c                    s:   zt | ƒ |  |¡¡W S  ty4   tƒ  |¡ Y S 0 d S r   )r   Ú__ge__r   r   r   r   r   r   r   r!   E   s    zTorchVersion.__ge__c                    s:   zt | ƒ |  |¡¡W S  ty4   tƒ  |¡ Y S 0 d S r   )r   Ú__le__r   r   r   r   r   r   r   r"   M   s    zTorchVersion.__le__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úversionr   r   r   r   r   r   r    r!   r"   Ú__classcell__r   r   r   r   r      s   "r   N)Útypingr   r   Úpkg_resourcesr   r'   r   r   r   Zinternal_versionr   r   r   r   r   r   Ú<module>   s   J