o 6a@sdZddlmZddZddZGdddeZeGd d d eZeGd d d eZeGd ddeZ eGddde Z eGddde Z edGddde Z edGdddeeZeGdddeZdS)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_modulecCst|dkr |dS|S)Nr)len)tupr8/usr/lib/python3/dist-packages/numpy/core/_exceptions.py _unpack_tuple s rcCst|tsJ|jj|_|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__)clsrrr_display_as_bases rc@seZdZdZddZdS)UFuncTypeErrorz% Base class for all ufunc exceptions cCs ||_dSN)ufunc)selfrrrr__init__"s zUFuncTypeError.__init__N)r __module__ __qualname____doc__rrrrrr s rc(eZdZdZfddZddZZS)_UFuncBinaryResolutionErrorz' Thrown when a binary resolution fails cs,t|t||_t|jdksJdS)N)superrtupledtypesrrrr __class__rrr)s  z$_UFuncBinaryResolutionError.__init__cCsdj|jjg|jRS)Nz7ufunc {!r} cannot use operands with types {!r} and {!r})formatrr rrrrr__str__.s z#_UFuncBinaryResolutionError.__str__r rrrrr" __classcell__rrrrr&s rcr)_UFuncNoLoopErrorz* Thrown when a ufunc loop cannot be found cst|t||_dSr)rrrrrrrrr9s z_UFuncNoLoopError.__init__cCs6d|jjt|jd|jjt|j|jjdS)NzLufunc {!r} did not contain a loop with signature matching types {!r} -> {!r})r rr rrninr!rrrr"=sz_UFuncNoLoopError.__str__r#rrrrr%6 r%cseZdZfddZZS)_UFuncCastingErrorcs"t|||_||_||_dSr)rrcastingfrom_to)rrr)r*r+rrrrJs  z_UFuncCastingError.__init__)r rrrr$rrrrr(Hsr(cr)_UFuncInputCastingErrorz, Thrown when a ufunc input cannot be casted ct||||||_dSr)rrin_irrr)r*r+irrrrT z _UFuncInputCastingError.__init__cC8|jjdkr d|jnd}d|jj||j|j|jS)Nr{} zGCannot cast ufunc {!r} input {}from {!r} to {!r} with casting rule {!r})rr&r r.r r*r+r)ri_strrrrr"X z_UFuncInputCastingError.__str__r#rrrrr,Qr'r,cr)_UFuncOutputCastingErrorz- Thrown when a ufunc output cannot be casted cr-r)rrout_ir/rrrrfr1z!_UFuncOutputCastingError.__init__cCr2)Nrr3r4zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})rnoutr r9r r*r+r)r5rrrr"jr7z _UFuncOutputCastingError.__str__r#rrrrr8cr'r8numpyc@s eZdZdS) TooHardErrorN)r rrrrrrr<vsr<cs"eZdZdZdfdd ZZS) AxisErrorz Axis supplied was invalid. NcsF|dur |dur |}nd||}|durd||}t|dS)Nz2axis {} is out of bounds for array of dimension {}z{}: {})r rr)raxisndim msg_prefixmsgrrrr~s zAxisError.__init__)NN)r rrrrr$rrrrr={sr=c@s8eZdZdZddZeddZeddZdd Z d S) _ArrayMemoryErrorz) Thrown when an array cannot be allocatedcCs||_||_dSr)shapedtype)rrCrDrrrrs z_ArrayMemoryError.__init__cCs |jj}|jD]}||9}q|Sr)rDitemsizerC)r num_bytesdimrrr _total_sizes  z_ArrayMemoryError._total_sizec Csd}d}gd}t|dd|}d||>}||}~t||kr,|d7}||}|t|krDt|d}|d|||>9}|}||}|dkrRd||St|dkr^d||Sd ||S) z5 Convert a number of bytes into a binary size string i)bytesKiBMiBGiBTiBPiBEiBrrz {:.0f} {}iz {:#.3g} {}z {:#.0f} {})max bit_lengthroundrr ) rF LOG2_STEPSTEPunitsunit_iunit_valn_units new_unit_i unit_namerrr_size_to_strings(        z!_ArrayMemoryError._size_to_stringcCs||j}d||j|jS)NzAUnable to allocate {} for an array with shape {} and data type {})r\rHr rCrD)rsize_strrrrr"s z_ArrayMemoryError.__str__N) r rrrrpropertyrH staticmethodr\r"rrrrrBs   $rBN)rnumpy.core.overridesrrr TypeErrorrrr%r(r,r8 RuntimeErrorr< ValueError IndexErrorr= MemoryErrorrBrrrrs*