o
    i!                     @   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 )N   r   )len)tup r   Q/var/www/edux/Edux_v2/venv/lib/python3.10/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                       (   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                       r   )_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       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                       r   )_UFuncInputCastingErrorz, Thrown when a ufunc input cannot be casted c                       t  |||| || _d S r   )r   r   in_ir   r   r)   r*   r+   ir   r   r   r   T      
z _UFuncInputCastingError.__init__c                 C   8   | 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   i_strr   r   r   r"   X      z_UFuncInputCastingError.__str__r#   r   r   r   r   r,   Q   r'   r,   c                       r   )_UFuncOutputCastingErrorz- Thrown when a ufunc output cannot be casted c                    r-   r   )r   r   out_ir/   r   r   r   r   f   r1   z!_UFuncOutputCastingError.__init__c                 C   r2   )Nr   r3   r4   zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})r   noutr    r9   r   r*   r+   r)   r5   r   r   r   r"   j   r7   z _UFuncOutputCastingError.__str__r#   r   r   r   r   r8   c   r'   r8   numpyc                   @   s   e Zd ZdZdS )TooHardErrorzmax_work was exceeded.

    This is raised whenever the maximum number of candidate solutions 
    to consider specified by the ``max_work`` parameter is exceeded.
    Assigning a finite number to max_work may have caused the operation 
    to fail.

    N)r   r   r   r   r   r   r   r   r<   v   s    	r<   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   sD   ||  u r
d u rn n|| _ d | _d | _d S || _ || _|| _d S r   )rA   r?   r@   )r   r?   r@   
msg_prefixr   r   r   r      s   

zAxisError.__init__c                 C   sT   | j }| j}||  u rd u r| jS  d| d| }| jd ur(| j d| }|S )Nzaxis z) is out of bounds for array of dimension z: r>   )r   r?   r@   msgr   r   r   r"      s   
zAxisError.__str__)NN)r   r   r   r   	__slots__r   r"   r   r   r   r   r=      s
    @
r=   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   rF   rG   r   r   r   r      s   
z_ArrayMemoryError.__init__c                 C   s    | j j}| jD ]}||9 }q|S r   )rG   itemsizerF   )r   	num_bytesdimr   r   r   _total_size   s   

z_ArrayMemoryError._total_sizec           	      C   s   d}d}g d}t |  d d| }d|| > }| | }~t||kr,|d7 }|| }|t|krDt|d }|d|| | > 9 }|}|| }|dkrRd||S t|dk r^d||S d	||S )
z5 Convert a number of bytes into a binary size string 
   i   )bytesKiBMiBGiBTiBPiBEiBr   r   z	{:.0f} {}i  z
{:#.3g} {}z
{:#.0f} {})max
bit_lengthroundr   r    )	rI   	LOG2_STEPSTEPunitsunit_iunit_valn_units
new_unit_i	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_   rK   r    rF   rG   )r   size_strr   r   r   r"     s   z_ArrayMemoryError.__str__N)
r   r   r   r   r   propertyrK   staticmethodr_   r"   r   r   r   r   rE      s    

$rE   N)r   numpy.core.overridesr   r   r   	TypeErrorr   r   r%   r(   r,   r8   RuntimeErrorr<   
ValueError
IndexErrorr=   MemoryErrorrE   r   r   r   r   <module>   s*    [