HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/numpy/lib/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/numpy/lib/__pycache__/utils.cpython-36.pyc
3

���hS�@s�ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
mZddlm
Z
mZmZddlZddlmZmZdddd	d
ddd
ddddgZdd�Zdd�ZGdd�d�Zdd�Zdd	�Zdd�Zdd�Zd3dd�Zdd�Zdada d4d!d"�Z!ej"fd#d$�Z#ed �dd%ej"d fd&d��Z$ed �ej"fd'd
��Z%iZ&ej'd(ej(�Z)ed �d5d+d��Z*d,d-�Z+d.d/�Z,d0d�Z-d1d2�Z.dS)6�N)�issubclass_�issubsctype�
issubdtype)�
set_module)�ndarray�ufunc�asarray)�
getargspec�
formatargspecrrr�	deprecate�deprecate_with_doc�get_include�info�source�who�lookfor�byte_bounds�	safe_evalcCsTddl}|jdkr.tjjtjj|j�dd�}n"ddlj}tjjtjj|j�d�}|S)a�
    Return the directory that contains the NumPy \*.h header files.

    Extension modules that need to compile against NumPy should use this
    function to locate the appropriate include directory.

    Notes
    -----
    When using ``distutils``, for example in ``setup.py``.
    ::

        import numpy as np
        ...
        Extension('extension_name', ...
                include_dirs=[np.get_include()])
        ...

    rN�core�include)	�numpyZshow_config�os�path�join�dirname�__file__�
numpy.corer)r�dr�r�0/tmp/pip-build-5_djhm0z/numpy/numpy/lib/utils.pyr
s

cCs
||_|S)N)�__name__)�func�namerrr�_set_function_name4sr#c@s"eZdZdZddd�Zdd�ZdS)�
_Deprecatez�
    Decorator class to deprecate old functions.

    Refer to `deprecate` for details.

    See Also
    --------
    deprecate

    NcCs||_||_||_dS)N)�old_name�new_name�message)�selfr%r&r'rrr�__init__Esz_Deprecate.__init__cs~|j}|j}|j}|dkr@y
�j}Wntk
r>�j}YnX|dkrRd|�nd||f�|dk	rr�d|7���fdd�}t||�}�j}|dkr��}n�|j�jd�}	t	|	dd��}
|	dj
�r�|
d	|}nRt|	d�d}x4|	dd�D]$}t|�|
k�rP|t|�d7}q�W||d�}tj
�d	|
��d
j�|g�}||_y
�j}
Wntk
�rlYnX|jj|
�|S)z:
        Decorator call.  Refer to ``decorate``.

        Nz`%s` is deprecated!z%`%s` is deprecated, use `%s` instead!�
cstj�tdd��||�S)z1`arrayrange` is deprecated, use `arange` instead!�)�
stacklevel)�warnings�warn�DeprecationWarning)�args�kwds)�depdocr!rr�newfuncasz$_Deprecate.__call__.<locals>.newfunc�r� z

)r%r&r'r �AttributeErrorr#�__doc__�
expandtabs�split�_get_indent�lstrip�len�textwrap�indentr�__dict__�update)r(r!r0�kwargsr%r&r'r3�doc�linesr>�skip�linerr)r2r!r�__call__JsL




z_Deprecate.__call__)NNN)r �
__module__�__qualname__r7r)rFrrrrr$9s

r$cCsHtj}x.|D]&}t|j��}|rt|t|�|�}qW|tjkrDd}|S)zU
    Determines the leading whitespace that could be removed from all the lines.
    r)�sys�maxsizer<r;�min)rCr>rE�contentrrrr:�s

r:cOs4|r&|d}|dd�}t||�|�St||�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.

    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.deprecate(np.uint)
    DeprecationWarning: `uint64` is deprecated! # may vary
    >>> olduint(6)
    6

    rr4N)r$)r0rA�fnrrrr�s
