B
    vd)                 @   s  d Z ddlmZ ddlZddlZddlZddlmZ ddl	Z	ddl
Z	ddlmZ ddlZddlmZmZ ddlmZ eejZee	jZeedkrdd	lmZ ndd	lmZ ydd
lmZmZ W n$ ek
r   dd
lmZmZ Y nX dd Zdd Z dd Z!G dd de	j"j#Z$dd Z%dd Z&G dd dZ'd*ddZ(ddd d!Z)eed"k r^e)Z*ndd#lm*Z* d$d% Z+d+d&d'Z,ej,j e,_ d(d) Z-ej-j e-_ dS ),zCompatibility fixes for older version of python, numpy and scipy

If you add content to this file, please give the version of the package
at which the fix is no longer needed.
    )update_wrapperN)lsqr   )config_context
get_config)parsez1.4)lobpcg)line_search_wolfe2line_search_wolfe1c             C   s   | | kS )N )Xr   r   `/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sklearn/utils/fixes.py_object_dtype_isnan-   s    r   c             C   s&   t tdkst| sddiS i S dS )zReturns the copy=False parameter for
    {ndarray, csr_matrix, csc_matrix}.astype when possible,
    otherwise don't specify
    z1.1copyFN)
sp_versionparse_versionspissparse)r   r   r   r   _astype_copy_false2   s    r   c              K   s   ddl }t|jtdkr| S t|  ddh}|rNtdt||jf i }d| kr| d }|dkrvtd| d	d
dd| |d< d| kr| d }|dkrtd| |dkrd	|d< |S )a  Set joblib.Parallel arguments in a compatible way for 0.11 and 0.12+

    For joblib 0.11 this maps both ``prefer`` and ``require`` parameters to
    a specific ``backend``.

    Parameters
    ----------

    prefer : str in {'processes', 'threads'} or None
        Soft hint to choose the default backend if no specific backend
        was selected with the parallel_backend context manager.

    require : 'sharedmem' or None
        Hard condstraint to select the backend. If set to 'sharedmem',
        the selected backend will be single-host and thread-based even
        if the user asked for a non-thread based backend with
        parallel_backend.

    See joblib.Parallel documentation for more details
    r   Nz0.12preferrequirez%unhandled arguments %s with joblib %s)threadsZ	processesNzprefer=%s is not supported	threadingmultiprocessingbackend)N	sharedmemzrequire=%s is not supportedr   )	joblibr   __version__setkeys
differenceNotImplementedErrorlist
ValueError)kwargsr   
extra_argsargsr   r   r   r   r   _joblib_parallel_args=   s0    
r'   c               @   s   e Zd ZdZdS )
loguniformaw  A class supporting log-uniform random variables.

    Parameters
    ----------
    low : float
        The minimum value
    high : float
        The maximum value

    Methods
    -------
    rvs(self, size=None, random_state=None)
        Generate log-uniform random variables

    The most useful method for Scikit-learn usage is highlighted here.
    For a full list, see
    `scipy.stats.reciprocal
    <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.reciprocal.html>`_.
    This list includes all functions of ``scipy.stats`` continuous
    distributions such as ``pdf``.

    Notes
    -----
    This class generates values between ``low`` and ``high`` or

        low <= loguniform(low, high).rvs() <= high

    The logarithmic probability density function (PDF) is uniform. When
    ``x`` is a uniformly distributed random variable between 0 and 1, ``10**x``
    are random variables that are equally likely to be returned.

    This class is an alias to ``scipy.stats.reciprocal``, which uses the
    reciprocal distribution:
    https://en.wikipedia.org/wiki/Reciprocal_distribution

    Examples
    --------

    >>> from sklearn.utils.fixes import loguniform
    >>> rv = loguniform(1e-3, 1e1)
    >>> rvs = rv.rvs(random_state=42, size=1000)
    >>> rvs.min()  # doctest: +SKIP
    0.0010435856341129003
    >>> rvs.max()  # doctest: +SKIP
    9.97403052786026
    N)__name__
__module____qualname____doc__r   r   r   r   r(   q   s   .r(   c       	      C   s  t tdkrtj| ||dS |dkr,|  } t|jtjsDtd| j	|j	krXt
dd|j	 }tt|dg tt|d |j	 }g }xbt|| jD ]R\}}|dkr|| q|d| d ||d d  }|t|| qW t|}| | S dS )	zQImplements a simplified version of np.take_along_axis if numpy
    version < 1.15z1.15)arrindicesaxisNz"`indices` must be an integer arrayz;`indices` and `arr` must have the same number of dimensions)   r0   ))
np_versionr   npZtake_along_axisflattenZ
issubdtypedtypeZintp
IndexErrorndimr#   r"   rangezipshapeappendZarangeZreshapetuple)	r-   r.   r/   Z
shape_onesZ	dest_dimsZfancy_indexdimnZ	ind_shaper   r   r   _take_along_axis   s&    
& r?   c                s   t   fdd}|S )z6Decorator used to capture the arguments of a function.c                 s   t  | |fS )N)_FuncWrapper)r&   r$   )functionr   r   delayed_function   s    z!delayed.<locals>.delayed_function)	functoolswraps)rA   rB   r   )rA   r   delayed   s    rE   c               @   s    e Zd ZdZdd Zdd ZdS )r@   z< "Load the global configuration before calling the function.c             C   s   || _ t | _t| | j  d S )N)rA   r   configr   )selfrA   r   r   r   __init__   s    z_FuncWrapper.__init__c          	   O   s$   t f | j | j||S Q R X d S )N)r   rF   rA   )rG   r&   r$   r   r   r   __call__   s    z_FuncWrapper.__call__N)r)   r*   r+   r,   rH   rI   r   r   r   r   r@      s   r@   2   TFc          	   C   sZ  t tdk r>t| d } t|d }t| |t|}|dkrH|}| jd  kr`|jkrzn ntj| |||||dS | jdks|jdks| j|jkrt	d| jd }tj
||f|d}	tj
|tjd}
xBt|D ]6}tj| | || ||d	|d\|	dd|f< |
|< qW |dkr*t|	d|}	|r8|	|
fS |	S ntj| ||||||d
S dS )a1  Implements a simplified linspace function as of numpy version >= 1.16.

    As of numpy 1.16, the arguments start and stop can be array-like and
    there is an optional argument `axis`.
    For simplicity, we only allow 1d array-like to be passed to start and stop.
    See: https://github.com/numpy/numpy/pull/12388 and numpy 1.16 release
    notes about start and stop arrays for linspace logspace and geomspace.

    Returns
    -------
    out : ndarray of shape (num, n_start) or (num,)
        The output array with `n_start=start.shape[0]` columns.
    z1.16g      ?Nr   )startstopnumendpointretstepr5   r0   z3start and stop must be 1d array-like of same shape.)r5   T)rK   rL   rM   rN   rO   r5   r/   )r2   r   r3   Z
