1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
U
O±d¿"ã@sÞdZddlmZdd„Zdd„ZGdd„deƒZeGd    d
„d
eƒƒZeGd d „d eƒƒZeGd d„deƒƒZ    eGdd„de    ƒƒZ
eGdd„de    ƒƒZ edƒGdd„de ƒƒZ edƒGdd„deeƒƒZeGdd„deƒƒZdS)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|SdS)Nér)Úlen)Útup©rúMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/core/_exceptions.pyÚ _unpack_tuple
s rcCst|tƒst‚|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ÚAssertionErrorÚ__base__Ú__name__)ÚclsrrrÚ_display_as_bases
 
rc@seZdZdZdd„ZdS)ÚUFuncTypeErrorz% Base class for all ufunc exceptions cCs
||_dS©N)Úufunc)ÚselfrrrrÚ__init__"szUFuncTypeError.__init__N)r Ú
__module__Ú __qualname__Ú__doc__rrrrrr srcs(eZdZdZ‡fdd„Zdd„Z‡ZS)Ú_UFuncBinaryResolutionErrorz' Thrown when a binary resolution fails cs,tƒ |¡t|ƒ|_t|jƒdks(t‚dS)Né)ÚsuperrÚtupleÚdtypesrr ©rrr©Ú    __class__rrr)s 
z$_UFuncBinaryResolutionError.__init__cCsdj|jjf|jžŽS)Nz7ufunc {!r} cannot use operands with types {!r} and {!r})Úformatrr r©rrrrÚ__str__.s ÿýýz#_UFuncBinaryResolutionError.__str__©r rrrrr"Ú __classcell__rrrrr&s rcs(eZdZdZ‡fdd„Zdd„Z‡ZS)Ú_UFuncNoLoopErrorz* Thrown when a ufunc loop cannot be found cstƒ |¡t|ƒ|_dSr)rrrrrrrrr9s z_UFuncNoLoopError.__init__cCs6d |jjt|jd|jj…ƒt|j|jjd…ƒ¡S)NzLufunc {!r} did not contain a loop with signature matching types {!r} -> {!r})r rr rrÚninr!rrrr"=s ÿúz_UFuncNoLoopError.__str__r#rrrrr%6s r%cseZdZ‡fdd„Z‡ZS)Ú_UFuncCastingErrorcs"tƒ |¡||_||_||_dSr)rrÚcastingÚfrom_Úto)rrr(r)r*rrrrJs z_UFuncCastingError.__init__)r rrrr$rrrrr'Hsr'cs(eZdZdZ‡fdd„Zdd„Z‡ZS)Ú_UFuncInputCastingErrorz, Thrown when a ufunc input cannot be casted cstƒ ||||¡||_dSr)rrÚin_i©rrr(r)r*ÚirrrrTsz _UFuncInputCastingError.__init__cCs8|jjdkrd |j¡nd}d |jj||j|j|j¡S)Nrú{} ÚzGCannot cast ufunc {!r} input {}from {!r} to {!r} with casting rule {!r})rr&r r,r r)r*r(©rZi_strrrrr"Xsÿüz_UFuncInputCastingError.__str__r#rrrrr+Qs r+cs(eZdZdZ‡fdd„Zdd„Z‡ZS)Ú_UFuncOutputCastingErrorz- Thrown when a ufunc output cannot be casted cstƒ ||||¡||_dSr)rrÚout_ir-rrrrfsz!_UFuncOutputCastingError.__init__cCs8|jjdkrd |j¡nd}d |jj||j|j|j¡S)Nrr/r0zHCannot cast ufunc {!r} output {}from {!r} to {!r} with casting rule {!r})rZnoutr r3r r)r*r(r1rrrr"jsÿüz _UFuncOutputCastingError.__str__r#rrrrr2cs r2Únumpyc@seZdZdZdS)Ú TooHardErrorzÿmax_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 rrrrrrrr5vs    r5c@s&eZdZdZdZddd„Zdd„ZdS)    Ú    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Ú_msgNcCsB||krdkr,nn||_d|_d|_n||_||_||_dSr)r:r8r9)rr8r9Z
msg_prefixrrrrÈszAxisError.__init__cCs\|j}|j}||kr dkr*nn|jSd|›d|›}|jdk    rT|j›d|›}|SdS)Nzaxis z) is out of bounds for array of dimension z: r7)rr8r9Úmsgrrrr"Ós
zAxisError.__str__)NN)r rrrÚ    __slots__rr"rrrrr6„s@
r6c@s8eZdZdZdd„Zedd„ƒZedd„ƒZdd    „Z    d
S) Ú_ArrayMemoryErrorz) Thrown when an array cannot be allocatedcCs||_||_dSr)ÚshapeÚdtype)rr>r?rrrrãsz_ArrayMemoryError.__init__cCs |jj}|jD] }||9}q|Sr)r?Úitemsizer>)rÚ    num_bytesZdimrrrÚ _total_sizeçs
 
z_ArrayMemoryError._total_sizec    CsÖd}d}ddddddd    g}t| ¡d
d
ƒ|}d
||>}||}~t|ƒ|krb|d
7}||}|t|ƒkr’t|ƒd
}|d
|||>9}|}||}|d kr®d  ||¡St|ƒd krÆd ||¡Sd ||¡SdS)z5 Convert a number of bytes into a binary size string é
iÚbytesZKiBZMiBZGiBZTiBZPiBZEiBrrz    {:.0f} {}ièz
{:#.3g} {}z
{:#.0f} {}N)ÚmaxÚ
bit_lengthÚroundrr )    rAZ    LOG2_STEPZSTEPZunitsZunit_iZunit_valZn_unitsZ
new_unit_iZ    unit_namerrrÚ_size_to_stringîs(       z!_ArrayMemoryError._size_to_stringcCs| |j¡}d ||j|j¡S)NzAUnable to allocate {} for an array with shape {} and data type {})rHrBr r>r?)rZsize_strrrrr"s ÿÿz_ArrayMemoryError.__str__N)
r rrrrÚpropertyrBÚ staticmethodrHr"rrrrr=às
 
$r=N)rZnumpy.core.overridesrrrÚ    TypeErrorrrr%r'r+r2Ú RuntimeErrorr5Ú
ValueErrorÚ
IndexErrorr6Ú MemoryErrorr=rrrrÚ<module>s(  [