U
    d<^                     @   sj  d Z ddgZddlZddlmZ ddlmZ ddlmZ dd	lm	Z
 dd
lmZmZmZ ddlmZmZmZmZ dd Zdd ZG dd dZe
je
je
je
je
je
jiZdZe
jee
j de!dde
jee
j"de!dde
j#ee
j$de!dde
j%ee
j&de!ddiZ'i Z(dd Z)i Z*dd Z+d d! Z,d"d# Z-ed$G d%d dZ.ed$G d&d dZ/dS )'zJMachine limits for Float32 and Float64 and (long double) if available...

finfoiinfo    N   )MachAr)
set_module)numeric)numerictypes)arrayinfNaN)log10exp2	nextafterisnanc                 C   s   | j dkr|  } d| _| S )zfix rank-0 --> rank-1r   )r   )ndimcopyshapea r   8/tmp/pip-unpacked-wheel-c1z6a0q8/numpy/core/getlimits.py_fr0   s    
r   c                 C   s   | j dkr|  } d| _| S )zfix rank > 0 --> rank-0r   r   )sizer   r   r   r   r   r   _fr1   s    
r   c                   @   sN   e Zd ZdZddddZedd Zedd	 Zd
d Zdd Z	dd Z
dS )
MachArLikez$ Object to simulate MachAr instance N)smallest_subnormalc          	      K   s4  t | | _|| _| jd | _|s@t| d| d| jd| _n|| _| | | _| _| || _	| | | _
| _| || _| | | _| _| jd || _| j| tt| j | _| | d| j  | _| | j| _| | j	| _| | j| _| | j
| _| | j| _| | j| _d S )Ntitler   r   dtypeitype
   )_MACHAR_PARAMSparamsftyper   r   _smallest_subnormal_float_to_floatepsilonepsepsnegZxmaxhugeZxminsmallest_normaltinyibeta__dict__updateintr   	precision_float_conv
resolution_float_to_str_str_eps_str_epsneg	_str_xmin	_str_xmax_str_resolution_str_smallest_normal)	selfr#   r'   r(   r)   r+   r,   r   kwargsr   r   r   __init__"   s6    
  
zMachArLike.__init__c                 C   s6   | j }| d|kr,tjd| jtdd | |S )a   Return the value for the smallest subnormal.

        Returns
        -------
        smallest_subnormal : float
            value for the smallest subnormal.

        Warns
        -----
        UserWarning
            If the calculated value for the smallest subnormal is zero.
        r   z8The value of the smallest subnormal for {} type is zero.   
stacklevel)r$   r#   warningswarnformatUserWarningr%   r:   valuer   r   r   r   >   s     zMachArLike.smallest_subnormalc                 C   s   |  | jS )z;Return the string representation of the smallest subnormal.)r3   r   r:   r   r   r   _str_smallest_subnormalV   s    z"MachArLike._str_smallest_subnormalc                 C   s   t | |S )zConverts float to float.

        Parameters
        ----------
        value : float
            value to be converted.
        )r   r1   rD   r   r   r   r%   [   s    zMachArLike._float_to_floatc                 C   s   t |g| jS )zConverts float to conv.

        Parameters
        ----------
        value : float
            value to be converted.
        )r	   r#   rD   r   r   r   r1   e   s    zMachArLike._float_convc                 C   s   | j d tt|d | j S )zConverts float to str.

        Parameters
        ----------
        value : float
            value to be converted.
        fmtr   )r"   r	   r   r#   rD   r   r   r   r3   o   s    zMachArLike._float_to_str)__name__
__module____qualname____doc__r<   propertyr   rG   r%   r1   r3   r   r   r   r   r       s   



