U
    3dr                     @   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   C/tmp/pip-unpacked-wheel-zrfo1fqw/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.
    Z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 z	 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 matrixZrandom_stateNbooleanverboseZ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'   rM   r   wrapper   s,      z3validate_params.<locals>.decorator.<locals>.wrapper)setattr	functoolswraps)rZ   r[   r'   )rZ   r   	decorator   s    #z"validate_params.<locals>.decoratorr   )r'   r`   r   r_   r   validate_params   s    ,ra   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    ri   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   rI   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   rI   valr   r   r   r$      s    z_Constraint.is_satisfied_byc                 C   s   dS )z;A human readable representational string of the constraint.Nr   rl   r   r   r   __str__   s    z_Constraint.__str__N)r   r   r   r   rm   r   r$   rp   r   r   r   r   rj      s   
rj   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r8   z~Constraint representing instances of a given type.

    Parameters
    ----------
    type : type
        The valid type.
    c                    s   t    || _d S N)superrm   r7   )rI   r7   	__class__r   r   rm     s    
z_InstancesOf.__init__c                 C   s   t || jS rq   r0   r7   rn   r   r   r   r$     s    z_InstancesOf.is_satisfied_byc                 C   s   dt | jS )Nzan instance of )ri   r7   rl   r   r   r   rp   	  s    z_InstancesOf.__str__r   r   r   r   rm   r$   rp   __classcell__r   r   rs   r   r8      s   r8   c                   @   s    e Zd ZdZdd Zdd ZdS )r6   z+Constraint representing the None singleton.c                 C   s   |d kS rq   r   rn   r   r   r   r$     s    z_NoneConstraint.is_satisfied_byc                 C   s   dS )NNoner   rl   r   r   r   rp     s    z_NoneConstraint.__str__Nr   r   r   r   r$   rp   r   r   r   r   r6     s   r6   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 rq   )r0   r   mathisnanrn   r   r   r   r$     s    z_NanConstraint.is_satisfied_byc                 C   s   dS )Nz	numpy.nanr   rl   r   r   r   rp     s    z_NanConstraint.__str__Nry   r   r   r   r   rz     s   rz   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)Zpandasr0   r7   ZNAZisnaImportError)rI   ro   pdr   r   r   r$   $  s
    z#_PandasNAConstraint.is_satisfied_byc                 C   s   dS )Nz	pandas.NAr   rl   r   r   r   rp   ,  s    z_PandasNAConstraint.__str__Nry   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.)rr   rm   r7   optionssetr   rB   )rI   r7   r   r   rs   r   r   rm   ?  s    
zOptions.__init__c                 C   s   t || jo|| jkS rq   )r0   r7   r   rn   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   )rI   optionZ
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   orl   r   r   r   T  s     z#Options.__str__.<locals>.<listcomp>za z among {})r&   r   ri   r7   )rI   options_strr   rl   r   rp   R  s    zOptions.__str__)	r   r   r   r   rm   r$   r   rp   rw   r   r   rs   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)r7   r   r   )rr   rm   r   )rI   r   r   rs   r   r   rm   f  s    zStrOptions.__init__)r   r   r   r   rm   rw   r   r   rs   r   r:   Y  s   r:   c                	       sn   e Zd ZdZeegeedgeedgeddddhgd fdd	Z	d
d Z
dd Zdd Zdd Z  ZS )r9   u  Constraint representing a typed interval.

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

    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 {+∞}`.
    Nleftrightbothneither)r7   r   r   closedc                   s.   t    || _|| _|| _|| _|   d S rq   )rr   rm   r7   r   r   r   _check_params)rI   r7   r   r   r   rs   r   r   rm     s    	
zInterval.__init__c                 C   s   | j tkrd}| jd k	r2t| jts2td| | jd k	rVt| jtsVtd| | jd kr| jdkrtd| j d| | jd kr| jdkrtd| j d| | jd k	r| jd k	r| j| jkrtd	| j d
| j d S )Nz"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(right can't be less than left. Got left=z and right=)r7   r   r   r0   	TypeErrorr   r   rB   )rI   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   )rI   ro   Zleft_cmpZ	right_cmpr   r   r   r   r   __contains__  s    


zInterval.__contains__c                 C   s   t || jsdS || kS rk   ru   rn   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   )r7   r   r   r   r   )rI   Ztype_strZleft_bracketZ
left_boundZright_boundZright_bracketr   r   r   rp     s    zInterval.__str__)r   r   r   r   ra   r7   r   r   r:   rm   r   r   r$   rp   rw   r   r   rs   r   r9   j  s    	r9   c                   @   s    e Zd ZdZdd Zdd ZdS )r1   z#Constraint representing array-likesc                 C   s   t |S rq   r   rn   r   r   r   r$     s    z_ArrayLikes.is_satisfied_byc                 C   s   dS )Nzan array-liker   rl   r   r   r   rp     s    z_ArrayLikes.__str__Nry   r   r   r   r   r1     s   r1   c                   @   s    e Zd ZdZdd Zdd ZdS )r2   z(Constraint representing sparse matrices.c                 C   s   t |S rq   r   rn   r   r   r   r$     s    z_SparseMatrices.is_satisfied_byc                 C   s   dS )Nza sparse matrixr   rl   r   r   r   rp     s    z_SparseMatrices.__str__Nry   r   r   r   r   r2     s   r2   c                   @   s    e Zd ZdZdd Zdd ZdS )r5   z"Constraint representing callables.c                 C   s   t |S rq   )r4   rn   r   r   r   r$     s    z_Callables.is_satisfied_byc                 C   s   dS )Nz
a callabler   rl   r   r   r   rp     s    z_Callables.__str__Nry   r   r   r   r   r5     s   r5   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r3   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   )
rr   rm   r9   r   r8   r   randomRandomStater6   _constraintsrl   rs   r   r   rm     s
    

z_RandomStates.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S rq   r$   r   ro   r   r   	<genexpr>  s     z0_RandomStates.is_satisfied_by.<locals>.<genexpr>anyr   rn   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   rl   r   r   r   rp     s    ,z_RandomStates.__str__rv   r   r   rs   r   r3     s   r3   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r=   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 rq   )rr   rm   r8   boolr   bool_r   r   rl   rs   r   r   rm     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 rq   r   r   r   r   r   r   #  s     z,_Booleans.is_satisfied_by.<locals>.<genexpr>)r0   r   r   warningswarnFutureWarningr   r   rn   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   '  s     z%_Booleans.__str__.<locals>.<listcomp>r!   r"   r   rl   r   r   r   rp   %  s    ,z_Booleans.__str__rv   r   r   rs   r   r=     s   r=   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r>   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   )	rr   rm   r9   r   r8   r   r   r   r   rl   rs   r   r   rm   3  s
    
z_VerboseHelper.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S rq   r   r   r   r   r   r   <  s     z1_VerboseHelper.is_satisfied_by.<locals>.<genexpr>r   rn   r   r   r   r$   ;  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   @  s     z*_VerboseHelper.__str__.<locals>.<listcomp>r!   r"   r   rl   r   r   r   rp   >  s    ,z_VerboseHelper.__str__rv   r   r   rs   r   r>   ,  s   r>   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r?   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   )rr   rm   r8   r   r9   r   r   r6   rz   r}   r   rl   rs   r   r   rm   S  s    
z_MissingValues.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S rq   r   r   r   r   r   r   `  s     z1_MissingValues.is_satisfied_by.<locals>.<genexpr>r   rn   r   r   r   r$   _  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   d  s     z*_MissingValues.__str__.<locals>.<listcomp>r!   r"   r   rl   r   r   r   rp   b  s    ,z_MissingValues.__str__rv   r   r   rs   r   r?   E  s   r?   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 rq   )rr   rm   r0   r   r   rI   r   rs   r   r   rm   u  s    

