`L iddlmZddlZddlmZddlmZddl m Z ddl m Z dZ d Ze d d gd gd d dZdZdZy))suppressN)sparse) is_scalar_nan)validate_params)_object_dtype_isnancttt5ddl}||jur|j |cdddS dddt |r||jjdk(rtj|}|S|jjdvr'tj|jt}|St|}|S||k(}|S#1swYxYw)Nrf)iudtype)r ImportErrorAttributeErrorpandasNAisnarrkindnpisnanzerosshapeboolr)X value_to_maskrXts Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/_mask.py_get_dense_maskrs +~ ."  FII %;;q> "" & "]# 77<<3 !B IWW\\Z '!''.B I %Q'B I-  I)""s #CC"cjtj|s t||St|j|}|jdk(rtj ntj }|||jj|jjf|jt}|S)aCompute 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)rr) spissparserdataformat csr_matrix csc_matrixindicescopyindptrrr)rrrsparse_constructor Xt_sparses r _get_maskr,&s" ;;q>q-00  /B*+((e*;" QYY^^ qxx}}/qwwdI z array-likez sparse matrix)rmaskT)prefer_skip_nested_validationctj|}tj|jtjr|St |dr'tj |jd}||}|S)asReturn 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)rasarray issubdtyper signedintegerhasattraranger)rr.inds r safe_maskr8Fs^F ::d D }}TZZ!1!12 q)ii 1 &4y Kr-c||dk7r|t||ddfStjd|jdfS)aReturn 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. rNr)r)r8rrr)rr.len_masks raxis0_safe_slicer;ss>@1}1d#Q&'' 881aggaj/ **r-c|tj|kr tdtj|t}d||<|S)aYConvert 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)rmax ValueErrorrr)r' mask_lengthr.s rindices_to_maskr@s>.bffWo%HII 88Kt ,DDM Kr-) contextlibrnumpyrscipyrr!_missingr_param_validationrfixesrrr,r8r;r@r-rrHs` #.&0@O ,#' ##L"+Jr-