U
    (|eu                     @   s  d dl mZ d dl mZ d dlmZ d dlZd dlZd dlmZ d dl	m
Z
 d dl	mZ d dlZd dlZd dlZd dlZd dlmZ d d	lmZ d
dlmZ G dd deeZdd Zdd Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G d d! d!eZ"G d"d# d#e"Z#G d$d% d%eZ$G d&d' d'eZ%G d(d) d)eZ&G d*d+ d+eZ'G d,d- d-eZ(G d.d/ d/eZ)G d0d1 d1eZ*G d2d3 d3eZ+G d4d5 d5eZ,G d6d7 d7eZ-G d8d9 d9eZ.G d:d; d;Z/dBd<d=Z0d>d? Z1d@dA Z2dS )C    )ABC)abstractmethod)IterableN)	signature)Integral)Realissparse)
csr_matrix   _is_arraylike_not_scalarc                   @   s   e Zd ZdZdS )InvalidParameterErrorzyCustom exception to be raised when the parameter of a class/method/function
    does not have a valid type or value.
    N)__name__
__module____qualname____doc__ r   r   \/var/www/website-v5/atlas_env/lib/python3.8/site-packages/sklearn/utils/_param_validation.pyr      s   r   c                 C   s   |  D ]\}}|| krq| | }|dkr,qdd |D }|D ]}||r> qq>dd |D }t|dkrx|d  }n*ddd |d	d
 D  d|d
  }td|d| d| d|d	qd	S )a  Validate types and values of given parameters.

    Parameters
    ----------
    parameter_constraints : dict or {"no_validation"}
        If "no_validation", validation is skipped for this parameter.

        If a dict, it must be a dictionary `param_name: list of constraints`.
        A parameter is valid if it satisfies one of the constraints from the list.
        Constraints can be:
        - an Interval object, representing a continuous or discrete range of numbers
        - the string "array-like"
        - the string "sparse matrix"
        - the string "random_state"
        - callable
        - None, meaning that None is a valid value for the parameter
        - any type, meaning that any instance of this type is valid
        - an Options object, representing a set of elements of a given type
        - a StrOptions object, representing a set of strings
        - the string "boolean"
        - the string "verbose"
        - the string "cv_object"
        - the string "missing_values"
        - a HasMethods object, representing method(s) an object must have
        - a Hidden object, representing a constraint not meant to be exposed to the user

    params : dict
        A dictionary `param_name: param_value`. The parameters to validate against the
        constraints.

    caller_name : str
        The name of the estimator or function or method that called this function.
    no_validationc                 S   s   g | ]}t |qS r   )make_constraint.0
constraintr   r   r   
<listcomp>J   s     z2validate_parameter_constraints.<locals>.<listcomp>c                 S   s   g | ]}|j s|qS r   hiddenr   r   r   r   r   U   s     r   r   , c                 S   s   g | ]}t |qS r   strr   cr   r   r   r   ]   s     N or zThe z parameter of z	 must be z. Got 	 instead.)itemsis_satisfied_bylenjoinr   )parameter_constraintsparamscaller_name
param_nameZ	param_valconstraintsr   Zconstraints_strr   r   r   validate_parameter_constraints   s(    "
(r.   c                 C   s  t | tr| dkrt S t | tr0| dkr0t S t | trH| dkrHt S | tkrVt S | dkrdt S t | trvt	| S t | t
tttfr| S t | tr| dkrt S t | tr| dkrt S t | tr| dkrt S t | tr| dkrt S t | trt| j} d	| _| S td
|  dS )a  Convert the constraint into the appropriate Constraint object.

    Parameters
    ----------
    constraint : object
        The constraint to convert.

    Returns
    -------
    constraint : instance of _Constraint
        The converted constraint.
    z