,cCs
t|d�S)N)r')r$)�msgrrr�<lambda>�srOc
Cs�|j}|dd}|d}|d}t|�jj}|}}|dkrN||j|7}nJx@t||�D]2\}}	|	dkr|||d|	7}qZ||d|	7}qZW||7}||fS)a#
    Returns pointers to the end-points of an array.

    Parameters
    ----------
    a : ndarray
        Input array. It must conform to the Python-side of the array
        interface.

    Returns
    -------
    (low, high) : tuple of 2 integers
        The first integer is the first byte of the array, the second
        integer is just past the last byte of the array.  If `a` is not
        contiguous it will not use every byte between the (`low`, `high`)
        values.

    Examples
    --------
    >>> I = np.eye(2, dtype='f'); I.dtype
    dtype('float32')
    >>> low, high = np.byte_bounds(I)
    >>> high - low == I.size*I.itemsize
    True
    >>> I = np.eye(2); I.dtype
    dtype('float64')
    >>> low, high = np.byte_bounds(I)
    >>> high - low == I.size*I.itemsize
    True

    �datar�strides�shapeNr4)Z__array_interface__r�dtype�itemsize�size�zip)
�aZaiZa_dataZastridesZashapeZbytes_aZa_lowZa_highrRZstriderrrr�s c
CsP|dkrtj�j}|j}g}i}x�|j�D]�}t||t�r*||}t|�}||j�krn|d||}d}n|||<|}d}djt	t
|j��}	t
|j�}
|j
||	|
|jj|g�q*Wd}d}d}
d}x�tt|��D]|}||}|t|d�kr�t|d�}|t|d�k�rt|d�}|
t|d�k�r8t|d�}
|dr�|t|d�7}q�Wt|�dk�r�td|�}td|�}td|
�}d	|d
|d
|d
f}t|ddt|�d
d�x�tt|��D]t}||}td|dd
|t|d�d|dd
|t|d�d
|dd
|t|d�d
|df��q�Wtd|�dS)a%
    Print the NumPy arrays in the given dictionary.

    If there is no dictionary passed in or `vardict` is None then returns
    NumPy arrays in the globals() dictionary (all NumPy arrays in the
    namespace).

    Parameters
    ----------
    vardict : dict, optional
        A dictionary possibly containing ndarrays.  Default is globals().

    Returns
    -------
    out : None
        Returns 'None'.

    Notes
    -----
    Prints out the name, shape, bytes and type of all of the ndarrays
    present in `vardict`.

    Examples
    --------
    >>> a = np.arange(10)
    >>> b = np.ones(20)
    >>> np.who()
    Name            Shape            Bytes            Type
    ===========================================================
    a               10               80               int64
    b               20               160              float64
    Upper bound on total bytes  =       240

    >>> d = {'x': np.arange(2.0), 'y': np.arange(3.0), 'txt': 'Some str',
    ... 'idx':5}
    >>> np.who(d)
    Name            Shape            Bytes            Type
    ===========================================================
    x               2                16               float64
    y               3                24               float64
    Upper bound on total bytes  =       40

    Nz (%s)rr4z x r+��
zName %s Shape %s Bytes %s Typer5r*�=�z%s %s %s %s %s %s %s�z'
Upper bound on total bytes  =       %d)rI�	_getframe�f_back�	f_globals�keys�
isinstancer�idr�map�strrR�nbytes�appendrSr"�ranger<�int�max�print)�vardict�frameZsta�cacher"�varZidv�namestr�originalZshapestrZbytestrZmaxnameZmaxshapeZmaxbyteZ
totalbytes�k�valZsp1Zsp2Zsp3Zprvalrrrrs^,




  c
Cs�t|�}|}|}d}|j|�}xp|D]h}||kr6d}	n|}	|t|�t|	�}||kr�|dt|�}|dd|d|}q$||	|}q$W|S)Nz, �r4z,
r5r+)r<r9)
r"�	arguments�widthZ
firstwidthrqZnewstrZsepstr�arglistZargumentZaddstrrrr�_split_lineps