r   z(numpy {} precision floating point numberz%24.16edouble)r   rH   r   z%15.7esinglez%szlong doublez%12.5ehalfc                 C   s   | t |< d S N)_KNOWN_TYPES)macharZbytepatr   r   r   _register_type   s    rT   c                  C   s  t j} t| dddddddddt| dt| d| d	| d
d}t|d |td< t j}t|dddddddddt|dt|d|ddd  t|dd}t|d |td< t j}d}d}t|dddddddddd|d| | |d  |d}t|d! |td"< t j}t|d#}	t|d$}
t	j
d%d& |d'|	 |
 |d  }W 5 Q R X t|d(d#d$d)d*d+dddt|d(|	||
d}t|d, t|d, |td< t|d-}t|d$}t	j
d%d& |d'| | |d  }W 5 Q R X t|d.d-d$d)d/d+dddt|d.|||d}t|d0 |td1< t|t|d|d2}t}|td3d}t|d4d5ddd6ddddt|d4t|d5|||d7}t|d8 t|d9 |td:< d S );Niii   r       r=   r   i  g      ?)machepnegepminexpmaxexpitiexpr,   irndngrdr'   r(   r)   r+   s   fiii         g   ?s   ̽    g      <g       iiii   4      g      <g      ?   s   @   iiignore)allr   ii @  p      s   ii?   s
   P   r   g        iii   )rW   rX   rY   rZ   r[   r\   r,   r]   r^   r'   r(   r)   r+   r   s   Y<s   Y<dd)ntypesZfloat16r   r   rT   	_float_maZfloat32Zfloat64
longdoubler   Zerrstater   r
   r   )Zf16Z
float16_maZf32Z
float32_maZf64Z
epsneg_f64Ztiny_f64Z
float64_maZldZepsneg_f128Z	tiny_f128Z	huge_f128Zfloat128_maZ
epsneg_f80Ztiny_f80Zhuge_f80Z
float80_maZhuge_ddZsmallest_normal_ddZsmallest_subnormal_ddZfloat_dd_mar   r   r   _register_known_types   s   







"
"



rr   c                 C   s   t | }|dkrtt| | dd }d}| tjkrPt|dd }|dkrbt|}|dk	rn|S t	j
d| d|  dtdd	 t| S )
a   Get MachAr instance or MachAr-like instance

    Get parameters for floating point type, by first trying signatures of
    various known floating point types, then, if none match, attempting to
    identify parameters by analysis.

    Parameters
    ----------
    ftype : class
        Numpy floating point type class (e.g. ``np.float64``)

    Returns
    -------
    ma_like : instance of :class:`MachAr` or :class:`MachArLike`
        Object giving floating point parameters for `ftype`.

    Warns
    -----
    UserWarning
        If the binary signature of the float type is not in the dictionary of
        known float types.
    Nz-0.1<r    z
Signature z for zz does not match any known type: falling back to type probe function.
This warnings indicates broken support for the dtype!r=   r>   )r!   get
ValueErrorreprZnewbyteordertobytesro   rq   rR   r@   rA   rC   _discovered_machar)r#   r"   keyZma_liker   r   r   _get_machar1  s"    


 rz   c                    s>   t   t fddfdd fdd fddd S )zB Create MachAr instance with found information on float types
    c                    s   t | g S rQ   )r	   vr#   r   r   <lambda>e      z$_discovered_machar.<locals>.<lambda>c                    s   t |  d d S )Nr   r   )r   Zastyper{   )r"   r   r   r~   f  r   c                    s   t t| d  S )Nr   r	   r   r{   r}   r   r   r~   g  r   c                    s   d t t| d   S )NrH   r   r   r{   r#   r"   r   r   r~   h  r   r   )r!   r   r}   r   r   r   rx   a  s    

