3
­?d]�  ã               @   s   d dl mZmZmZ d dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZ d dlmZ d dlmZmZmZ d dlZd dlmZmZ ddd	d
ddddddddgZdd„ Zdd„ ZG dd„ deƒZdd„ Zdd
„ Zdd„ Zdd„ Z d6dd„Z!dd „ Z"da#da$d7d"d#„Z%ej&fd$d%„Z'ed!ƒdd&ej&d!fd'd„ƒZ(ed!ƒej&fd(d„ƒZ)i a*ej+d)ej,ƒZ-ed!ƒd8d,d„ƒZ.d-d.„ Z/d/d0„ Z0G d1d2„ d2eƒZ1d3d„ Z2d4d5„ Z3dS )9é    )ÚdivisionÚabsolute_importÚprint_functionN)Úissubclass_ÚissubsctypeÚ
issubdtype)Ú
set_module)ÚndarrayÚufuncÚasarray)Ú
getargspecÚformatargspecr   r   r   Ú	deprecateÚdeprecate_with_docÚget_includeÚinfoÚsourceÚwhoÚlookforÚbyte_boundsÚ	safe_evalc              C   sT   ddl } | jdkr.tjjtjj| jƒddƒ}n"ddlj}tjjtjj|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()])
        ...

    r   NÚcoreÚinclude)	ÚnumpyZshow_configÚosÚpathÚjoinÚdirnameÚ__file__Ú
numpy.corer   )r   Údr   © r!   ú0/tmp/pip-build-op5p2y5_/numpy/numpy/lib/utils.pyr      s    

c             C   s
   || _ | S )N)Ú__name__)ÚfuncÚnamer!   r!   r"   Ú_set_function_name5   s    r&   c               @   s"   e Zd ZdZddd„Zdd„ ZdS )Ú
_Deprecatez†
    Decorator class to deprecate old functions.

    Refer to `deprecate` for details.

    See Also
    --------
    deprecate

    Nc             C   s   || _ || _|| _d S )N)Úold_nameÚnew_nameÚmessage)Úselfr(   r)   r*   r!   r!   r"   Ú__init__F   s    z_Deprecate.__init__c                sn  | j }| j}| j}|dkr@y
ˆj}W n tk
r>   ˆj}Y nX |dkrRd| ‰ nd||f ‰ |dk	rrˆ d| 7 ‰ ‡ ‡fdd„}t||ƒ}ˆj}|dkržˆ }n˜|jƒ jdƒ}	t	|	dd… ƒ}
|	d j
ƒ rÖ|
d	 | }nRt|	d ƒd }x4|	dd… D ]$}t|ƒ|
k�rP |t|ƒd 7 }qôW ||d… }d
jˆ |gƒ}||_y
ˆj}W n tk
�r\   Y nX |jj|ƒ |S )z:
        Decorator call.  Refer to ``decorate``.

        Nz`%s` is deprecated!z%`%s` is deprecated, use `%s` instead!Ú
c                 s   t jˆ tdd� ˆ| |ŽS )z1`arrayrange` is deprecated, use `arange` instead!é   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarning)ÚargsÚkwds)Údepdocr$   r!   r"   Únewfuncb   s    z$_Deprecate.__call__.<locals>.newfuncé   r   ú z

)r(   r)   r*   r#   ÚAttributeErrorr&   Ú__doc__Ú
expandtabsÚsplitÚ_get_indentÚlstripÚlenr   Ú__dict__Úupdate)r+   r$   r3   Úkwargsr(   r)   r*   r6   ÚdocÚlinesÚindentÚskipÚliner    r!   )r5   r$   r"   Ú__call__K   sJ    




z_Deprecate.__call__)NNN)r#   Ú
__module__Ú__qualname__r:   r,   rH   r!   r!   r!   r"   r'   :   s   

r'   c             C   sH   t j}x.| D ]&}t|jƒ ƒ}|rt|t|ƒ| ƒ}qW |t jkrDd}|S )zU
    Determines the leading whitespace that could be removed from all the lines.
    r   )ÚsysÚmaxsizer?   r>   Úmin)rD   rE   rG   Úcontentr!   r!   r"   r=   …   s    

