B
    G0d>M                 @   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 ddlmZmZ ddl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)log10exp2)umathc             C   s   | j dkr|  } d| _| S )zfix rank-0 --> rank-1r   )r   )ndimcopyshape)a r   F/var/www/html/venv/lib/python3.7/site-packages/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               @   s   e Zd ZdZdd ZdS )
MachArLikez$ Object to simulate MachAr instance c      
         s   t  fdd  fdd}fdd}	d | _|| | _| _||| _|| | _| _|| | _| _d || _	| j
| tt| j | _| d| j  | _|	| j| _|	| j| _|	| j| _|	| j| _|	| j| _d S )Nc                s   t | g S )N)r	   )v)ftyper   r   <lambda>'       z%MachArLike.__init__.<locals>.<lambda>c                s   t  | S )N)r   )r   )
float_convr   r   r   (   r   c                s   d t t| d   S )Nfmtr   )r	   r   )r   )r   paramsr   r   r   )   r   titleitype
   )_MACHAR_PARAMSr   epsilonepsepsnegZxmaxhugeZxmintinyibeta__dict__updateintr   	precision
resolution_str_eps_str_epsneg	_str_xmin	_str_xmax_str_resolution)
selfr   r$   r%   r&   r'   r(   kwargsZfloat_to_floatZfloat_to_strr   )r   r   r   r   __init__#   s$    

zMachArLike.__init__N)__name__
__module____qualname____doc__r5   r   r   r   r   r       s   r   z(numpy {} precision floating point numberz%24.16edouble)r    r   r   z%15.7esinglez%szlong doublez%12.5ehalfc             C   s   | t |< d S )N)_KNOWN_TYPES)macharZbytepatr   r   r   _register_typeZ   s    r?   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 d 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 d Q R X t|d.d-d$d)d/d+dddt|d.|||d}t|d0 |td1< ttd2rDt|t|dn|j}t|d3d4ddd5ddddt|d3t|d4|t|dd}t|d6 t|d7 |td8< d S )9Niii   r!         r   i  g      ?)machepnegepminexpmaxexpitiexpr(   ZirndZ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   	nextafteriii   s   Y<s   Y<dd)ntypesZfloat16r   r   r?   	_float_maZfloat32Zfloat64
longdoubler   Zerrstatehasattrr   rW   r
   r&   )Zf16Z
float16_maZf32Z
float32_maZf64Z
epsneg_f64Ztiny_f64Z
float64_maldZepsneg_f128Z	tiny_f128Z	huge_f128Zfloat128_maZ
epsneg_f80Ztiny_f80Zhuge_f80Z
float80_maZhuge_ddZfloat_dd_mar   r   r   _register_known_types^   s    






"
"

 

r_   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|| 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!   zVSignature {} for {} does not match any known type: falling back to type probe functionrB   )
stacklevel)r"   get
ValueErrorreprZnewbyteordertobytesrZ   r\   r=   warningswarnformatUserWarning_discovered_machar)r   r   keyZma_liker   r   r   _get_machar   s     



rl   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 )N)r	   )r   )r   r   r   r      r   z$_discovered_machar.<locals>.<lambda>c                s   t |  d d S )Nr    r   )r   Zastype)r   )r   r   r   r   !  r   c                s   t t| d  S )Nr   )r	   r   )r   )r   r   r   r   "  r   c                s   d t t| d   S )Nr   r   )r	   r   )r   )r   r   r   r   r   #  r   r   )r"   r   )r   r   )r   r   r   rj     s    

rj   numpyc               @   s4   e Zd ZdZi Zdd Zdd Zdd Zdd	 Zd
S )r   a  
    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.
    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
        The smallest positive floating point number with full precision
        (see Notes).

    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 ``tiny`` 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 ``tiny``. 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  y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| |}x|D ]}|| j|< qW |S )Nzdata type %r not inexact)r   dtype	TypeErrortype_finfo_cacherb   Z
obj2sctypeappend
issubclassZinexactrc   Zfloating_convert_to_floatobject__new___init)clsrn   objZdtypesZnewdtypedtr   r   r   rv   ~  s:    



zfinfo.__new__c             C   s   t || _t|}xdD ]}t| |t|| qW x$dD ]}t| |t||jd  q:W | jjd | _|jjd | _	| j	 | _
|jjd | _|j| _|j| _|| _|j | _|j | _|j | _|j | _|j | _| S )N)r,   rH   rF   rE   rD   rC   )r'   r-   r%   r   rK   )r   rn   rl   setattrgetattrZflatitemsizebitsr&   maxminr$   rH   ZnexprG   Znmantr>   r0   stripZ	_str_tinyr1   Z_str_maxr/   r.   r2   )r3   rn   r>   wordr   r   r   rw     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
---------------------------------------------------------------
)r)   )r3   r   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__r6   r)   r   )r3   cdr   r   r   __repr__  s
    
zfinfo.__repr__N)	r6   r7   r8   r9   rq   rv   rw   r   r   r   r   r   r   r   '  s   S!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~   y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 )NrK   z%s%diuzInvalid integer data type %r.)	r   rn   ro   rp   kindr}   r~   rk   rc   )r3   Zint_typer   r   r   r5     s    

ziinfo.__init__c             C   s\   | j dkrdS y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_valsrk   KeyErrorr+   r~   )r3   valr   r   r   r     s    
z	iinfo.minc             C   sj   y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_valsrk   r   r   r+   r~   )r3   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
---------------------------------------------------------------
)rn   r   r   )rn   r   r   )r3   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   r6   r   r   rn   )r3   r   r   r   r   2  s    ziinfo.__repr__N)r6   r7   r8   r9   r   r   r5   propertyr   r   r   r   r   r   r   r   r     s   0)-r9   __all__rf   r>   r   Z	overridesr    r   r   rZ   r	   r
   r   r   r   r   r   r   Zcsingler;   Zcomplex_Zfloat_Z
clongfloatZ	longfloatrt   Z
_title_fmtr:   dictZint64rh   Zint32r\   Zlonglongr<   Zint16r"   r=   r?   r[   r_   rl   rj   r   r   r   r   r   r   <module>   sT    / '