array-likezsparse matrixrandom_stateNbooleanverbosemissing_valuesZ	cv_objectTUnknown constraint type: )
isinstancer   _ArrayLikes_SparseMatrices_RandomStatescallable
_Callables_NoneConstrainttype_InstancesOfInterval
StrOptionsOptions
HasMethods	_Booleans_VerboseHelper_MissingValues
_CVObjectsHiddenr   r   r   
ValueErrorr   r   r   r   r   g   s6    

r   c                    s    fdd}|S )a  Decorator to validate types and values of functions and methods.

    Parameters
    ----------
    parameter_constraints : dict
        A dictionary `param_name: list of constraints`. See the docstring of
        `validate_parameter_constraints` for a description of the accepted constraints.

        Note that the *args and **kwargs parameters are not validated and must not be
        present in the parameter_constraints dictionary.

    Returns
    -------
    decorated_function : function or method
        The decorated function.
    c                    s(   t  d t  fdd}|S )NZ_skl_parameter_constraintsc               
      s   t }|j| |}|  dd |j D   ddg7   fdd|j D }t|jd z| |W S  t	k
r } z*t
dd	j d
t|}t	||W 5 d }~X Y nX d S )Nc                 S   s$   g | ]}|j |j|jfkr|jqS r   )kindVAR_POSITIONALVAR_KEYWORDname)r   pr   r   r   r      s   zGvalidate_params.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>selfclsc                    s   i | ]\}}| kr||qS r   r   )r   kvZ	to_ignorer   r   
<dictcomp>   s       zGvalidate_params.<locals>.decorator.<locals>.wrapper.<locals>.<dictcomp>)r+   zparameter of \w+ must bezparameter of z must be)r   bindapply_defaults
parametersvalues	argumentsr%   r.   r   r   resubr   )argskwargsZfunc_sigr*   emsg)funcr)   rQ   r   wrapper   s,      z3validate_params.<locals>.decorator.<locals>.wrapper)setattr	functoolswraps)r^   r_   r)   )r^   r   	decorator   s    #z"validate_params.<locals>.decoratorr   )r)   rd   r   rc   r   validate_params   s    ,re   c                 C   s>   | j }| j}|dkr|S | tkr$dS | tkr0dS | d| S )z(Convert type into human readable string.builtinsfloatint.)r   r   r   r   )tmodulequalnamer   r   r   
_type_name   s    rm   c                   @   s0   e Zd ZdZdd Zedd Zedd ZdS )	_Constraintz&Base class for the constraint objects.c                 C   s
   d| _ d S NFr   rM   r   r   r   __init__   s    z_Constraint.__init__c                 C   s   dS )a  Whether or not a value satisfies the constraint.

        Parameters
        ----------
        val : object
            The value to check.

        Returns
        -------
        is_satisfied : bool
            Whether or not the constraint is satisfied by this value.
        Nr   rM   valr   r   r   r&      s    z_Constraint.is_satisfied_byc                 C   s   dS )z;A human readable representational string of the constraint.Nr   rp   r   r   r   __str__   s    z_Constraint.__str__N)r   r   r   r   rq   r   r&   rt   r   r   r   r   rn      s   
rn   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r<   z~Constraint representing instances of a given type.

    Parameters
    ----------
    type : type
        The valid type.
    c                    s   t    || _d S N)superrq   r;   )rM   r;   	__class__r   r   rq     s    
