a :jg,e @sjdZddgZddlZddlmZddlmZdd lmZdd lm Z dd lm Z m Z m Z dd lmZmZmZmZd dZddZGdddZe je je je je je jiZdZe jee j de!dde jee j"de!dde jee j#de!dde j$ee j%de!ddiZ&iZ'ddZ(iZ)dd Z*d!d"Z+d#d$Z,ed%Gd&ddZ-ed%Gd'ddZ.dS)(zJMachine limits for Float32 and Float64 and (long double) if available... finfoiinfoN) set_module)MachAr)numeric) numerictypes)arrayinfnan)log10exp2 nextafterisnancCs|jdkr|}d|_|S)zfix rank-0 --> rank-1r)r)ndimcopyshapear?/usr/local/lib/python3.9/site-packages/numpy/_core/getlimits.py_fr0s rcCs|jdkr|}d|_|S)zfix rank > 0 --> rank-0rr)sizerrrrrr_fr1s rc@sNeZdZdZddddZeddZedd Zd d Zd d Z ddZ dS) MachArLikez$ Object to simulate MachAr instance N)smallest_subnormalc Ks4t||_||_|jd|_|s@t|d|d|jd|_n||_|||_|_|||_ |||_ |_ |||_ |||_ |_|jd||_|j|tt|j |_||d|j |_||j|_||j |_||j |_||j |_||j|_||j |_dS)Ntitlerrdtypeitype )_MACHAR_PARAMSparamsftyperr_smallest_subnormal_float_to_floatepsilonepsepsnegZxmaxhugeZxminsmallest_normaltinyibeta__dict__updateintr 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-rkwargsrrr__init__"s2      zMachArLike.__init__cCs6|j}|d|kr,tjd|jtdd||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. rz8The value of the smallest subnormal for {} type is zero.r stacklevel)r%r$warningswarnformat UserWarningr&r;valuerrrr>szMachArLike.smallest_subnormalcCs ||jS)z;Return the string representation of the smallest subnormal.)r4rr;rrr_str_smallest_subnormalVsz"MachArLike._str_smallest_subnormalcCst||S)zConverts float to float. Parameters ---------- value : float value to be converted. )rr2rDrrrr&[szMachArLike._float_to_floatcCst|g|jS)zConverts float to conv. Parameters ---------- value : float value to be converted. )r r$rDrrrr2eszMachArLike._float_convcCs|jdtt|d|jS)zConverts float to str. Parameters ---------- value : float value to be converted. fmtr)r#r rr$rDrrrr4oszMachArLike._float_to_str) __name__ __module__ __qualname____doc__r=propertyrrGr&r2r4rrrrr s     rz(numpy {} precision floating point numberz%24.16edouble)r rHrz%15.7esinglez%sz long doublez%12.5ehalfcCs |t|<dSN) _KNOWN_TYPES)macharZbytepatrrr_register_typesrTcCstj}t|dddddddddt|dt|d|d |d d }t|d |td<tj}t|d ddddddddt|d t|d|dddt|dd }t|d|td<tj}d}d}t|dddddddddd|d|||d |d }t|d!|td"<tj}t|d#} t|d$} t j d%d&(|d'| | |d } Wdn1sb0Yt|d(d#d$d)d*d+dddt|d(| | | d } t| d,| td<t|d-} t|d$}t j d%d&(|d'| ||d }Wdn1s0Yt|d.d-d$d)d/d+dddt|d.| ||d }t|d0|td1<t |t |d|d2}t }|t d3d}t|d4d5ddd6ddddt|d4t|d5|||d7}t|d8t|d9|td:<dS);Niiir!rrig?) machepnegepminexpmaxexpitiexpr-irndngrdr(r)r*r,sfiiig?s̽ gbz_get_machar..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!rr>)r"get ValueErrorreprviewrZ newbyteordertobytesrorrrRrvitemsr@rArC_discovered_machar)r$r#keyZma_likeZ_ktrrr _get_machar5s(    rcs>ttfddfddfddfdddS)z Create MachAr instance with found information on float types TODO: MachAr should be retired completely ideally. We currently only ever use it system with broken longdouble (valgrind, WSL). cs t|gSrQ)r ryr$rrvr{z$_discovered_machar..cst|ddS)Nr r)rZastyper)r#rrrwr{cstt|dS)Nrr rrrrrrxr{csdtt|dS)NrHrrrr$r#rrryr{r)r"rrrrrros    rnumpyc@sLeZdZdZiZddZddZddZdd Ze d d Z e d d Z dS)ra finfo(dtype) Machine limits for floating point types. Attributes ---------- bits : int The number of bits occupied by the type. dtype : dtype Returns the dtype for which `finfo` returns information. For complex input, the returned dtype is the associated ``float*`` dtype for its real and complex components. 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. 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 or complex floating point data-type about which to get information. See Also -------- 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]_. This function can also be used for complex data types as well. If used, the output will be the same as the corresponding real float type (e.g. numpy.finfo(numpy.csingle) is the same as numpy.finfo(numpy.single)). However, the output is true for the real and imaginary components. References ---------- .. [1] IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2008, pp.1-70, 2008, https://doi.org/10.1109/IEEESTD.2008.4610935 .. [2] Wikipedia, "Denormal Numbers", https://en.wikipedia.org/wiki/Denormal_number Examples -------- >>> np.finfo(np.float64).dtype dtype('float64') >>> np.finfo(np.complex64).dtype dtype('float32') cCsrz|j|}|dur|WSWnty0Yn0|durJtjdtddzt|}Wn tyxtt|}Yn0|j|}|dur|S|g}t |}||ur| ||}t |tj std||j|}|dur|St |tjsHt|}||urH| ||}|j|d}|durH|D]}||j|<q2|St||}|D]}||j|<q\|S)Nzifinfo() dtype cannot be None. This behavior will raise an error in the future. (Deprecated in NumPy 1.25)rr>zdata type %r not inexact) _finfo_cacher| TypeErrorr@rADeprecationWarningrrtyperoZ obj2sctypeappend issubclassZinexactr}Zfloating_convert_to_floatobject__new___init)clsrobjZdtypesZnewdtypedtrrrrsV             z finfo.__new__cCst||_t|}dD]}t||t||qdD]}t||t||jdq4|jjd|_|jjd|_ |j |_ |j jd|_ |j |_ |j|_||_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|S)N)r1r\rZrYrXrW)r3r)rrra)rrrsetattrgetattrflatitemsizebitsr*maxminr(r\Znexpr[Znmant_macharr7stripZ _str_tinyr8Z_str_maxr6r5r9r:rG)r;rrSwordrrrrs*         z finfo._initcCsd}||jS)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;rHrrr__str__9s z finfo.__str__cCs"|jj}|j}||d<d|S)NklasszZ%(klass)s(resolution=%(resolution)s, min=-%(_str_max)s, max=%(_str_max)s, dtype=%(dtype)s)) __class__rIr.r)r;cdrrr__repr__Is  zfinfo.__repr__cCs0t|jjjdr"tjdtdd|jjjdS)a7Return 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. rz;The value of smallest normal is undefined for double doublerr>)rrr+rr@rArCrFrrrr+Ps zfinfo.smallest_normalcCs|jS)aQReturn 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+rFrrrr,gsz finfo.tinyN) rIrJrKrLrrrrrrMr+r,rrrrr}sf8 c@sHeZdZdZiZiZddZeddZeddZ dd Z d d Z d S) ra iinfo(type) Machine limits for integer types. Attributes ---------- bits : int The number of bits occupied by the type. dtype : dtype Returns the dtype for which `iinfo` returns information. 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 cCs|zt||_Wn"ty2tt||_Yn0|jj|_|jjd|_d|j|jf|_|jdvrxtd|jfdS)Nraz%s%diuzInvalid integer data type %r.) rrrrkindrrrr})r;Zint_typerrrr=s   ziinfo.__init__cCsZ|jdkrdSztj|j}Wn2tyPtd|jd> }|tj|j<Yn0|SdS)zMinimum value of given dtype.urrN)rr _min_valsrKeyErrorr0rr;valrrrrs  z iinfo.mincCshztj|j}WnRtyb|jdkrd}ntd|jd>d}|tj|j<Yn0|S)zMaximum value of given dtype.rr)r _max_valsrrrr0rrrrrrs  z iinfo.maxcCsd}||j|j|jdS)zString representation.zMachine parameters for %(dtype)s --------------------------------------------------------------- min = %(min)s max = %(max)s --------------------------------------------------------------- rrrrrrrrrsz iinfo.__str__cCsd|jj|j|j|jfS)Nz%s(min=%s, max=%s, dtype=%s))rrIrrrrFrrrrs ziinfo.__repr__N) rIrJrKrLrrr=rMrrrrrrrrrys2    )/rL__all__r@Z_utilsrrrrr ror r r Zumathr rrrrrrZcsinglerOZ complex128rqZ clongdoublerrrZ _title_fmtrNdictZint64rBZint32ZlonglongrPZint16r"rRrTrprtrrrrrrrrsb    [:|