rx   Znumpyc                   @   sX   e Zd ZdZi Zdd Zdd Zdd Zdd	 Ze	d
d Z
e	dd Ze	dd ZdS )r   a7  
    finfo(dtype)

    Machine limits for floating point types.

    Attributes
    ----------
    bits : int
        The number of bits occupied by the type.
    eps : float
        The difference between 1.0 and the next smallest representable float
        larger than 1.0. For example, for 64-bit binary floats in the IEEE-754
        standard, ``eps = 2**-52``, approximately 2.22e-16.
    epsneg : float
        The difference between 1.0 and the next smallest representable float
        less than 1.0. For example, for 64-bit binary floats in the IEEE-754
        standard, ``epsneg = 2**-53``, approximately 1.11e-16.
    iexp : int
        The number of bits in the exponent portion of the floating point
        representation.
    machar : MachAr
        The object which calculated these parameters and holds more
        detailed information.

        .. deprecated:: 1.22
    machep : int
        The exponent that yields `eps`.
    max : floating point number of the appropriate type
        The largest representable number.
    maxexp : int
        The smallest positive power of the base (2) that causes overflow.
    min : floating point number of the appropriate type
        The smallest representable number, typically ``-max``.
    minexp : int
        The most negative power of the base (2) consistent with there
        being no leading 0's in the mantissa.
    negep : int
        The exponent that yields `epsneg`.
    nexp : int
        The number of bits in the exponent including its sign and bias.
    nmant : int
        The number of bits in the mantissa.
    precision : int
        The approximate number of decimal digits to which this kind of
        float is precise.
    resolution : floating point number of the appropriate type
        The approximate decimal resolution of this type, i.e.,
        ``10**-precision``.
    tiny : float
        An alias for `smallest_normal`, kept for backwards compatibility.
    smallest_normal : float
        The smallest positive floating point number with 1 as leading bit in
        the mantissa following IEEE-754 (see Notes).
    smallest_subnormal : float
        The smallest positive floating point number with 0 as leading bit in
        the mantissa following IEEE-754.

    Parameters
    ----------
    dtype : float, dtype, or instance
        Kind of floating point data-type about which to get information.

    See Also
    --------
    MachAr : The implementation of the tests that produce this information.
    iinfo : The equivalent for integer data types.
    spacing : The distance between a value and the nearest adjacent number
    nextafter : The next floating point value after x1 towards x2

    Notes
    -----
    For developers of NumPy: do not instantiate this at the module level.
    The initial calculation of these parameters is expensive and negatively
    impacts import times.  These objects are cached, so calling ``finfo()``
    repeatedly inside your functions is not a problem.

    Note that ``smallest_normal`` is not actually the smallest positive
    representable value in a NumPy floating point type. As in the IEEE-754
    standard [1]_, NumPy floating point types make use of subnormal numbers to
    fill the gap between 0 and ``smallest_normal``. However, subnormal numbers
    may have significantly reduced precision [2]_.

    References
    ----------
    .. [1] IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2008,
           pp.1-70, 2008, http://www.doi.org/10.1109/IEEESTD.2008.4610935
    .. [2] Wikipedia, "Denormal Numbers",
           https://en.wikipedia.org/wiki/Denormal_number
    c                 C   s  zt |}W n" tk
r0   t t|}Y nX | j|d }|d k	rL|S |g}t |}||k	rr|| |}t|t j	st
d| | j|d }|d k	r|S t|t jst| }||k	r|| |}| j|d }|d k	r|S t| |}|D ]}|| j|< q|S )Nzdata type %r not inexact)r   r   	TypeErrortype_finfo_cachert   Z
obj2sctypeappend
issubclassZinexactru   Zfloating_convert_to_floatobject__new___init)clsr   objZdtypesZnewdtypedtr   r   r   r     s:    


zfinfo.__new__c                 C   s   t || _t|}dD ]}t| |t|| qdD ]}t| |t||jd  q4| jjd | _|jjd | _	| j	 | _
|jjd | _|j| _|j| _|| _|j | _|j | _|j | _|j | _|j | _|j | _|j | _| S )N)r0   r\   rZ   rY   rX   rW   )r2   r(   r   r   ra   )r   r   rz   setattrgetattrflatitemsizebitsr)   maxminr'   r\   Znexpr[   Znmant_macharr6   stripZ	_str_tinyr7   Z_str_maxr5   r4   r8   r9   rG   )r:   r   rS   wordr   r   r   r     s*    
zfinfo._initc                 C   s   d}|| j  S )Na+  Machine parameters for %(dtype)s
---------------------------------------------------------------
precision = %(precision)3s   resolution = %(_str_resolution)s
machep = %(machep)6s   eps =        %(_str_eps)s
negep =  %(negep)6s   epsneg =     %(_str_epsneg)s
minexp = %(minexp)6s   tiny =       %(_str_tiny)s
maxexp = %(maxexp)6s   max =        %(_str_max)s
nexp =   %(nexp)6s   min =        -max
smallest_normal = %(_str_smallest_normal)s   smallest_subnormal = %(_str_smallest_subnormal)s
---------------------------------------------------------------
)r-   r:   rH   r   r   r   __str__  s    zfinfo.__str__c                 C   s"   | j j}| j }||d< d| S )NklasszZ%(klass)s(resolution=%(resolution)s, min=-%(_str_max)s, max=%(_str_max)s, dtype=%(dtype)s))	__class__rI   r-   r   )r:   cdr   r   r   __repr__  s    
zfinfo.__repr__c                 C   s0   t | jjjd r"tjdtdd | jjjd S )a7  Return the value for the smallest normal.

        Returns
        -------
        smallest_normal : float
            Value for the smallest normal.

        Warns
        -----
        UserWarning
            If the calculated value for the smallest normal is requested for
            double-double.
        r   z;The value of smallest normal is undefined for double doubler=   r>   )r   r   r*   r   r@   rA   rC   rF   r   r   r   r*     s     zfinfo.smallest_normalc                 C   s   | j S )aQ  Return the value for tiny, alias of smallest_normal.

        Returns
        -------
        tiny : float
            Value for the smallest normal, alias of smallest_normal.

        Warns
        -----
        UserWarning
            If the calculated value for the smallest normal is requested for
            double-double.
        )r*   rF   r   r   r   r+   3  s    z