z_InstancesOf.__init__c                 C   s   t || jS ru   )r4   r;   rr   r   r   r   r&     s    z_InstancesOf.is_satisfied_byc                 C   s   dt | jS )Nzan instance of )rm   r;   rp   r   r   r   rt   	  s    z_InstancesOf.__str__r   r   r   r   rq   r&   rt   __classcell__r   r   rw   r   r<      s   r<   c                   @   s    e Zd ZdZdd Zdd ZdS )r:   z+Constraint representing the None singleton.c                 C   s   |d kS ru   r   rr   r   r   r   r&     s    z_NoneConstraint.is_satisfied_byc                 C   s   dS )NNoner   rp   r   r   r   rt     s    z_NoneConstraint.__str__Nr   r   r   r   r&   rt   r   r   r   r   r:     s   r:   c                   @   s    e Zd ZdZdd Zdd ZdS )_NanConstraintz/Constraint representing the indicator `np.nan`.c                 C   s   t |tot|S ru   )r4   r   mathisnanrr   r   r   r   r&     s    z_NanConstraint.is_satisfied_byc                 C   s   dS )Nz	numpy.nanr   rp   r   r   r   rt     s    z_NanConstraint.__str__Nr|   r   r   r   r   r}     s   r}   c                   @   s    e Zd ZdZdd Zdd ZdS )_PandasNAConstraintz.Constraint representing the indicator `pd.NA`.c                 C   s@   z$dd l }t|t|jo"||W S  tk
r:   Y dS X d S )Nr   F)pandasr4   r;   NAZisnaImportError)rM   rs   pdr   r   r   r&   $  s
    z#_PandasNAConstraint.is_satisfied_byc                 C   s   dS )Nz	pandas.NAr   rp   r   r   r   rt   ,  s    z_PandasNAConstraint.__str__Nr|   r   r   r   r   r   !  s   r   c                       s>   e Zd ZdZdd fdd
Zdd Zdd	 Zd
d Z  ZS )r?   aG  Constraint representing a finite set of instances of a given type.

    Parameters
    ----------
    type : type

    options : set
        The set of valid scalars.

    deprecated : set or None, default=None
        A subset of the `options` to mark as deprecated in the string
        representation of the constraint.
    N
deprecatedc                   s:   t    || _|| _|pt | _| j| j r6tdd S )Nz7The deprecated options must be a subset of the options.)rv   rq   r;   optionssetr   rF   )rM   r;   r   r   rw   r   r   rq   ?  s    
zOptions.__init__c                 C   s   t || jo|| jkS ru   )r4   r;   r   rr   r   r   r   r&   H  s    zOptions.is_satisfied_byc                 C   s   |}|| j kr| d}|S )z-Add a deprecated mark to an option if needed.z (deprecated)r   )rM   option
option_strr   r   r   _mark_if_deprecatedK  s    

zOptions._mark_if_deprecatedc                    s4   d  fdd jD  }dt j d| dS )Nr   c                    s   g | ]}  |qS r   )r   )r   orp   r   r   r   T  s     z#Options.__str__.<locals>.<listcomp>za z among {})r(   r   rm   r;   )rM   Zoptions_strr   rp   r   rt   R  s    zOptions.__str__)	r   r   r   r   rq   r&   r   rt   rz   r   r   rw   r   r?   0  s
   	r?   c                       s&   e Zd ZdZdd fdd
Z  ZS )r>   a2  Constraint representing a finite set of strings.

    Parameters
    ----------
    options : set of str
        The set of valid strings.

    deprecated : set of str or None, default=None
        A subset of the `options` to mark as deprecated in the string
        representation of the constraint.
    Nr   c                   s   t  jt||d d S )N)r;   r   r   )rv   rq   r   )rM   r   r   rw   r   r   rq   f  s    zStrOptions.__init__)r   r   r   r   rq   rz   r   r   rw   r   r>   Y  s   r>   c                       sH   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	  Z
S )r=   uU  Constraint representing a typed interval.

    Parameters
    ----------
    type : {numbers.Integral, numbers.Real, "real_not_int"}
        The set of numbers in which to set the interval.

        If "real_not_int", only reals that don't have the integer type
        are allowed. For example 1.0 is allowed but 1 is not.

    left : float or int or None
        The left bound of the interval. None means left bound is -∞.

    right : float, int or None
        The right bound of the interval. None means right bound is +∞.

    closed : {"left", "right", "both", "neither"}
        Whether the interval is open or closed. Possible choices are:

        - `"left"`: the interval is closed on the left and open on the right.
          It is equivalent to the interval `[ left, right )`.
        - `"right"`: the interval is closed on the right and open on the left.
          It is equivalent to the interval `( left, right ]`.
        - `"both"`: the interval is closed.
          It is equivalent to the interval `[ left, right ]`.
        - `"neither"`: the interval is open.
          It is equivalent to the interval `( left, right )`.

    Notes
    -----
    Setting a bound to `None` and setting the interval closed is valid. For instance,
    strictly speaking, `Interval(Real, 0, None, closed="both")` corresponds to
    `[0, +∞) U {+∞}`.
    c                   s.   t    || _|| _|| _|| _|   d S ru   )rv   rq   r;   leftrightclosed_check_params)rM   r;   r   r   r   rw   r   r   rq     s    
