B
    G0d                 @   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   H/var/www/html/venv/lib/python3.7/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 )N)r   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   nin)r   r   r   r   r   =   s    z_UFuncNoLoopError.__str__)r   r   r   r   r   r   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 )N)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 )N)r   r   in_i)r   r   r#   r$   r%   i)r   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   z{}  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   s    z_UFuncInputCastingError.__str__)r   r   r   r   r   r   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 )N)r   r   out_i)r   r   r#   r$   r%   r(   )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   z{} r)   zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})r   Znoutr   r,   r   r$   r%   r#   )r   r*   r   r   r   r   j   s    z _UFuncOutputCastingError.__str__)r   r   r   r   r   r   r   r   r   )r   r   r+   c   s   r+   numpyc               @   s   e Zd ZdS )TooHardErrorN)r   r   r   r   r   r   r   r.   v   s   r.   c                   s"   e Zd ZdZd fdd	Z  ZS )	AxisErrorz Axis supplied was invalid. Nc                sF   |d kr|d kr|}n d ||}|d k	r6d ||}t | d S )Nz2axis {} is out of bounds for array of dimension {}z{}: {})r   r   r   )r   ZaxisndimZ
msg_prefixmsg)r   r   r   r   ~   s    zAxisError.__init__)NN)r   r   r   r   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 )N)shapedtype)r   r3   r4   r   r   r   r      s    z_ArrayMemoryError.__init__c             C   s$   | j j}x| jD ]}||9 }qW |S )N)r4   itemsizer3   )r   	num_bytes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   bytesKiBMiBGiBTiBPiBEiBr   r   z	{:.0f} {}i  z
{:#.3g} {}z
{:#.0f} {}N)max
bit_lengthroundr   r   )	r6   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 {})rD   r8   r   r3   r4   )r   Zsize_strr   r   r   r      s    z_ArrayMemoryError.__str__N)
r   r   r   r   r   propertyr8   staticmethodrD   r   r   r   r   r   r2      s
   %r2   N)r   Znumpy.core.overridesr   r   r   	TypeErrorr   r   r    r"   r&   r+   RuntimeErrorr.   
ValueError
IndexErrorr/   MemoryErrorr2   r   r   r   r   <module>   s(   
