3
[h:                 @   sD  d Z ddlmZ ddlmZ ddlZddlZddljZ	ddl
Z
ddlZ
ddlmZ ddlmZ ddlmZmZ d	d
lmZ yddlmZ W n ek
r   eZY nX eejZee
jZeedkrddlmZ nddlmZ dd Zdd Z dd Z!G dd de
j"j#Z$edG dd deZdd Z%dd Z&G dd dZ'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 fixe is no longer needed.
    )update_wrapper)LooseVersionN)lsqr)MaskedArray   )config_context
get_config   )
deprecated)parse_versionz1.4)lobpcgc             C   s   | | kS )N )Xr   r   ;/tmp/pip-build-zwgx3nbq/scikit-learn/sklearn/utils/fixes.py_object_dtype_isnan/   s    r   c             C   s(   t tdkstj|  r 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_versionr   spissparse)r   r   r   r   _astype_copy_false4   s    r   c              K   s   ddl }t|jtdkr| S t| j j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threads	processeszprefer=%s is not supported	threadingmultiprocessing)r   r   Nbackend	sharedmemzrequire=%s is not supported)r   r   N)Nr   )	joblibr   __version__setkeys
differenceNotImplementedErrorlist
ValueError)kwargsr   
extra_argsargsr   r   r   r   r   _joblib_parallel_args?   s,    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*   o   s   .r*   zMaskedArray is deprecated in version 0.23 and will be removed in version 1.0 (renaming of 0.25). Use numpy.ma.MaskedArray instead.c               @   s   e Zd ZdS )r   N)r+   r,   r-   r   r   r   r   r      s   r   c       	      C   s  t tdkrtj| ||dS |dkr,| j } tj|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|j| q|d| d	 ||d d  }|jtj|j| 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 dimensionsr	   )r	   )r2   )
np_versionr   npZtake_along_axisflattenZ
issubdtypeZdtypeZintp
IndexErrorndimr%   r$   rangezipshapeappendZarangeZreshapetuple)	r/   r0   r1   Z
shape_onesZ	dest_dimsZfancy_indexZdimnZ	ind_shaper   r   r   _take_along_axis   s(    
 r>   c                s   t j  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)r@   rA   r   )r@   r   delayed   s    rD   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)r@   r   configr   )selfr@   r   r   r   __init__   s    z_FuncWrapper.__init__c          
   O   s$   t f | j | j||S Q R X d S )N)r   rE   r@   )rF   r(   r&   r   r   r   __call__   s    z_FuncWrapper.__call__N)r+   r,   r-   r.   rG   rH   r   r   r   r   r?      s   r?   )(r.   rB   r   Zdistutils.versionr   Znumpyr4   Zscipy.sparsesparser   ZscipyZscipy.statsZscipy.sparse.linalgr   Zsparse_lsqrZnumpy.mar   Z_MaskedArrayZ_configr   r   deprecationr
   pkg_resourcesr   ImportErrorr   r3   r   r   Zexternals._lobpcgr   r   r)   statsZ
reciprocalr*   r>   rD   r?   r   r   r   r   <module>   s<   



01%