zInterval.__init__c                 C   sp  | j ttdfkr"td| j  d| jdkr>td| j d| j tkrd}| jd k	rpt| jtsptd| | jd k	rt| jtstd| | jd kr| jd	krtd
| j d| | jd kr| jdkrtd| j d| nD| jd k	rt| jtstd| jd k	r.t| jts.td| jd k	rl| jd k	rl| j| jkrltd| j d| j d S )Nreal_not_intzJtype must be either numbers.Integral, numbers.Real or 'real_not_int'. Got r$   )r   r   bothneitherz@closed must be either 'left', 'right', 'both' or 'neither'. Got z"for an interval over the integers.zExpecting left to be an int zExpecting right to be an int r   r   z"left can't be None when closed ==  r   r   z#right can't be None when closed == z#Expecting left to be a real number.z$Expecting right to be a real number.z(right can't be less than left. Got left=z and right=)	r;   r   r   rF   r   r   r4   	TypeErrorr   )rM   suffixr   r   r   r     s<    

&zInterval._check_paramsc                 C   s   t |rdS | jdkrtjntj}| jdkr4tjntj}| jd krLt j	 n| j}| j
d krbt j	n| j
}|||rvdS |||rdS dS )NFr   r   T)npr   r   operatorltlegtger   infr   )rM   rs   Zleft_cmpZ	right_cmpr   r   r   r   r   __contains__  s    


zInterval.__contains__c                 C   s,   | j dkr t|tot|t S t|| j S )Nr   )r;   r4   r   r   rr   r   r   r   _has_valid_type  s    
zInterval._has_valid_typec                 C   s   |  |sdS || kS ro   )r   rr   r   r   r   r&     s    
zInterval.is_satisfied_byc                 C   sz   | j tkrdnd}| jdkr dnd}| jd kr2dn| j}| jd krFdn| j}| jdkrZd	nd
}| d| | d| | S )Nzan intza floatr   [(z-infr   r   ])z in the range r   )r;   r   r   r   r   )rM   Ztype_strZleft_bracketZ
left_boundZright_boundZright_bracketr   r   r   rt     s    zInterval.__str__)r   r   r   r   rq   r   r   r   r&   rt   rz   r   r   rw   r   r=   j  s   #	'r=   c                   @   s    e Zd ZdZdd Zdd ZdS )r5   z#Constraint representing array-likesc                 C   s   t |S ru   r   rr   r   r   r   r&     s    z_ArrayLikes.is_satisfied_byc                 C   s   dS )Nzan array-liker   rp   r   r   r   rt     s    z_ArrayLikes.__str__Nr|   r   r   r   r   r5     s   r5   c                   @   s    e Zd ZdZdd Zdd ZdS )r6   z(Constraint representing sparse matrices.c                 C   s   t |S ru   r   rr   r   r   r   r&     s    z_SparseMatrices.is_satisfied_byc                 C   s   dS )Nza sparse matrixr   rp   r   r   r   rt     s    z_SparseMatrices.__str__Nr|   r   r   r   r   r6     s   r6   c                   @   s    e Zd ZdZdd Zdd ZdS )r9   z"Constraint representing callables.c                 C   s   t |S ru   )r8   rr   r   r   r   r&     s    z_Callables.is_satisfied_byc                 C   s   dS )Nz
a callabler   rp   r   r   r   rt     s    z_Callables.__str__Nr|   r   r   r   r   r9     s   r9   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r7   zConstraint representing random states.

    Convenience class for
    [Interval(Integral, 0, 2**32 - 1, closed="both"), np.random.RandomState, None]
    c                    s0   t    ttddddttjjt g| _	d S )Nr   l    r   r   )
