a
    ³ÐOc˜   ã                   @   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dƒG dd„ deƒƒZedƒG dd„ de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é   r   )Úlen)Útup© r   úM/var/www/html/gsl.tools/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 )Ú_UFuncBinaryResolutionErrorz' Thrown when a binary resolution fails c                    s,   t ƒ  |¡ t|ƒ| _t| jƒdks(J ‚d S )Né   )Úsuperr   ÚtupleÚdtypesr   ©r   r   r   ©Ú	__class__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})Úformatr   r   r   ©r   r   r   r   Ú__str__.   s    ÿýýz#_UFuncBinaryResolutionError.__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 )Ú_UFuncNoLoopErrorz* Thrown when a ufunc loop cannot be found c                    s   t ƒ  |¡ t|ƒ| _d S r   )r   r   r   r   r   r   r   r   r   9   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})r   r   r   r   r   Úninr    r   r   r   r!   =   s    ÿúz_UFuncNoLoopError.__str__r"   r   r   r   r   r$   6   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   J   s    z_UFuncCastingError.__init__)r   r   r   r   r#   r   r   r   r   r&   H   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   T   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!   X   s
    ÿüz_UFuncInputCastingError.__str__r"   r   r   r   r   r*   Q   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   f   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!   j   s
    ÿüz _UFuncOutputCastingError.__str__r"   r   r   r   r   r1   c   s   r1   Únumpyc                   @   s   e Zd ZdS )ÚTooHardErrorN)r   r   r   r   r   r   r   r4   v   s   r4   c                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	Ú	AxisErroraÞ  Axis supplied was invalid.

    This is raised whenever an ``axis`` parameter is specified that is larger
    than the number of array dimensions.
    For compatibility with code written against older numpy versions, which
    raised a mixture of `ValueError` and `IndexError` for this situation, this
    exception subclasses both to ensure that ``except ValueError`` and
    ``except IndexError`` statements continue to catch `AxisError`.

    .. versionadded:: 1.13

    Parameters
    ----------
    axis : int or str
        The out of bounds axis or a custom exception message.
        If an axis is provided, then `ndim` should be specified as well.
    ndim : int, optional
        The number of array dimensions.
    msg_prefix : str, optional
        A prefix for the exception message.

    Attributes
    ----------
    axis : int, optional
        The out of bounds axis or ``None`` if a custom exception
        message was provided. This should be the axis as passed by
        the user, before any normalization to resolve negative indices.

        .. versionadded:: 1.22
    ndim : int, optional
        The number of array dimensions or ``None`` if a custom exception
        message was provided.

        .. versionadded:: 1.22


    Examples
    --------
    >>> array_1d = np.arange(10)
    >>> np.cumsum(array_1d, axis=1)
    Traceback (most recent call last):
      ...
    numpy.AxisError: axis 1 is out of bounds for array of dimension 1

    Negative axes are preserved:

    >>> np.cumsum(array_1d, axis=-2)
    Traceback (most recent call last):
      ...
    numpy.AxisError: axis -2 is out of bounds for array of dimension 1

    The class constructor generally takes the axis and arrays'
    dimensionality as arguments:

    >>> print(np.AxisError(2, 1, msg_prefix='error'))
    error: axis 2 is out of bounds for array of dimension 1

    Alternatively, a custom exception message can be passed:

    >>> print(np.AxisError('Custom error message'))
    Custom error message

    ©ÚaxisÚndimÚ_msgNc                 C   sB   ||  u rd u r,n n|| _ d | _d | _n|| _ || _|| _d S r   )r9   r7   r8   )r   r7   r8   Z
msg_prefixr   r   r   r   ¿   s    zAxisError.__init__c                 C   s\   | j }| j}||  u r d u r*n n| jS d|› d|› �}| jd urT| j› d|› �}|S d S )Nzaxis z) is out of bounds for array of dimension z: r6   )r   r7   r8   Úmsgr   r   r   r!   Ê   s    
zAxisError.__str__)NN)r   r   r   r   Ú	__slots__r   r!   r   r   r   r   r5   {   s   @
r5   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   r=   r>   r   r   r   r   Ú   s    z_ArrayMemoryError.__init__c                 C   s    | j j}| jD ]}||9 }q|S r   )r>   Úitemsizer=   )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   )	r@   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 {})rG   rA   r   r=   r>   )r   Zsize_strr   r   r   r!   
  s
    
ÿÿz_ArrayMemoryError.__str__N)
r   r   r   r   r   ÚpropertyrA   ÚstaticmethodrG   r!   r   r   r   r   r<   ×   s   

$r<   N)r   Znumpy.core.overridesr   r   r   Ú	TypeErrorr   r   r$   r&   r*   r1   ÚRuntimeErrorr4   Ú
ValueErrorÚ
IndexErrorr5   ÚMemoryErrorr<   r   r   r   r   Ú<module>   s(   [