a
    ;¹§e  ã                   @   s¬   d Z ddlmZ dd„ Zdd„ ZG dd„ deƒZeG d	d
„ d
eƒƒZeG dd„ deƒƒZeG dd„ deƒƒZ	eG dd„ de	ƒƒZ
eG dd„ de	ƒƒZeG dd„ deƒƒZdS )zÚ
Various richly-typed exceptions, that also help us deal with string formatting
in python where it's easier.

By putting the formatting in `__str__`, we also avoid paying the cost for
users who silence the exceptions.
é   )Ú
set_modulec                 C   s   t | ƒdkr| d S | S d S )Né   é    )Úlen)Útup© r   úJ/var/www/sunrise/env/lib/python3.9/site-packages/numpy/core/_exceptions.pyÚ_unpack_tuple
   s    r	   c                 C   s   t | tƒsJ ‚| jj| _| S )aG  
    A decorator that makes an exception class look like its base.

    We use this to hide subclasses that are implementation details - the user
    should catch the base type, which is what the traceback will show them.

    Classes decorated with this decorator are subject to removal without a
    deprecation warning.
    )Ú
issubclassÚ	ExceptionÚ__base__Ú__name__)Úclsr   r   r   Ú_display_as_base   s    

r   c                   @   s   e Zd ZdZdd„ ZdS )ÚUFuncTypeErrorz% Base class for all ufunc exceptions c                 C   s
   || _ d S ©N)Úufunc)Úselfr   r   r   r   Ú__init__"   s    zUFuncTypeError.__init__N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r       s   r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú_UFuncNoLoopErrorz* Thrown when a ufunc loop cannot be found c                    s   t ƒ  |¡ t|ƒ| _d S r   )Úsuperr   ÚtupleÚdtypes©r   r   r   ©Ú	__class__r   r   r   )   s    z_UFuncNoLoopError.__init__c                 C   s6   d  | jjt| jd | jj… ƒt| j| jjd … ƒ¡S )NzLufunc {!r} did not contain a loop with signature matching types {!r} -> {!r})Úformatr   r   r	   r   Únin©r   r   r   r   Ú__str__-   s    ÿúz_UFuncNoLoopError.__str__©r   r   r   r   r   r"   Ú__classcell__r   r   r   r   r   &   s   r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú_UFuncBinaryResolutionErrorz' Thrown when a binary resolution fails c                    s$   t ƒ  ||¡ t| jƒdks J ‚d S )Nr   )r   r   r   r   r   r   r   r   r   ;   s    z$_UFuncBinaryResolutionError.__init__c                 C   s   dj | jjg| j¢R Ž S )Nz7ufunc {!r} cannot use operands with types {!r} and {!r})r   r   r   r   r!   r   r   r   r"   ?   s    ÿýýz#_UFuncBinaryResolutionError.__str__r#   r   r   r   r   r%   8   s   r%   c                       s   e Zd Z‡ fdd„Z‡  ZS )Ú_UFuncCastingErrorc                    s"   t ƒ  |¡ || _|| _|| _d S r   )r   r   ÚcastingÚfrom_Úto)r   r   r'   r(   r)   r   r   r   r   I   s    z_UFuncCastingError.__init__)r   r   r   r   r$   r   r   r   r   r&   G   s   r&   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú_UFuncInputCastingErrorz, Thrown when a ufunc input cannot be casted c                    s   t ƒ  ||||¡ || _d S r   )r   r   Úin_i©r   r   r'   r(   r)   Úir   r   r   r   S   s    z _UFuncInputCastingError.__init__c                 C   s8   | j jdkrd | j¡nd}d | j j|| j| j| j¡S )Nr   ú{} Ú zGCannot cast ufunc {!r} input {}from {!r} to {!r} with casting rule {!r})r   r    r   r+   r   r(   r)   r'   ©r   Zi_strr   r   r   r"   W   s
    ÿüz_UFuncInputCastingError.__str__r#   r   r   r   r   r*   P   s   r*   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú_UFuncOutputCastingErrorz- Thrown when a ufunc output cannot be casted c                    s   t ƒ  ||||¡ || _d S r   )r   r   Úout_ir,   r   r   r   r   e   s    z!_UFuncOutputCastingError.__init__c                 C   s8   | j jdkrd | j¡nd}d | j j|| j| j| j¡S )Nr   r.   r/   zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})r   Znoutr   r2   r   r(   r)   r'   r0   r   r   r   r"   i   s
    ÿüz _UFuncOutputCastingError.__str__r#   r   r   r   r   r1   b   s   r1   c                   @   s8   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdd	„ Z	d
S )Ú_ArrayMemoryErrorz) Thrown when an array cannot be allocatedc                 C   s   || _ || _d S r   )ÚshapeÚdtype)r   r4   r5   r   r   r   r   w   s    z_ArrayMemoryError.__init__c                 C   s    | j j}| jD ]}||9 }q|S r   )r5   Úitemsizer4   )r   Ú	num_bytesZdimr   r   r   Ú_total_size{   s    

z_ArrayMemoryError._total_sizec           	      C   sÌ   d}d}g d¢}t |  ¡ d dƒ| }d|| > }| | }~t|ƒ|krX|d7 }|| }|t|ƒkrˆt|ƒd }|d|| | > 9 }|}|| }|dkr¤d ||¡S t|ƒdk r¼d ||¡S d	 ||¡S d
S )z5 Convert a number of bytes into a binary size string é
   i   )ÚbytesZKiBZMiBZGiBZTiBZPiBZEiBr   r   z	{:.0f} {}iè  z
{:#.3g} {}z
{:#.0f} {}N)ÚmaxÚ
bit_lengthÚroundr   r   )	r7   Z	LOG2_STEPZSTEPZunitsZunit_iZunit_valZn_unitsZ
new_unit_iZ	unit_namer   r   r   Ú_size_to_string‚   s(    z!_ArrayMemoryError._size_to_stringc                 C   s   |   | j¡}d || j| j¡S )NzAUnable to allocate {} for an array with shape {} and data type {})r>   r8   r   r4   r5   )r   Zsize_strr   r   r   r"   §   s
    
ÿÿz_ArrayMemoryError.__str__N)
r   r   r   r   r   Úpropertyr8   Ústaticmethodr>   r"   r   r   r   r   r3   t   s   

$r3   N)r   Ú_utilsr   r	   r   Ú	TypeErrorr   r   r%   r&   r*   r1   ÚMemoryErrorr3   r   r   r   r   Ú<module>   s    