rv   rq   r=   r   r<   r   randomRandomStater:   _constraintsrp   rw   r   r   rq   
  s
    

z_RandomStates.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S ru   r&   r    rs   r   r   	<genexpr>  s     z0_RandomStates.is_satisfied_by.<locals>.<genexpr>anyr   rr   r   r   r   r&     s    z_RandomStates.is_satisfied_byc                 C   s.   d dd | jd d D  d| jd  S )Nr   c                 S   s   g | ]}t |qS r   r   r    r   r   r   r     s     z)_RandomStates.__str__.<locals>.<listcomp>r"   r#   r(   r   rp   r   r   r   rt     s    ,z_RandomStates.__str__ry   r   r   rw   r   r7     s   r7   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )rA   zrConstraint representing boolean likes.

    Convenience class for
    [bool, np.bool_, Integral (deprecated)]
    c                    s(   t    ttttjttg| _d S ru   )rv   rq   r<   boolr   bool_r   r   rp   rw   r   r   rq   #  s
    
z_Booleans.__init__c                    s8   t  tr t  ts tdt t fdd| jD S )NzrPassing an int for a boolean parameter is deprecated in version 1.2 and won't be supported anymore in version 1.4.c                 3   s   | ]}|  V  qd S ru   r   r    r   r   r   r   4  s     z,_Booleans.is_satisfied_by.<locals>.<genexpr>)r4   r   r   warningswarnFutureWarningr   r   rr   r   r   r   r&   +  s    z_Booleans.is_satisfied_byc                 C   s.   d dd | jd d D  d| jd  S )Nr   c                 S   s   g | ]}t |qS r   r   r    r   r   r   r   8  s     z%_Booleans.__str__.<locals>.<listcomp>r"   r#   r   rp   r   r   r   rt   6  s    ,z_Booleans.__str__ry   r   r   rw   r   rA     s   rA   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )rB   zHelper constraint for the verbose parameter.

    Convenience class for
    [Interval(Integral, 0, None, closed="left"), bool, numpy.bool_]
    c                    s0   t    ttdd ddttttjg| _d S )Nr   r   r   )	rv   rq   r=   r   r<   r   r   r   r   rp   rw   r   r   rq   D  s
    
z_VerboseHelper.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S ru   r   r    r   r   r   r   M  s     z1_VerboseHelper.is_satisfied_by.<locals>.<genexpr>r   rr   r   r   r   r&   L  s    z_VerboseHelper.is_satisfied_byc                 C   s.   d dd | jd d D  d| jd  S )Nr   c                 S   s   g | ]}t |qS r   r   r    r   r   r   r   Q  s     z*_VerboseHelper.__str__.<locals>.<listcomp>r"   r#   r   rp   r   r   r   rt   O  s    ,z_VerboseHelper.__str__ry   r   r   rw   r   rB   =  s   rB   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )rC   zHelper constraint for the `missing_values` parameters.

    Convenience for
    [
        Integral,
        Interval(Real, None, None, closed="both"),
        str,
        None,
        _NanConstraint(),
        _PandasNAConstraint(),
    ]
    c                    s:   t    ttttd d ddttt t t	 g| _