asanyarrayZresult_typefloatr7   linspacer:   r#   emptyr8   Zmoveaxis)rK   rL   rM   rN   rO   r5   r/   dtZn_startoutstepir   r   r   rQ      sP     
 
rQ   Zlinear)methodc            K   s   t j| |fd|i|S )Ninterpolation)r3   
percentile)aqrW   r$   r   r   r   _percentile  s    r\   z1.22)rY   c               C   s(   t tdsd S t tds"t t_tjS )NThreadpoolController_sklearn_threadpool_controller)hasattrthreadpoolctlsklearnr]   r^   r   r   r   r   _get_threadpool_controller+  s
    


rb   c             C   s.   t  }|d k	r|j| |dS tj| |dS d S )N)limitsuser_api)rb   limitr`   threadpool_limits)rc   rd   
controllerr   r   r   rf   5  s    rf   c              C   s"   t  } | d k	r|  S t S d S )N)rb   infor`   threadpool_info)rg   r   r   r   ri   @  s    ri   )rJ   TFNr   )NN).r,   rC   r   ra   numpyr3   Zscipy.sparsesparser   ZscipyZscipy.statsZscipy.sparse.linalgr   Zsparse_lsqrr`   _configr   r   Zexternals._packaging.versionr   r   r   r2   r   r   Zexternals._lobpcgZscipy.optimize._linesearchr	   r
   ImportErrorZscipy.optimize.linesearchr   r   r'   statsZ
reciprocalr(   r?   rE   r@   rQ   r\   rY   rb   rf   ri   r   r   r   r   <module>   sJ   

41"

B


