
    ,Vh                         d Z ddlmZ d Zd Z G d de      Ze G d de             Ze G d	 d
e             Ze G d de             Z	e G d de	             Z
e G d de	             Ze G d de             Zy)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                 ,    t        |       dk(  r| d   S | S )N       )len)tups    G/home/dcms/DCMS/lib/python3.12/site-packages/numpy/_core/_exceptions.py_unpack_tupler
   
   s    
3x1}1v
    c                 `    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__)clss    r	   _display_as_baser      s*     c9%%%<<((CLJr   c                       e Zd ZdZd Zy)UFuncTypeErrorz% Base class for all ufunc exceptions c                     || _         y N)ufunc)selfr   s     r	   __init__zUFuncTypeError.__init__"   s	    
r   N)r   
__module____qualname____doc__r    r   r	   r   r       s
    /r   r   c                   (     e Zd ZdZ fdZd Z xZS )_UFuncNoLoopErrorz* Thrown when a ufunc loop cannot be found c                 D    t         |   |       t        |      | _        y r   )superr   tupledtypesr   r   r#   	__class__s      r	   r   z_UFuncNoLoopError.__init__)   s    Fmr   c           	          dj                  | 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   s    r	   __str__z_UFuncNoLoopError.__str__-   sY    
&JJ$++otzz~~67$++djjnno67
	
r   r   r   r   r   r   r*   __classcell__r%   s   @r	   r   r   &   s    4$
r   r   c                   (     e Zd ZdZ fdZd Z xZS )_UFuncBinaryResolutionErrorz' Thrown when a binary resolution fails c                 Z    t         |   ||       t        | j                        dk(  sJ y )Nr   )r!   r   r   r#   r$   s      r	   r   z$_UFuncBinaryResolutionError.__init__;   s)    '4;;1$$$r   c                 d     dj                   | j                  j                  g| j                   S )Nz7ufunc {!r} cannot use operands with types {!r} and {!r})r'   r   r   r#   r)   s    r	   r*   z#_UFuncBinaryResolutionError.__str__?   s4    E
&JJ
 #'++
 	
r   r+   r-   s   @r	   r/   r/   8   s    1%
r   r/   c                        e Zd Z fdZ xZS )_UFuncCastingErrorc                 N    t         |   |       || _        || _        || _        y r   )r!   r   castingfrom_to)r   r   r5   r6   r7   r%   s        r	   r   z_UFuncCastingError.__init__I   s%    
r   )r   r   r   r   r,   r-   s   @r	   r3   r3   G   s     r   r3   c                   (     e Zd ZdZ fdZd Z xZS )_UFuncInputCastingErrorz, Thrown when a ufunc input cannot be casted c                 8    t         |   ||||       || _        y r   )r!   r   in_ir   r   r5   r6   r7   ir%   s         r	   r   z _UFuncInputCastingError.__init__S   s    3	r   c                     | j                   j                  dk7  rdj                  | j                        nd}dj                  | 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   r6   r7   r5   r   i_strs     r	   r*   z_UFuncInputCastingError.__str__W   sZ    +/::>>Q+>TYY'B
&JJ

DGGT\\
	
r   r+   r-   s   @r	   r9   r9   P   s    6
r   r9   c                   (     e Zd ZdZ fdZd Z xZS )_UFuncOutputCastingErrorz- Thrown when a ufunc output cannot be casted c                 8    t         |   ||||       || _        y r   )r!   r   out_ir<   s         r	   r   z!_UFuncOutputCastingError.__init__e   s    3
r   c                     | j                   j                  dk7  rdj                  | j                        nd}dj                  | j                   j                  || j
                  | j                  | j                        S )Nr   r?   r@   zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})r   noutr'   rF   r   r6   r7   r5   rA   s     r	   r*   z _UFuncOutputCastingError.__str__i   sZ    ,0JJOOq,@TZZ(b
&JJ

DGGT\\
	
r   r+   r-   s   @r	   rD   rD   b   s    7
r   rD   c                   <    e Zd ZdZd Zed        Zed        Zd Z	y)_ArrayMemoryErrorz) Thrown when an array cannot be allocatedc                      || _         || _        y r   )shapedtype)r   rL   rM   s      r	   r   z_ArrayMemoryError.__init__w   s    

r   c                 ^    | j                   j                  }| j                  D ]  }||z  }	 |S r   )rM   itemsizerL   )r   	num_bytesdims      r	   _total_sizez_ArrayMemoryError._total_size{   s4    JJ''	:: 	CI	r   c                    d}d}g d}t        | j                         dz
  d      |z  }d||z  z  }| |z  }~t        |      |k(  r
|dz  }||z  }|t        |      k\  rt        |      dz
  }|d||z
  |z  z  z  }|}||   }|dk(  rdj	                  ||      S t        |      dk  rdj	                  ||      S d	j	                  ||      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'   )	rP   	LOG2_STEPSTEPunitsunit_iunit_valn_units
new_unit_i	unit_names	            r	   _size_to_stringz!_ArrayMemoryError._size_to_string   s    
 	CY))+a/3y@)+,h& >T!aKFtOG SZUaJqfz1Y>??GF&M	Q;%%gy997^d"&&w	::  &&w	::r   c                     | j                  | j                        }dj                  || j                  | j                        S )NzAUnable to allocate {} for an array with shape {} and data type {})rg   rR   r'   rL   rM   )r   size_strs     r	   r*   z_ArrayMemoryError.__str__   s6    ''(8(89OVHdjj$**5	
r   N)
r   r   r   r   r   propertyrR   staticmethodrg   r*   r   r   r	   rJ   rJ   t   s8    3   "; ";H
r   rJ   N)r   _utilsr   r
   r   	TypeErrorr   r   r/   r3   r9   rD   MemoryErrorrJ   r   r   r	   <module>ro      s     Y  
 
 
" 
"3 
 
    
0 
 
" 
1 
 
" 7
 7
 7
r   