d S )Nr   r   )rv   rq   r<   r   r=   r   r   r:   r}   r   r   rp   rw   r   r   rq   d  s    
z_MissingValues.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S ru   r   r    r   r   r   r   q  s     z1_MissingValues.is_satisfied_by.<locals>.<genexpr>r   rr   r   r   r   r&   p  s    z_MissingValues.is_satisfied_byc                 C   s.   d dd | jd d D  d| jd  S )Nr   c                 S   s   g | ]}t |qS r   r   r    r   r   r   r   u  s     z*_MissingValues.__str__.<locals>.<listcomp>r"   r#   r   rp   r   r   r   rt   s  s    ,z_MissingValues.__str__ry   r   r   rw   r   rC   V  s   rC   c                       s@   e Zd ZdZedeegi fddZdd Zdd Z	  Z
S )	r@   aI  Constraint representing objects that expose specific methods.

    It is useful for parameters following a protocol and where we don't want to impose
    an affiliation to a specific module or class.

    Parameters
    ----------
    methods : str or list of str
        The method(s) that the object is expected to expose.
    methodsc                    s$   t    t|tr|g}|| _d S ru   )rv   rq   r4   r   r   rM   r   rw   r   r   rq     s    

zHasMethods.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}t t |d V  qd S ru   )r8   getattr)r   methodr   r   r   r     s     z-HasMethods.is_satisfied_by.<locals>.<genexpr>)allr   rr   r   r   r   r&     s    zHasMethods.is_satisfied_byc                 C   sT   t | jdkr| jd }n.ddd | jd d D  d| jd }d| S )	Nr   r   r   c                 S   s   g | ]}t |qS r   )reprr   mr   r   r   r     s     z&HasMethods.__str__.<locals>.<listcomp>r"   z and zan object implementing )r'   r   r(   r   r   r   r   rt     s
    ,zHasMethods.__str__)r   r   r   r   re   r   listrq   r&   rt   rz   r   r   rw   r   r@   z  s
   r@   c                   @   s    e Zd ZdZdd Zdd ZdS )_IterablesNotStringz7Constraint representing iterables that are not strings.c                 C   s   t |tot |t S ru   )r4   r   r   rr   r   r   r   r&     s    z#_IterablesNotString.is_satisfied_byc                 C   s   dS )Nzan iterabler   rp   r   r   r   rt     s    z_IterablesNotString.__str__Nr|   r   r   r   r   r     s   r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )rD   zConstraint representing cv objects.

    Convenient class for
    [
        Interval(Integral, 2, None, closed="left"),
        HasMethods(["split", "get_n_splits"]),
        _IterablesNotString(),
        None,
    ]
    c                    s4   t    ttdd ddtddgt t g| _d S )N   r   r   splitZget_n_splits)rv   rq   r=   r   r@   r   r:   r   rp   rw   r   r   rq     s    

z_CVObjects.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S ru   r   r    r   r   r   r     s     z-_CVObjects.is_satisfied_by.<locals>.<genexpr>r   rr   r   r   r   r&     s    z_CVObjects.is_satisfied_byc                 C   s.   d dd | jd d D  d| jd  S )Nr   c                 S   s   g | ]}t |qS r   r   r    r   r   r   r     s     z&_CVObjects.__str__.<locals>.<listcomp>r"   r#   r   rp   r   r   r   rt     s    ,z_CVObjects.__str__ry   r   r   rw   r   rD     s   	rD   c                   @   s   e Zd ZdZdd ZdS )rE   zClass encapsulating a constraint not meant to be exposed to the user.

    Parameters
    ----------
    constraint : str or _Constraint instance
        The constraint to be used internally.
    c                 C   s
   || _ d S ru   rG   )rM   r   r   r   r   rq     s    zHidden.__init__N)r   r   r   r   rq   r   r   r   r   rE     s   rE   c                 C   s   t | trdd| j S t | tr6tdddgS t | trDdS t | tr\t	ddi  S t | t
rjd	S t | trxd
S t | tst|dkr| gn|}t| |S )aS  Return a value that does not satisfy the constraint.

    Raises a NotImplementedError if there exists no invalid value for this constraint.

    This is only useful for testing purpose.

    Parameters
    ----------
    constraint : _Constraint instance
        The constraint to generate a value for.

    constraints : list of _Constraint instances or None, default=None
        The list of all constraints for this parameter. If None, the list only
        containing `constraint` is used.

    Returns
    -------
    val : object
        A value that does not satisfy the constraint.
    znot r#   r   r      r"   ZHasNotMethodsr   za stringznot a cv objectN)r4   r>   r(   r   rC   r   arrayrB   r@   r;   r   rD   r=   NotImplementedError$_generate_invalid_param_val_interval)r   r-   r   r   r   generate_invalid_param_val  s     