r=   c              O   s4   | r&| d }| dd… } t | |Ž|ƒS t | |ŽS dS )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

    r   r7   N)r'   )r3   rB   Úfnr!   r!   r"   r   “   s
    ,c             C   s
   t | d�S )N)r*   )r'   )Úmsgr!   r!   r"   Ú<lambda>Ç   s    rQ   c       
      C   s    | j }|d d }|d }|d }t| ƒjj}| }}|dkrN|| j| 7 }nJx@t||ƒD ]2\}}	|	dk r|||d |	 7 }qZ||d |	 7 }qZW ||7 }||fS )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ÚshapeNr7   )Z__array_interface__r   ÚdtypeÚitemsizeÚsizeÚzip)
ÚaZaiZa_dataZastridesZashapeZbytes_aZa_lowZa_highrT   Zstrider!   r!   r"   r   Î   s     c             C   sP  | dkrt jƒ j}|j} g }i }x”| jƒ D ]ˆ}t| | tƒr*| | }t|ƒ}||jƒ krn|d||   }d}n|||< |}d}djt	t
|jƒƒ}	t
|jƒ}
|j||	|
|jj|gƒ q*W d}d}d}d}xŒtt|ƒƒD ]|}|| }|t|d ƒk rüt|d ƒ}|t|d ƒk �rt|d ƒ}|t|d ƒk �r8t|d ƒ}|d rÔ|t|d ƒ7 }qÔW t|ƒdk�rºtd|ƒ}td|ƒ}td|ƒ}d	|d
 |d
 |d
 f }t|d dt|ƒd   d ƒ x„tt|ƒƒD ]t}|| }td|d d
|t|d ƒ d  |d d
|t|d ƒ d  |d d
|t|d ƒ d  |d f ƒ �qÈW td| ƒ dS )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)r   r7   z x r.   é   é
   zName %s Shape %s Bytes %s Typer8   r-   ú=é   z%s %s %s %s %s %s %sé   z'
Upper bound on total bytes  =       %d)rK   Ú	_getframeÚf_backÚ	f_globalsÚkeysÚ
isinstancer	   Úidr   ÚmapÚstrrT   ÚnbytesÚappendrU   r%   Úranger?   ÚintÚmaxÚprint)ÚvardictÚframeZstaÚcacher%   ÚvarZidvÚnamestrÚoriginalZshapestrZbytestrZmaxnameZmaxshapeZmaxbyteZ
totalbytesÚkÚvalZsp1Zsp2Zsp3Zprvalr!   r!   r"   r     s^    ,




  c       
      C   s”   t | ƒ}|}| }d}|j|ƒ}xp|D ]h}||kr6d}	n|}	|t |ƒ t |	ƒ }||kr€|d t |ƒ }|d d|d   | }q$||	 | }q$W |S )Nz, Ú r7   z,
r8   r.   )r?   r<   )
r%   Ú	argumentsÚwidthZ
firstwidthrs   ZnewstrZsepstrÚarglistÚargumentZaddstrr!   r!   r"   Ú_split_linep  s    

rz   r   c             C   s®   t | tƒ tƒ g ƒ} | j| ji}| jg}| jg}xvt|ƒdkr>P |jdƒ}xX|jƒ D ]L}t|| t	j
ƒrR|| j}||krR|| j}|j|ƒ |j|ƒ |||< qRW q0W ||fS )Nr   )Ú
__import__ÚglobalsÚlocalsr#   r@   r?   Úpoprb   rc   ÚtypesÚ
ModuleTyperh   )ÚmoduleZthedictZdictlistZ
totraverseZthisdictÚxÚmodnameZmoddictr!   r!   r"   Ú_makenamedictˆ  s"    




r„   c       
      C   sx  d}d}dd„ }t | dt| ƒƒ}t |d|ƒ}| j}| jj}td||d� td| j|d� td	||d� td