finfo.tinyc                 C   s   t jdtdd | jS )zThe object which calculated these parameters and holds more
        detailed information.

        .. deprecated:: 1.22
        z)`finfo.machar` is deprecated (NumPy 1.22)r=   r>   )r@   rA   DeprecationWarningr   rF   r   r   r   rS   D  s     zfinfo.macharN)rI   rJ   rK   rL   r   r   r   r   r   rM   r*   r+   rS   r   r   r   r   r   l  s   Z!

c                   @   sH   e Zd ZdZi Zi Zdd Zedd Zedd Z	dd	 Z
d
d ZdS )r   al  
    iinfo(type)

    Machine limits for integer types.

    Attributes
    ----------
    bits : int
        The number of bits occupied by the type.
    min : int
        The smallest integer expressible by the type.
    max : int
        The largest integer expressible by the type.

    Parameters
    ----------
    int_type : integer type, dtype, or instance
        The kind of integer data type to get information about.

    See Also
    --------
    finfo : The equivalent for floating point data types.

    Examples
    --------
    With types:

    >>> ii16 = np.iinfo(np.int16)
    >>> ii16.min
    -32768
    >>> ii16.max
    32767
    >>> ii32 = np.iinfo(np.int32)
    >>> ii32.min
    -2147483648
    >>> ii32.max
    2147483647

    With instances:

    >>> ii32 = np.iinfo(np.int32(10))
    >>> ii32.min
    -2147483648
    >>> ii32.max
    2147483647

    c                 C   s~   zt || _W n$ tk
r4   t t|| _Y nX | jj| _| jjd | _d| j| jf | _| jdkrztd| jf d S )Nra   z%s%diuzInvalid integer data type %r.)	r   r   r   r   kindr   r   ry   ru   )r:   Zint_typer   r   r   r<     s    

ziinfo.__init__c                 C   s\   | j dkrdS ztj| j }W n4 tk
rR   td| jd >  }|tj| j< Y nX |S dS )zMinimum value of given dtype.ur   r   N)r   r   	_min_valsry   KeyErrorr/   r   r:   valr   r   r   r     s    
z	iinfo.minc                 C   sj   zt j| j }W nT tk
rd   | jdkr>td| j> d }ntd| jd > d }|t j| j< Y nX |S )zMaximum value of given dtype.r   r   )r   	_max_valsry   r   r   r/   r   r   r   r   r   r     s    
z	iinfo.maxc                 C   s   d}|| j | j| jd S )zString representation.zMachine parameters for %(dtype)s
---------------------------------------------------------------
min = %(min)s
max = %(max)s
---------------------------------------------------------------
r   r   r   r   r   r   r   r   r     s    ziinfo.__str__c                 C   s   d| j j| j| j| jf S )Nz%s(min=%s, max=%s, dtype=%s))r   rI   r   r   r   rF   r   r   r   r     s
      ziinfo.__repr__N)rI   rJ   rK   rL   r   r   r<   rM   r   r   r   r   r   r   r   r   r   S  s   0

)0rL   __all__r@   r   r   Z	overridesr    r   r   ro   r	   r
   r   Zumathr   r   r   r   r   r   r   ZcsinglerO   Zcomplex_Zfloat_Z
clongfloatZ	longfloatr   Z
_title_fmtrN   dictZint64rB   Zint32rq   ZlonglongrP   Zint16r!   rR   rT   rp   rr   rz   rx   r   r   r   r   r   r   <module>   sp   [        0 g