U
    b                      @   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   V/home/fireinfo/NEWAFireInfo/venv/lib/python3.8/site-packages/numpy/core/_exceptions.py_unpack_tuple
   s    r   c                 C   s   t | tst| 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AssertionError__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(td S )N   )superr   tupledtypesr   r   r   r   r   	__class__r   r   r   )   s    
z$_UFuncBinaryResolutionError.__init__c                 C   s   dj | jjf| j 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/   r0   zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})r   Znoutr    r3   r   r)   r*   r(   r1   r   r   r   r"   j   s        z _UFuncOutputCastingError.__str__r#   r   r   r   r   r2   c   s   r2   Z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   ||  krd k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}||  kr d kr*n n| jS d| d| }| jd k	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}ddddddd	g}t |  d
 d
| }d
|| > }| | }~t||krb|d
7 }|| }|t|krt|d
 }|d
|| | > 9 }|}|| }|dkrd||S t|dk rd||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+   r2   RuntimeErrorr4   
ValueError
IndexErrorr5   MemoryErrorr<   r   r   r   r   <module>   s(   [