| j|d� td|| jj	ƒ|d� td|| jj
ƒ|d� td| jj|d� tdt| jjjƒ|f |d� tdd|d� |dk�rtd|tj|f |d� d}	nH|dk�r2td||f |d� tjdk}	ntd||f |d� tjdk}	td||	ƒ|d� td| j |d� dS )aO  Provide 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.

    ru   c             S   s   | S )Nr!   )r‚   r!   r!   r"   rQ   °  s    z_info.<locals>.<lambda>Ú	__class__r#   zclass: )Úfilezshape: z	strides: z
itemsize: z	aligned: zcontiguous: z	fortran: zdata pointer: %s%szbyteorder: r8   )Úendr†   ú|r\   z%s%s%sFú>z%sbig%sÚbigz
%slittle%sÚlittlez
byteswap: ztype: %sN)rˆ   r\   )ÚgetattrÚtyperS   rU   Ú	byteorderrl   rT   rV   ÚflagsZalignedÚ
contiguousZfortranÚhexÚctypesZ_as_parameter_ÚvaluerK   )
ÚobjÚoutputÚextraZticZbpÚclsÚnmrS   ZendianZbyteswapr!   r!   r"   Ú_infoœ  s8    


r™   éL   c             C   sl  ddl }ddl}t| dƒs$t| dƒr,| j} nt| dƒr<| j} | dkrPttƒ �nt| tƒrjt| |d� �nþt| t	ƒ�rTt
dkrŠt|ƒ\a
ad}g }x�tD ]ˆ}ylt
| |  }	t|	ƒ|krÈtd| |d� n6|jt|	ƒƒ td	| |d� t|	ƒ td
| |d� |d7 }W q˜ tk
�r   Y q˜X q˜W |dk�r@td|  |d� ntd| |d� �n|j| ƒ�rÄ| j}
tt| ƒŽ }t|
| ƒ|k�r’t|
||ƒ}n|
| }td| d |d� t|j| ƒ|d� �n¤|j| ƒ�rZ| j}
d}yZt| dƒ�r2tt| jjƒŽ }|jdƒ}t|ƒdk�r2d|d  |d< dj|dd… ƒ}W n tk
�rJ   Y nX t|
| ƒ|k�rlt|
||ƒ}n|
| }td| d |d� |j| ƒ}|dk�r¾t| dƒ�rÐt|j| jƒ|d� nt|j| ƒ|d� |j| ƒ}|g k�rhtd|d� xd|D ]\}|d dk�r�qöt| |dƒ}|dk	�r<|j |j|ƒ�p4dƒ\}}td||f |d� �qöW �nt!j"d dk �ršt| t#j$ƒ�rštd| j%j|d� t|d� t| dƒ�r†tt| j&jƒŽ }|jdƒ}t|ƒdk�rìd|d  |d< dj|dd… ƒ}nd}t| dƒ�rd| j' }
nd}
t|
| ƒ|k�r,t|
||ƒ}n|
| }td| d |d� |j| j&ƒ}|dk	�rrt|j| j&ƒ|d� t|j| ƒ|d� nt|j| ƒ|d� nÎ|j(| ƒ�rJ| j}
tt| jƒŽ }|jdƒ}t|ƒdk�röd|d  |d< dj|dd… ƒ}nd}t|
| ƒ|k�rt|
||ƒ}n|
| }td| d |d� t|j| ƒ|d� nt| dƒ�rht|j| ƒ|d� dS )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. ***

    r   NZ_ppimport_importerÚ_ppimport_moduleÚ_ppimport_attr)r•   z+
     *** Repeat reference found in %s *** )r†   z     *** Found in %s ***ú-r7   zHelp for %s not found.z+
     *** Total of %d references found. ***r8   r-   z()r,   z, ú(z

Methods:
Ú_ÚNonez  %s  --  %sr^   zInstance of class: rH   r%   z%sz<name>r:   ))ÚpydocÚinspectÚhasattrr›   rœ   r   rc   r	   r™   rf   Ú	_namedictr„   Ú	_dictlistrd   rl   rh   ÚKeyErrorÚ
isfunctionr#   r   r   r?   rz   ÚgetdocÚisclassr,   Ú__func__r<   r   Ú	ExceptionZ
allmethodsrŒ   ZsplitdocrK   Úversion_infor   ZInstanceTyper…   rH   r%   Úismethod)ÚobjectZmaxwidthr•   Útoplevelr¡   r¢   ZnumfoundZobjlistrq   r”   r%   rv   Zargstrrx   Zdoc1ÚmethodsÚmethZthisobjZmethstrÚotherrC   r!   r!   r"   r   Ï  sè    4


















