a :jg[@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl Z gdZe dddZe ddd ZGd d d Zd d ZddZddZddZdadad#ddZd$ddZe dd%ddZddZddZdd Zd!d"ZdS)&N)ndarray) set_module) get_includeinfo show_runtimenumpyc Csddlm}m}m}ddlm}tjtjt dg}gg}}|D]"}||r\| |qD| |qD| d|||dizddl m }||WntytdYn0||d S) a( Print information about various resources in the system including available intrinsic support and BLAS/LAPACK library in use .. versionadded:: 1.24.0 See Also -------- show_config : Show libraries in the system on which NumPy was built. Notes ----- 1. Information is derived with the help of `threadpoolctl `_ library if available. 2. SIMD related information is derived from ``__cpu_features__``, ``__cpu_baseline__`` and ``__cpu_dispatch__`` r__cpu_features____cpu_baseline____cpu_dispatch__)pprint)Z numpy_versionpythonunameZsimd_extensions)Zbaselinefound not_found)threadpool_infozWARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build informationN)numpy._core._multiarray_umathr r r r np __version__sysversionplatformrappendZ threadpoolctlrextend ImportErrorprint) r r r r Z config_foundZfeatures_foundZfeatures_not_foundfeaturerr?/usr/local/lib/python3.9/site-packages/numpy/lib/_utils_impl.pyrs0      rcCsVddl}|jdur.tjtj|jdd}n$ddlm}tjtj|jd}|S)aX Return the directory that contains the NumPy \*.h header files. Extension modules that need to compile against NumPy may need to use this function to locate the appropriate include directory. Notes ----- When using ``setuptools``, for example in ``setup.py``:: import numpy as np ... Extension('extension_name', ... include_dirs=[np.get_include()]) ... Note that a CLI tool ``numpy-config`` was introduced in NumPy 2.0, using that is likely preferred for build systems other than ``setuptools``:: $ numpy-config --cflags -I/path/to/site-packages/numpy/_core/include # Or rely on pkg-config: $ export PKG_CONFIG_PATH=$(numpy-config --pkgconfigdir) $ pkg-config --cflags -I/path/to/site-packages/numpy/_core/include rN_coreinclude) rZ show_configospathjoindirname__file__ numpy._corer)rdrrrrrIs   rc@s"eZdZdZdddZddZdS) _Deprecatez Decorator class to deprecate old functions. Refer to `deprecate` for details. See Also -------- deprecate NcCs||_||_||_dSN)old_namenew_namemessage)selfr*r+r,rrr__init__~sz_Deprecate.__init__c s2|j}|j}|j}|dur j}|dur2d|n d||f|durRd|7tfdd}||_j}|dur}n|d} t | dd} | d r| d |}nNt | dd} | ddD]$} t | | krq| t | d7} q|| d}t d | d |g}||_|S) z: Decorator call. Refer to ``decorate``. Nz`%s` is deprecated!z%`%s` is deprecated, use `%s` instead! cstjtdd|i|S)N stacklevel)warningswarnDeprecationWarning)argskwdsZdepdocfuncrrnewfuncsz$_Deprecate.__call__..newfuncr z )r*r+r,__name__ functoolswraps__doc__ expandtabssplit _get_indentlstriplentextwrapindentr#) r-r9r6kwargsr*r+r,r:doclinesrGskiplinerr8r__call__s@     z_Deprecate.__call__)NNN)r= __module__ __qualname__r@r.rMrrrrr(rs r(cCsDtj}|D]&}t|}|r t|t||}q |tjkr@d}|S)zU Determines the leading whitespace that could be removed from all the lines. r)rmaxsizerErDmin)rJrGrLcontentrrrrCs  rCcOsLtjdtdd|r:|d}|dd}t|i||St|i|SdS)a Issues a DeprecationWarning, adds warning to `old_name`'s docstring, rebinds ``old_name.__name__`` and returns the new function object. This function may also be used as a decorator. .. deprecated:: 2.0 Use `~warnings.warn` with :exc:`DeprecationWarning` instead. Parameters ---------- func : function The function to be deprecated. old_name : str, optional The name of the function to be deprecated. Default is None, in which case the name of `func` is used. new_name : str, optional The new name for the function. Default is None, in which case the deprecation message is that `old_name` is deprecated. If given, the deprecation message is that `old_name` is deprecated and `new_name` should be used instead. message : str, optional Additional explanation of the deprecation. Displayed in the docstring after the warning. Returns ------- old_func : function The deprecated function. Examples -------- Note that ``olduint`` returns a value after printing Deprecation Warning: >>> olduint = np.lib.utils.deprecate(np.uint) DeprecationWarning: `uint64` is deprecated! # may vary >>> olduint(6) 6 b`deprecate` is deprecated, use `warn` with `DeprecationWarning` instead. (deprecated in NumPy 2.0)r0r1rr;Nr3r4r5r()r6rHfnrrr deprecates0 rVcCstjdtddt|dS)a Deprecates a function and includes the deprecation in its docstring. .. deprecated:: 2.0 Use `~warnings.warn` with :exc:`DeprecationWarning` instead. This function is used as a decorator. It returns an object that can be used to issue a DeprecationWarning, by passing the to-be decorated function as argument, this adds warning to the to-be decorated function's docstring and returns the new function object. See Also -------- deprecate : Decorate a function such that it issues a :exc:`DeprecationWarning` Parameters ---------- msg : str Additional explanation of the deprecation. Displayed in the docstring after the warning. Returns ------- obj : object rSr0r1)r,rT)msgrrrdeprecate_with_docs rXc Cst|}|}|}d}||}|D]h}||kr4d} n|} |t|t| }||kr~|dt|}|dd|d|}q"|| |}q"|S)Nz, r;z, r<r0)rErB) name argumentswidthZ firstwidthkZnewstrZsepstrZarglistargumentZaddstrrrr _split_line7s r_cCst|ttg}|j|ji}|jg}|jg}t|dkrwz_info.. __class__r=Nzclass: filezshape: z strides: z itemsize: z aligned: z contiguous: z fortran: zdata pointer: %s%sz byteorder: r<)endrq)|=z%s%s%sF>z%sbig%sbigz %slittle%slittlez byteswap: ztype: %s)getattrtypestridesdtype byteorderrstdoutrshapeitemsizeflagsZaligned contiguousfortranhexctypesZ_as_parameter_value) objoutputextraZticbpclsnmrzZendianbyteswaprrr_infocs>     rLc CsXddl}ddl}t|ds$t|dr,|j}nt|dr<|j}|durJtj}|dur^ttnt|t rxt ||dnt|t r\t durt |\a ad}g}tD]}zlt ||} t| |vrtd||dn6|t| td ||dt| td ||d|d 7}Wqty(Yq0q|dkrHtd ||dntd ||dn||st||r|j} zt ||} Wntyd} Yn0t| | |krt| | |} n| | } td| d|dt|||dn\||r6|j} zt ||} Wnty4d} Yn0t| | |krVt| | |} n| | } td| d|d||} | durt|drt||j|dnt|||d||}dd|D}|rTtd|d|D]J}t||d}|dur|||pd\}}td||f|dqnt|drTt|||ddS)a Get help information for an array, function, class, or module. Parameters ---------- object : object or str, optional Input object or name to get information about. If `object` is an `ndarray` instance, information about the array is printed. If `object` is a numpy object, its docstring is given. If it is a string, available modules are searched for matching objects. If None, information about `info` itself is returned. maxwidth : int, optional Printing width. output : file like object, optional File like object that the output is written to, default is ``None``, in which case ``sys.stdout`` will be used. The object has to be opened in 'w' or 'a' mode. toplevel : str, optional Start search at this level. Notes ----- When used interactively with an object, ``np.info(obj)`` is equivalent to ``help(obj)`` on the Python prompt or ``obj?`` on the IPython prompt. Examples -------- >>> np.info(np.polyval) # doctest: +SKIP polyval(p, x) Evaluate the polynomial p at x. ... When using a string for `object` it is possible to get multiple results. >>> np.info('fft') # doctest: +SKIP *** Found in numpy *** Core FFT routines ... *** Found in numpy.fft *** fft(a, n=None, axis=-1) ... *** Repeat reference found in numpy.fft.fftpack *** *** Total of 3 references found. *** When the argument is an array, information about the array is printed. >>> a = np.array([[1 + 2j, 3, -4], [-5j, 6, 0]], dtype=np.complex64) >>> np.info(a) class: ndarray shape: (2, 3) strides: (24, 8) itemsize: 8 aligned: True contiguous: True fortran: False data pointer: 0x562b6e0d2860 # may vary byteorder: little byteswap: False type: complex64 rNZ_ppimport_importer_ppimport_module_ppimport_attr)rz+ *** Repeat reference found in %s *** rpz *** Found in %s ***-r;zHelp for %s not found.z+ *** Total of %d references found. ***z()r<r/r.cSsg|]}|ddkr|qS)r_r).0methrrr -rnzinfo..z Methods: Nonez %s -- %sr@) pydocinspecthasattrrrrr}rrfrrstr _namedictrl _dictlistidrrKeyError isfunctionismethodr= signature ExceptionrEr_getdocisclassr.Z allmethodsrxZsplitdoc)objectZmaxwidthrtoplevelrrZnumfoundZobjlistZnamestrrrZr[ZargstrZdoc1methodsZpublic_methodsrZthisobjZmethstrotherrrrrsB                      rcCs"tjdtddddl}||S)a Protected string evaluation. .. deprecated:: 2.0 Use `ast.literal_eval` instead. Evaluate a string containing a Python literal expression without allowing the execution of arbitrary non-literal code. .. warning:: This function is identical to :py:meth:`ast.literal_eval` and has the same security implications. It may not always be safe to evaluate large input strings. Parameters ---------- source : str The string to evaluate. Returns ------- obj : object The result of evaluating `source`. Raises ------ SyntaxError If the code has invalid Python syntax, or if it contains non-literal code. Examples -------- >>> np.safe_eval('1') 1 >>> np.safe_eval('[1, 2, 3]') [1, 2, 3] >>> np.safe_eval('{"foo": ("bar", 10.0)}') {'foo': ('bar', 10.0)} >>> np.safe_eval('import os') Traceback (most recent call last): ... SyntaxError: invalid syntax >>> np.safe_eval('open("/home/user/.ssh/id_dsa").read()') Traceback (most recent call last): ... ValueError: malformed node or string: <_ast.Call object at 0x...> z`safe_eval` is deprecated. Use `ast.literal_eval` instead. Be aware of security implications, such as memory exhaustion based attacks (deprecated in NumPy 2.0)r0r1rN)r3r4r5ast literal_eval)sourcerrrr safe_eval<s6 rcCsl|jdkr|S|jd|d}t|}tj|r<|d}|sH|St|tj rX|Stj |||d|S)a{ Utility function to check median result from data for NaN values at the end and return NaN in that case. Input result can also be a MaskedArray. Parameters ---------- data : array Sorted input data to median function result : Array or MaskedArray Result of median function. axis : int Axis along which the median was computed. Returns ------- result : scalar or ndarray Median or NaN in axes which contained NaN in the input. If the input was an array, NaN will be inserted in-place. If a scalar, either the input itself or a scalar NaN. r)axisF)where) sizeZtakerisnanmaZ isMaskedArrayZfilledanyrfZgenericZcopyto)dataresultrZpotential_nansnrrr_median_nanchecks     rcCsrddlm}m}m}t|dkr0t|dkr0dSd|}|D].}||r\|d|d7}q>|d|d7}q>|S)a Returns a string containing the CPU features supported by the current build. The format of the string can be explained as follows: - Dispatched features supported by the running machine end with `*`. - Dispatched features not supported by the running machine end with `?`. - Remaining features represent the baseline. Returns: str: A formatted string indicating the supported CPU features. rrrYr<*?)rr r r rEr#)r r r Zenabled_featuresrrrr _opt_infos rc Cs"|jdur|jdu}g}g}g}g}|jD]d\}}t|d}||durRd}||||||d|t|dkrdn|dq.|s|St|||||jd} tj | |j dS|j dur|j \} } t| } |jdur| | ur|St | | fS|jdur|St |j SdS) a Returns the dtype unchanged if it contained no metadata or a copy of the dtype if it (or any of its structure dtypes) contained metadata. This utility is used by `np.save` and `np.savez` to drop metadata before saving. .. note:: Due to its limitation this function may move to a more appropriate home or change in the future and is considered semi-public API only. .. warning:: This function does not preserve more strange things like record dtypes and user dtypes may simply return the wrong thing. If you need to be sure about the latter, check the result with: ``np.can_cast(new_dtype, dtype, casting="no")``. NrTr;r0)namesformatsoffsetstitlesr)align) fieldsmetadataitems drop_metadatarrEdictrrr{Zisalignedstructsubdtyper) r{Zfound_metadatarrrrrZfieldZfield_dtZ structurerr~Z new_subdtyperrrrs<          r)r)N)NrNr)r!rrFrgrer3r>rr&rZ numpy._utilsrrr__all__rrr(rCrVrXr_rrrlrrrrrrrrrrs>   5 (DA2  6 #C*