
    {Kg                         d dl mZ d dlZd dlmZ ddlmZ ddl	m
Z
 ddlmZ d Zd	 Z e
d
dgd
gdd      d        Zd Zd Zy)    )suppressN)sparse   )is_scalar_nan)validate_params)_object_dtype_isnanc                    t        t        t              5  dd l}||j                  u r|j                  |       cd d d        S 	 d d d        t        |      r|| j                  j                  dk(  rt        j                  |       }|S | j                  j                  dv r't        j                  | j                  t              }|S t        |       }|S | |k(  }|S # 1 sw Y   xY w)Nr   f)iudtype)r   ImportErrorAttributeErrorpandasNAisnar   r   kindnpisnanzerosshapeboolr   )Xvalue_to_maskr   Xts       W/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/utils/_mask.py_get_dense_maskr      s    	+~	. 	FII%;;q> 
/	.
 & 
/ ]#77<<3!B I WW\\Z'!''.B I	 %Q'B I -I) 
/	.s   #CC"c                 j   t        j                  |       st        | |      S t        | j                  |      }| j                  dk(  rt         j
                  nt         j                  } ||| j                  j                         | j                  j                         f| j                  t              }|S )a  Compute the boolean mask X == value_to_mask.

    Parameters
    ----------
    X : {ndarray, sparse matrix} of shape (n_samples, n_features)
        Input data, where ``n_samples`` is the number of samples and
        ``n_features`` is the number of features.

    value_to_mask : {int, float}
        The value which is to be masked in X.

    Returns
    -------
    X_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)
        Missing mask.
    csr)r   r   )spissparser   dataformat
csr_matrix
csc_matrixindicescopyindptrr   r   )r   r   r   sparse_constructor	Xt_sparses        r   	_get_maskr,   #   s    " ;;q> q-00		/B*+((e*;"	QYY^^qxx}}/qwwdI     z
array-likezsparse matrix)r   maskT)prefer_skip_nested_validationc                     t        j                  |      }t        j                  |j                  t         j                        r|S t        | d      r't        j                  |j                  d         }||   }|S )as  Return a mask which is safe to use on X.

    Parameters
    ----------
    X : {array-like, sparse matrix}
        Data on which to apply mask.

    mask : array-like
        Mask to be used on X.

    Returns
    -------
    mask : ndarray
        Array that is safe to use on X.

    Examples
    --------
    >>> from sklearn.utils import safe_mask
    >>> from scipy.sparse import csr_matrix
    >>> data = csr_matrix([[1], [2], [3], [4], [5]])
    >>> condition = [False, True, True, False, True]
    >>> mask = safe_mask(data, condition)
    >>> data[mask].toarray()
    array([[2],
           [3],
           [5]])
    toarrayr   )r   asarray
issubdtyper   signedintegerhasattraranger   )r   r.   inds      r   	safe_maskr8   C   s^    F ::dD	}}TZZ!1!12q)ii

1&4yKr-   c                 |    |dk7  r| t        | |      ddf   S t        j                  d| j                  d   f      S )a  Return a mask which is safer to use on X than safe_mask.

    This mask is safer than safe_mask since it returns an
    empty array, when a sparse matrix is sliced with a boolean mask
    with all False, instead of raising an unhelpful error in older
    versions of SciPy.

    See: https://github.com/scipy/scipy/issues/5361

    Also note that we can avoid doing the dot product by checking if
    the len_mask is not zero in _huber_loss_and_gradient but this
    is not going to be the bottleneck, since the number of outliers
    and non_outliers are typically non-zero and it makes the code
    tougher to follow.

    Parameters
    ----------
    X : {array-like, sparse matrix}
        Data on which to apply mask.

    mask : ndarray
        Mask to be used on X.

    len_mask : int
        The length of the mask.

    Returns
    -------
    mask : ndarray
        Array that is safe to use on X.
    r   Nr   )r   )r8   r   r   r   )r   r.   len_masks      r   axis0_safe_slicer;   p   s>    @ 1}1d#Q&''881aggaj/**r-   c                     |t        j                  |       k  rt        d      t        j                  |t              }d|| <   |S )aY  Convert list of indices to boolean mask.

    Parameters
    ----------
    indices : list-like
        List of integers treated as indices.
    mask_length : int
        Length of boolean mask to be generated.
        This parameter must be greater than max(indices).

    Returns
    -------
    mask : 1d boolean nd-array
        Boolean array that is True where indices are present, else False.

    Examples
    --------
    >>> from sklearn.utils._mask import indices_to_mask
    >>> indices = [1, 2 , 3, 4]
    >>> indices_to_mask(indices, 5)
    array([False,  True,  True,  True,  True])
    z-mask_length must be greater than max(indices)r   T)r   max
ValueErrorr   r   )r'   mask_lengthr.   s      r   indices_to_maskr@      s>    . bffWo%HII88Kt,DDMKr-   )
contextlibr   numpyr   scipyr   r!   _missingr   _param_validationr   fixesr   r   r,   r8   r;   r@    r-   r   <module>rH      s^       # . &0@ O, #'##L"+Jr-   