c             C   sZ   ddl }y,td|j| ƒ |d� t|j| ƒ|d� W n  tk
rT   td|d� Y nX dS )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.

    r   NzIn file: %s
)r†   zNot available for this object.)r¢   rl   ÚgetsourcefileÚ	getsourcer«   )r®   r•   r¢   r!   r!   r"   r   �  s    )z[a-z0-9_]+\(.*[,=].*\)TFc                sØ  ddl }t|||ƒ‰ g }t| ƒjƒ jƒ ‰ˆs0dS xZˆ jƒ D ]N\}\}}	}
|	dkrRq:d}|jƒ }xˆD ]}||krdd}P qdW |r:|j|ƒ q:W dddddœ‰‡‡fd	d
„‰‡ ‡fdd„}|j|d� ddjˆƒ }|dt	|ƒ g}x’|ddd… D ]€}ˆ | \}}	}dd„ |j
ƒ jdƒD ƒ}y(|d j
ƒ }tj|ƒ�r@|d j
ƒ }W n tk
�r\   d}Y nX |jd||f ƒ qðW |�s„|jdƒ |dk	�r |jdj|ƒƒ n4t	|ƒdk�rÆ|jƒ }|dj|ƒƒ ntdj|ƒƒ dS )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.
    ...

    r   Nr�   r®   TFiè  )r$   Úclassr�   r®   c                s¦   d}dj |jƒ jƒ jdƒd d… ƒ‰ |t‡ fdd„ˆD ƒƒ7 }|t‡fdd„ˆD ƒƒ7 }|tˆƒ d 7 }|ˆj|dƒ7 }|ˆjd	ƒ d
 7 }|t| d dƒ7 }|S )Nr   r-   r^   c                s   g | ]}|ˆ krd ‘qS )éÈ   r!   )Ú.0Úw)Ú	first_docr!   r"   ú
<listcomp>+  s    z.lookfor.<locals>.relevance.<locals>.<listcomp>c                s   g | ]}|ˆ krd ‘qS )é   r!   )r·   r¸   )r%   r!   r"   rº   -  s    r]   iè  Ú.r[   éd   iüÿÿiœÿÿÿ)	r   ÚlowerÚstripr<   Úsumr?   ÚgetÚcountrk   )r%   ZdocstrÚkindÚindexÚr)Úkind_relevanceÚwhats)r¹   r%   r"   Ú	relevance'  s     zlookfor.<locals>.relevancec                s   ˆ| fˆ |  žŽ S )Nr!   )rY   )ro   rÈ   r!   r"   Úrelevance_value7  s    z lookfor.<locals>.relevance_value)ÚkeyzSearch results for '%s'r8   r�   r7   c             S   s   g | ]}|j ƒ r|j ƒ ‘qS r!   )r¿   )r·   rG   r!   r!   r"   rº   A  s    zlookfor.<locals>.<listcomp>r-   ru   z	%s
    %szNothing found.r[   )r�   r®   iüÿÿiüÿÿéÿÿÿÿ)r¡   Ú_lookfor_generate_cacherf   r¾   r<   Úitemsrh   Úsortr   r?   r¿   Ú_function_signature_reÚsearchÚ
IndexErrorÚwriteZgetpagerrl   )Úwhatr�   Úimport_modulesÚ
regenerater•   r¡   Úfoundr%   Z	docstringrÃ   rÄ   ÚokrC   r¸   rÉ   ÚsÚ	help_textÚixZdoclinesr¹   Zpagerr!   )ro   rÆ   rÈ   rÇ   r"   r   Ø  sT    /




