ó
    Ñ]jA  ã                   ó†   • S SK Jr  S SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S rS r\
" S	S
/S	/S.SS9S 5       rS rS rg)é    )ÚsuppressN)Úsparse)Úis_scalar_nan)Úvalidate_params)Ú_object_dtype_isnanc                 óâ  • [        [        [        5         SS KnXR                  L a  UR                  U 5      sS S S 5        $  S S S 5        [        U5      (       a  U R                  R                  S:X  a  [        R                  " U 5      nU$ U R                  R                  S;   a%  [        R                  " U R                  [        S9nU$ [        U 5      n U$ X:H  nU$ ! , (       d  f       N£= f)Nr   Úf)ÚiÚu©Údtype)r   ÚImportErrorÚAttributeErrorÚpandasÚNAÚisnar   r   ÚkindÚnpÚisnanÚzerosÚshapeÚboolr   )ÚXÚvalue_to_maskr   ÚXts       ÚP/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/utils/_mask.pyÚ_get_dense_maskr      sÁ   € Ü	”+œ~Õ	.ó 	àŸI™IÒ%Ø—;‘;˜q“>÷ 
/Ñ	.ð
 &÷ 
/ô �]×#Ñ#Ø�7‰7�<‰<˜3ÓÜ—’˜!“ˆBð €Ið �W‰W�\‰\˜ZÓ'ä—’˜!Ÿ'™'¬Ñ.ˆBð €Iô	 % QÓ'‰Bð €Ið Ñˆà€I÷) 
/Õ	.ús   •#C Ã 
C.c                 ón  • [         R                  " U 5      (       d  [        X5      $ [        U R                  U5      nU R                  S:X  a  [         R
                  O[         R                  nU" X R                  R                  5       U R                  R                  5       4U R                  [        S9nU$ )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Ó*;œŸšÄÇÁÐÙ"Ø	�Y‰Y�^‰^Ó˜qŸx™xŸ}™}›Ð/°q·w±wÄdñ€Ið Ðó    z
array-likezsparse matrix)r   ÚmaskT)Úprefer_skip_nested_validationc                 ó  • [         R                  " U5      n[         R                  " UR                  [         R                  5      (       a  U$ [        U S5      (       a'  [         R                  " UR                  S   5      nX!   nU$ )a  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_maskr7   F   sb   € ôF �:Š:�dÓ€DÜ	‡}‚}�T—Z‘Z¤×!1Ñ!1×2Ñ2Øˆäˆq�)×ÑÜ�iŠi˜Ÿ
™
 1™Ó&ˆØ‰yˆØ€Kr,   c                 óx   • US:w  a  U [        X5      SS24   $ [        R                  " SU R                  S   4S9$ )a6  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   Né   )r   )r7   r   r   r   )r   r-   Úlen_masks      r   Úaxis0_safe_slicer;   s   s<   € ð@ �1ƒ}Ø”˜1Ó#¢QÐ&Ñ'Ð'Ü�8Š8˜1˜aŸg™g a™j˜/Ñ*Ð*r,   c                 óŠ   • U[         R                  " U 5      ::  a  [        S5      e[         R                  " U[        S9nSX '   U$ )a  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<   € ð. ”b—f’f˜W“oÓ%ÜÐHÓIÐIä�8Š8�K¤tÑ,€DØ€D�Mà€Kr,   )Ú
contextlibr   Únumpyr   Úscipyr   r    Úsklearn.utils._missingr   Úsklearn.utils._param_validationr   Úsklearn.utils.fixesr   r   r+   r7   r;   r@   © r,   r   Ú<module>rH      s`   ðõ  ã Ý å 0Ý ;Ý 3òò0ñ@ à˜OÐ,Ø�ñð #'ññ#óð#òL"+óJr,   