r   c                 C   s  | j tkrr| jdkrD| jdkrD| jdkr.tjS | jdkr@tj S t| jdk	r^t| jd S t	| jd S n| jdkr| jdkrtdd |D }|r|d nd}|dkr| jdk	r| jd S | jd S | j}|dk	r| jdkr|d }| j}|dk	r| jdkr|d }|j}|jdk	rHt
t	|j}|jdkrH|d }|j}|jdk	r~t
t|j}|jdkr~|d }|dk	r|dk	rt||d S |dk	r|dk	rt||d S |dk	r|dk	r|| d	kr|d S tn$|dk	r|| d	kr|d S tdS )
a  Return a value that does not satisfy an interval constraint.

    Generating an invalid value for an integer interval depends on the other constraints
    since an int is a real, meaning that it can be valid for a real interval.
    Assumes that there can be at most 2 interval constraints: one integer interval
    and/or one real interval.

    This is only useful for testing purpose.

    Parameters
    ----------
    interval : Interval instance
        The interval to generate a value for.

    constraints : list of _Constraint instances
        The list of all constraints for this parameter.

    Returns
    -------
    val : object
        A value that does not satisfy the interval constraint.
    N)r   r   )r   r   g      ?c                 S   s$   g | ]}t |tr|jtkr|qS r   )r4   r=   r;   r   )r   ir   r   r   r   -  s    
 
 z8_generate_invalid_param_val_interval.<locals>.<listcomp>r   r   r   )r;   r   r   r   r   r   r   r   floorceilrh   minmax)intervalr-   Zreal_intervalsZreal_intervalZint_leftZ	int_rightZ	real_leftZ
real_rightr   r   r   r      s^    







r   c                 C   s  t | trtdddgS t | tr8tddgddggS t | trNtjdS t | t	r`dd S t | t
rndS t | tr|  S t | trd	S t | trdS t | trtjS t | trtd
ddd | jD  S t | trdddgS t | trdS t | tr| jD ]
}|  S t | tr| }|jdkr<|jdkr<dS |jdkrR|jd S |jdkrh|jd S |jtkr|j|j d S |jd S td|  dS )a1  Return a value that does satisfy a constraint.

    This is only useful for testing purpose.

    Parameters
    ----------
    constraint : Constraint instance
        The constraint to generate a value for.

    Returns
    -------
    val : object
        A value that does satisfy the constraint.
    r   r   r   r   *   c                 S   s   | S ru   r   )xr   r   r   <lambda>      z&generate_valid_param.<locals>.<lambda>NTZValidHasMethodsr   c                 S   s   i | ]}|d d qS )c                 S   s   d S ru   r   rp   r   r   r   r     r   z1generate_valid_param.<locals>.<dictcomp>.<lambda>r   r   r   r   r   rR     s      z(generate_valid_param.<locals>.<dictcomp>   r3   )r4   r5   r   r   r6   r
   r7   r   r   r9   r:   r<   r;   rA   rB   rC   nanr@   r   r   rD   r?   r   r=   r   r   r   rF   )r   r   r   r   r   r   generate_valid_paramh  sV    









  






r   )N)3abcr   r   collections.abcr   ra   r~   inspectr   numbersr   r   r   rX   r   numpyr   scipy.sparser	   r
   
validationr   rF   r   r   r.   r   re   rm   rn   r<   r:   r}   r   r?   r>   r=   r5   r6   r9   r7   rA   rB   rC   r@   r   rD   rE   r   r   r   r   r   r   r   <module>   sR   K*A

){


!$!

/h