c          #   C   sæ  ddl }tjd dkr$ddlm} nddlm} | dkr<d} t| tƒrtyt| ƒ W n tk
rf   i S X tj	|  } n<t| t
ƒsˆt| tƒr°i }x| D ]}|jt|||ƒƒ q’W |S t| ƒtkrÎ| rÎtt| ƒ S i }|tt| ƒ< i }d}| j| fg}	�xì|	�rà|	jdƒ\}
}t|ƒ|k�rqöd|t|ƒ< |d7 }d}|j|ƒ�rNd	}y
|j}W n tk
�rf   d}Y nX |�rnt|d
ƒ�rnxò|jD ]è}xàtj|ƒD ]Ò}tjj||ƒ}tjj||dƒ}tjj|ƒ�rÜ|jdƒ�rÜ|dd… }ntjj|ƒ�r’|}n�q’|dk�r�q’yDtj}tj}z$|ƒ t_|ƒ t_td|
|f ƒ W d|t_|t_X W n tk
�r`   �w’Y nX �q’W �q‚W xÜt |ƒD ]Ð\}}y$t!|dd|
|f ƒ}t!|ddƒ}W n& t"k
�rÊ   d|
|f }d}Y nX d|k�rè|�rèd||f }|j#|
d ƒ�st|t$ƒ�rxn�qxn$|j|ƒ�p(|dk�p(||k�s0�qx|	j%d|
|f |fƒ �qxW nP|j&|ƒ�rŽd}x>t |ƒD ] \}}|	j%d|
|f |fƒ �qhW nt|dƒ�ržd}y|j'|ƒ}W n t"k
�rÆ   d}Y nX |dk	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.

    r   Nr^   )ÚStringIOr   Tr7   r®   r�   Ú__path__z__init__.pyz.pyr,   z%s.%sr#   rI   r¼   rµ   rH   r$   éýÿÿÿ)(r¢   rK   r¬   ÚiorÛ   rc   rf   r{   ÚImportErrorÚmodulesÚlistÚtuplerA   rÌ   rd   Ú_lookfor_cachesr#   r~   ÚismoduleÚ__all__r9   r£   rÜ   r   Úlistdirr   r   ÚisfileÚendswithÚstdoutÚstderrÚBaseExceptionÚ_getmembersrŒ   Ú	NameErrorÚ
startswithr
   rh   r©   r¨   )r�   rÔ   rÕ   r¢   rÛ   ro   ÚmodÚseenrÄ   Ústackr%   ÚitemrÃ   Z_allÚpthZmod_pathZthis_pyZinit_pyZ	to_importZ
old_stdoutZ
old_stderrÚnÚvZ	item_nameÚmod_namerC   r!   r!   r"   rÌ   Y  s¶    







 
rÌ   c                sF   dd l }y|jˆ ƒ}W n* tk
r@   ‡ fdd„tˆ ƒD ƒ}Y nX |S )Nr   c                s$   g | ]}t ˆ |ƒr|tˆ |ƒf‘qS r!   )r£   rŒ   )r·   r‚   )rò   r!   r"   rº   ê  s    z_getmembers.<locals>.<listcomp>)r¢   Ú
getmembersr«   Údir)rò   r¢   Úmembersr!   )rò   r"   rì   å  s    rì   c               @   sx   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSafeEvalzù
    Object to evaluate constant string expressions.

    This includes strings with lists, dicts and tuples using the abstract
    syntax tree created by ``compiler.parse``.

    .. deprecated:: 1.10.0

    See Also
    --------
    safe_eval

    c             C   s   t jdtdd� d S )Nz3SafeEval is deprecated in 1.10 and will be removed.r.   )r/   )r0   r1   r2   )r+   r!   r!   r"   r,     s    zSafeEval.__init__c             C   s"   |j }t| d|j | jƒ}||ƒS )NÚvisit)r…   rŒ   r#   Údefault)r+   Únoder—   r±   r!   r!   r"   rû     s    zSafeEval.visitc             C   s   t d|j ƒ‚d S )Nz Unsupported source construct: %s)ÚSyntaxErrorr…   )r+   rý   r!   r!   r"   rü     s    zSafeEval.defaultc             C   s   | j |jƒS )N)rû   Úbody)r+   rý   r!   r!   r"   ÚvisitExpression  s    zSafeEval.visitExpressionc             C   s   |j S )N)rô   )r+   rý   r!   r!   r"   ÚvisitNum  s    zSafeEval.visitNumc             C   s   |j S )N)rØ   )r+   rý   r!   r!   r"   ÚvisitStr  s    zSafeEval.visitStrc             C   s   |j S )N)rØ   )r+   rý   r!   r!   r"   Ú
visitBytes"  s    zSafeEval.visitBytesc                s    t ‡ fdd„t|j|jƒD ƒƒS )Nc                s$   g | ]\}}ˆ j |ƒˆ j |ƒf‘qS r!   )rû   )r·   rs   rõ   )r+   r!   r"   rº   &  s   z&SafeEval.visitDict.<locals>.<listcomp>)ÚdictrX   rb   Úvalues)r+   rý   Úkwr!   )r+   r"   Ú	visitDict%  s    zSafeEval.visitDictc                s   t ‡ fdd„|jD ƒƒS )Nc                s   g | ]}ˆ j |ƒ‘qS r!   )rû   )r·   Úi)r+   r!   r"   rº   *  s    z'SafeEval.visitTuple.<locals>.<listcomp>)râ   Úelts)r+   rý   r!   )r+   r"   Ú
visitTuple)  s    zSafeEval.visitTuplec                s   ‡ fdd„|j D ƒS )Nc                s   g | ]}ˆ j |ƒ‘qS r!   )rû   )r·   r  )r+   r!   r"   rº   -  s    z&SafeEval.visitList.<locals>.<listcomp>)r	  )r+   rý   r!   )r+   r"   Ú	visitList,  s    zSafeEval.visitListc             C   sR   dd l }t|j|jƒr$| j|jƒ
 S t|j|jƒr@| j|jƒ S td|j ƒ‚d S )Nr   zUnknown unary op: %r)Úastrc   ÚopÚUAddrû   ÚoperandÚUSubrþ   )r+   rý   r  r!   r!   r"   ÚvisitUnaryOp/  s    zSafeEval.visitUnaryOpc             C   s<   |j dkrdS |j dkrdS |j dkr*d S td|j  ƒ‚d S )NÚFalseFÚTrueTr    zUnknown name: %s)rd   rþ   )r+   rý   r!   r!   r"   Ú	visitName8  s    


zSafeEval.visitNamec             C   s   |j S )N)r“   )r+   rý   r!   r!   r"   ÚvisitNameConstantB  s    zSafeEval.visitNameConstantN)r#   rI   rJ   r:   r,   rû   rü   r   r  r  r  r  r
  r  r  r  r  r!   r!   r!   r"   rú   ý  s   	
rú   c             C   s   ddl }|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...>

    r   N)r  Úliteral_eval)r   r  r!   r!   r"   r   F  s    ,c             C   s¢   | j dkr|S tj| |dƒ} tj| d	 ƒ}tjj|ƒr@|jdƒ}|jdkr‚|dkrž|dk	rr| jj	tj
ƒ|d< |}qž| jj	tj
ƒ}ntj|jƒ ƒdkržtj
||< |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.
    r   r7   .FTNrË   rË   ).rË   )rW   ÚnpZmoveaxisÚisnanÚmaZisMaskedArrayZfilledÚndimrU   r�   ÚnanZcount_nonzeroZravel)rR   ÚresultZaxisÚoutrô   r!   r!   r"   Ú_median_nancheckv  s    



r  )N)r   )NTFN)4Ú
__future__r   r   r   r   rK   r   Úrer0   Znumpy.core.numerictypesr   r   r   Znumpy.core.overridesr   r   r	   r
   r   r   r  Znumpy.compatr   r   rå   r   r&   r®   r'   r=   r   r   r   r   rz   r¤   r¥   r„   ré   r™   r   r   rã   ÚcompileÚIrÏ   r   rÌ   rì   rú   r   r  r!   r!   r!   r"   Ú<module>   sT   

K49
i
3 N3  I0