rwrcCs�t|t�t�g�}|j|ji}|jg}|jg}xvt|�dkr>P|jd�}xX|j�D]L}t||t	j
�rR||j}||krR||j}|j|�|j|�|||<qRWq0W||fS)Nr)�
__import__�globals�localsr r?r<�popr`ra�types�
ModuleTyperf)�moduleZthedictZdictlistZ
totraverseZthisdict�x�modnameZmoddictrrr�
_makenamedict�s"




r�c
Csxd}d}dd�}t|dt|��}t|d|�}|j}|jj}td||d�td|j|d�td	||d�td
|j|d�td||jj	�|d�td||jj
�|d�td
|jj|d�tdt|j
jj�|f|d�tdd|d�|dk�rtd|tj|f|d�d}	nH|dk�r2td||f|d�tjdk}	ntd||f|d�tjdk}	td||	�|d�td|j|d�dS)aOProvide information about ndarray obj.

    Parameters
    ----------
    obj : ndarray
        Must be ndarray, not checked.
    output
        Where printed output goes.

    Notes
    -----
    Copied over from the numarray module prior to its removal.
    Adapted somewhat as only numpy is an option now.

    Called by info.

    rscSs|S)Nr)rrrrrO�sz_info.<locals>.<lambda>�	__class__r zclass: )�filezshape: z	strides: z
itemsize: z	aligned: zcontiguous: z	fortran: zdata pointer: %s%szbyteorder: r5)�endr��|rZz%s%s%sF�>z%sbig%s�bigz
%slittle%s�littlez
byteswap: ztype: %sN)r�rZ)�getattr�typerQrS�	byteorderrjrRrT�flagsZaligned�
contiguousZfortran�hex�ctypesZ_as_parameter_�valuerI)
�obj�output�extraZticZbp�cls�nmrQZendianZbyteswaprrr�_info�s8


r��Lc
Cs*ddl}ddl}t|d�s$t|d�r,|j}nt|d�r<|j}|dkrPtt��n�t|t�rjt||d��n�t|t	��rTt
dkr�t|�\a
ad}g}x�tD]�}ylt
||}	t
|	�|kr�td||d�n6|jt
|	��td	||d�t|	�td
||d�|d7}Wq�tk
�rYq�Xq�W|dk�r@td||d�ntd
||d��n�|j|��r�|j}
tt|��}t|
|�|k�r�t|
||�}n|
|}td|d|d�t|j|�|d��nb|j|��rX|j}
d}yZt|d��r2tt|jj��}|jd�}
t|
�dk�r2d|
d|
d<dj|
dd��}Wntk
�rJYnXt|
|�|k�rlt|
||�}n|
|}td|d|d�|j|�}|dk�r�t|d��r�t|j|j�|d�nt|j|�|d�|j|�}|gk�r&td|d�xd|D]\}|ddk�r�q�t||d�}|dk	�r<|j |j|��p4d�\}}td||f|d��q�Wn�|j!|��r|j}
tt|j��}|jd�}
t|
�dk�r�d|
d|
d<dj|
dd��}nd}t|
|�|k�r�t|
||�}n|
|}td|d|d�t|j|�|d�nt|d��r&t|j|�|d�dS)a�
    Get help information for a function, class, or module.

    Parameters
    ----------
    object : object or str, optional
        Input object or name to get information about. 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
        ``stdout``.  The object has to be opened in 'w' or 'a' mode.
    toplevel : str, optional
        Start search at this level.

    See Also
    --------
    source, lookfor

    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. ***

    rNZ_ppimport_importer�_ppimport_module�_ppimport_attr)r�z+
     *** Repeat reference found in %s *** )r�z     *** Found in %s ***�-r4zHelp for %s not found.z+
     *** Total of %d references found. ***r5r*z()r)z, �(z

Methods:
�_�Nonez  %s  --  %sr7)"�pydoc�inspect�hasattrr�r�rrarr�rd�	_namedictr��	_dictlistrbrjrf�KeyErrorZ
isfunctionr r
r	r<rw�getdoc�isclassr)�__func__r9r�	ExceptionZ
allmethodsr�ZsplitdocZismethod)�objectZmaxwidthr��toplevelr�r�ZnumfoundZobjlistror�r"rtZargstrrvZdoc1�methods�methZthisobjZmethstr�otherrrrr�s�4















cCsZddl}y,td|j|�|d�t|j|�|d�Wn tk
rTtd|d�YnXdS)a�
    Print or write to a file the source code for a NumPy object.

    The source code is only returned for objects written in Python. Many
    functions and classes are defined in C and will therefore not return
    useful information.

    Parameters
    ----------
    object : numpy object
        Input object. This can be any object (function, class, module,
        ...).
    output : file object, optional
        If `output` not supplied then source code is printed to screen
        (sys.stdout).  File object must be created with either write 'w' or
        append 'a' modes.

    See Also
    --------
    lookfor, info

    Examples
    --------
    >>> np.source(np.interp)                        #doctest: +SKIP
    In file: /usr/lib/python2.6/dist-packages/numpy/lib/function_base.py
    def interp(x, xp, fp, left=None, right=None):
        """.... (full docstring printed)"""
        if isinstance(x, (float, int, number)):
            return compiled_interp([x], xp, fp, left, right).item()
        else:
            return compiled_interp(x, xp, fp, left, right)

    The source code is only returned for objects written in Python.

    >>> np.source(np.array)                         #doctest: +SKIP
    Not available for this object.

    rNzIn file: %s
)r�zNot available for this object.)r�rjZ
getsourcefileZ	getsourcer�)r�r�r�rrrrzs)z[a-z0-9_]+\(.*[,=].*\)TFc
s�ddl}t|||��g}t|�j�j���s0dSxL�j�D]@\}\}}	}
|	dkrRq:|j��t�fdd��D��r:|j|�q:Wddddd����fd	d
����fdd�}|j|d
�ddj	��}|dt
|�g}
x�|ddd�D]�}�|\�}	}dd��j�jd�D�}y(|dj�}tj
|��r2|dj�}Wntk
�rNd}YnX|
jd||f�q�W|�sv|
jd�|dk	�r�|jdj	|
��n4t
|
�dk�r�|j�}|dj	|
��ntdj	|
��dS)a�
    Do a keyword search on docstrings.

    A list of objects that matched the search is displayed,
    sorted by relevance. All given keywords need to be found in the
    docstring for it to be returned as a result, but the order does
    not matter.

    Parameters
    ----------
    what : str
        String containing words to look for.
    module : str or list, optional
        Name of module(s) whose docstrings to go through.
    import_modules : bool, optional
        Whether to import sub-modules in packages. Default is True.
    regenerate : bool, optional
        Whether to re-generate the docstring cache. Default is False.
    output : file-like, optional
        File-like object to write the output to. If omitted, use a pager.

    See Also
    --------
    source, info

    Notes
    -----
    Relevance is determined only roughly, by checking if the keywords occur
    in the function name, at the start of a docstring, etc.

    Examples
    --------
    >>> np.lookfor('binary representation') # doctest: +SKIP
    Search results for 'binary representation'
    ------------------------------------------
    numpy.binary_repr
        Return the binary representation of the input number as a string.
    numpy.core.setup_common.long_double_representation
        Given a binary dump as given by GNU od -b, look for long double
    numpy.base_repr
        Return a string representation of a number in the given base system.
    ...

    rNr~r�c3s|]}|�kVqdS)Nr)�.0�w)rBrr�	<genexpr>�szlookfor.<locals>.<genexpr>i�)r!�classr~r�cs�d}dj|j�j�jd�dd���|t�fdd��D��7}|t�fdd��D��7}|t��d7}|�j|d�7}|�jd	�d
7}|t|dd
�7}|S)Nrr*r\csg|]}|�krd�qS)��r)r�r�)�	first_docrr�
<listcomp>sz.lookfor.<locals>.relevance.<locals>.<listcomp>csg|]}|�krd�qS)�r)r�r�)r"rrr�sr[i��.rY�di���i����)	r�lower�stripr9�sumr<�get�countri)r"Zdocstr�kind�index�r)�kind_relevance�whats)r�r"r�	relevance�s zlookfor.<locals>.relevancecs�|f�|��S)Nr)rW)rmr�rr�relevance_valuesz lookfor.<locals>.relevance_value)�keyzSearch results for '%s'r5r�r4cSsg|]}|j�r|j��qSr)r�)r�rErrrr�szlookfor.<locals>.<listcomp>r*rsz	%s
    %szNothing found.rY)r~r�i���i������)r��_lookfor_generate_cacherdr�r9�items�allrf�sortrr<r��_function_signature_re�search�
IndexError�writeZgetpagerrj)�whatr~�import_modules�
regenerater�r��foundr"Z	docstringr�r�r��s�	help_text�ixZdoclinesr�Zpagerr)rmrBr�r�r�rr�sJ/



c#Cs�ddl}ddlm}|dkr d}t|t�rXyt|�Wntk
rJiSXtj|}n<t|t	�slt|t
�r�i}x|D]}|jt|||��qvW|St
|�tkr�|r�tt
|�Si}|tt
|�<i}d}|j|fg}	�x�|	�r�|	jd�\}
}t
|�|k�r�q�d|t
|�<|d7}d}|j|��r2d}y
|j}
Wntk
�rJd}
YnX|�rRt|d	��rRx�|jD]�}x�tj|�D]�}tjj||�}tjj||d
�}tjj|��r�|jd��r�|dd�}ntjj|��rv|}n�qv|d
k�r�qvyDtj}tj}z$|�t_|�t_td|
|f�Wd|t_|t_XWntk
�rD�wvYnX�qvW�qfWx�t|�D]�\}}y$t |dd|
|f�}t |dd�}Wn&t!k
�r�d|
|f}d}YnXd|k�r�|�r�d||f}|j"|
d��s�t|t#��r\n�q\n$|j|��p|
dk�p||
k�s�q\|	j$d|
|f|f��q\WnP|j%|��rrd}x>t|�D] \}}|	j$d|
|f|f��qLWnt|d��r�d}y|j&|�}Wnt!k
�r�d}YnX|dk	r�|||f||
<q�W|S)a�
    Generate docstring cache for given module.

    Parameters
    ----------
    module : str, None, module
        Module for which to generate docstring cache
    import_modules : bool
        Whether to import sub-modules in packages.
    regenerate : bool
        Re-generate the docstring cache

    Returns
    -------
    cache : dict {obj_full_name: (docstring, kind, index), ...}
        Docstring cache for the module, either cached one (regenerate=False)
        or newly generated.

    rN)�StringIOrTr4r�r~�__path__z__init__.pyz.pyr\r)z%s.%sr rGr�r�rFr!���)'r��ior�rardrx�ImportErrorrI�modules�list�tupler@r�rb�_lookfor_cachesr r{Zismodule�__all__r6r�r�r�listdirrr�isfile�endswith�stdout�stderr�
BaseException�_getmembersr��	NameError�
startswithrrfr�r�)r~r�r�r�r�rm�mod�seenr��stackr"�itemr�Z_all�pthZmod_pathZthis_pyZinit_pyZ	to_importZ
old_stdoutZ
old_stderr�n�vZ	item_name�mod_namerBrrrr�1s�







 
r�csFddl}y|j��}Wn*tk
r@�fdd�t��D�}YnX|S)Nrcs$g|]}t�|�r|t�|�f�qSr)r�r�)r�r)r�rrr��sz_getmembers.<locals>.<listcomp>)r��
getmembersr��dir)r�r��membersr)r�rr��sr�cCsddl}|j|�S)a�
    Protected string evaluation.

    Evaluate a string containing a Python literal expression without
    allowing the execution of arbitrary non-literal code.

    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...>

    rN)�astZliteral_eval)rr�rrrr�s,cCs�|jdkr|Stj||d�}tj|d	�}tjj|�r@|jd�}|jdkr�|dkr�|dk	rr|jj	tj
�|d<|}q�|jj	tj
�}ntj|j��dkr�tj
||<|S)
aj
    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
        Input data to median function
    result : Array or MaskedArray
        Result of median function
    axis : {int, sequence of int, None}, optional
        Axis or axes along which the median was computed.
    out : ndarray, optional
        Output array in which to place the result.
    Returns
    -------
    median : scalar or ndarray
        Median or NaN in axes which contained NaN in the input.
    rr4.FTNr�r�).r�)
rU�npZmoveaxis�isnan�maZ
isMaskedArrayZfilled�ndimrSr��nanZ
count_nonzeroZravel)rP�resultZaxis�outr�rrr�_median_nancheck�s



r�)N)r)NTFN)/rrIr=r|�rer-Znumpy.core.numerictypesrrrZnumpy.core.overridesrrrrrrr�Znumpy.compatr	r
r�r
r#r$r:rrrrrwr�r�r�r�r�rrr��compile�Ir�rr�r�rr�rrrr�<module>sR

L49
i
3+3z
0