zHasMethods.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}t t |d V  qd S rq   )r4   getattr)r   methodr   r   r   r   }  s     z-HasMethods.is_satisfied_by.<locals>.<genexpr>)allr   rn   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   rp     s
    ,zHasMethods.__str__)r   r   r   r   ra   r   listrm   r$   rp   rw   r   r   rs   r   r<   i  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 rq   )r0   r   r   rn   r   r   r   r$     s    z#_IterablesNotString.is_satisfied_byc                 C   s   dS )Nzan iterabler   rl   r   r   r   rp     s    z_IterablesNotString.__str__Nry   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 )r@   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)rr   rm   r9   r   r<   r   r6   r   rl   rs   r   r   rm     s    

z_CVObjects.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]}|  V  qd S rq   r   r   r   r   r   r     s     z-_CVObjects.is_satisfied_by.<locals>.<genexpr>r   rn   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   rl   r   r   r   rp     s    ,z_CVObjects.__str__rv   r   r   rs   r   r@     s   	r@   c                   @   s   e Zd ZdZdd ZdS )rA   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 rq   rC   )rI   r   r   r   r   rm     s    zHidden.__init__N)r   r   r   r   rm   r   r   r   r   rA     s   rA   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)r0   r:   r&   r   r?   r   arrayr>   r<   r7   r   r@   r9   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   )r0   r9   r7   r   )r   ir   r   r   r     s    
 
 z8_generate_invalid_param_val_interval.<locals>.<listcomp>r   r   r   )r7   r   r   r   r   r   r   r   floorceilrd   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 rq   r   )xr   r   r   <lambda>p      z&generate_valid_param.<locals>.<lambda>NTZValidHasMethodsr   c                 S   s   i | ]}|d d qS )c                 S   s   d S rq   r   rl   r   r   r   r     r   z1generate_valid_param.<locals>.<dictcomp>.<lambda>r   r   r   r   r   rN     s      z(generate_valid_param.<locals>.<dictcomp>   r/   )r0   r1   r   r   r2   r
   r3   r   r   r5   r6   r8   r7   r=   r>   r?   nanr<   r   r   r@   r;   r   r9   r   r   r   rB   )r   r   r   r   r   r   generate_valid_paramW  sV    









  






r   )N)3abcr   r   collections.abcr   r]   r{   inspectr   Znumbersr   r   r   rT   r   Znumpyr   Zscipy.sparser	   r
   Z
validationr   rB   r   r   r,   r   ra   ri   rj   r8   r6   rz   r}   r;   r:   r9   r1   r2   r5   r3   r=   r>   r?   r<   r   r@   rA   r   r   r   r   r   r   r   <module>   sR   K*A

)j


!$!

/h