ó
    Ñ]jZ  ã                   ó€   • S r SSKJrJr  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
 S\	\S9rSS jrg)zUtilities for meta-estimators.é    )ÚABCMetaÚabstractmethod)ÚsuppressN)ÚBaseEstimator)Ú_safe_indexing)Úavailable_if)Úget_tagsr   c                   óX   ^ • \ rS rSrSr\S 5       rS	U 4S jjrU 4S jrS r	S r
SrU =r$ )
Ú_BaseCompositioné   a¬  Base class for estimators that are composed of named sub-estimators.

This abstract class provides parameter management functionality for
meta-estimators that contain collections of named estimators. It handles
the complex logic for getting and setting parameters on nested estimators
using the "estimator_name__parameter" syntax.

The class is designed to work with any attribute containing a list of
(name, estimator) tuples.
c                 ó   • g ©N© )Úselfs    ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/utils/metaestimators.pyÚ__init__Ú_BaseComposition.__init__   s   € àó    c                 ó<  >• [         T	U ]  US9nU(       d  U$ [        X5      n UR                  U5        U HI  u  pV[        US5      (       d  M  UR                  SS9R                  5        H  u  pxXƒU< SU< 3'   M     MK     U$ ! [        [
        4 a    Us $ f = f)N©ÚdeepÚ
get_paramsTÚ__)Úsuperr   ÚgetattrÚupdateÚ	TypeErrorÚ
ValueErrorÚhasattrÚitems)
r   Úattrr   ÚoutÚ
estimatorsÚnameÚ	estimatorÚkeyÚvalueÚ	__class__s
            €r   Ú_get_paramsÚ_BaseComposition._get_params#   s¨   ø€ Ü‰gÑ  dÐ Ð+ˆÞØˆJä˜TÓ(ˆ
ð	Ø�J‰J�zÔ"ó  *‰OˆDÜ�y ,×/Ó/Ø"+×"6Ñ"6¸DÐ"6Ð"A×"GÑ"GÖ"I‘J�CØ27£Dª#Ð.Ó/ó #Jñ  *ð ˆ
øô œ:Ð&ó 	ð ŠJð	ús   ¤B ÂBÂBc           	      ó¼  >• X;   a  [        XUR                  U5      5        [        X5      n[        U[        5      (       ay  U(       ar  [        [        5         [        U6 u  pE[	        UR                  5       5       H3  nSU;  d  M  Xd;   d  M  U R                  XUR                  U5      5        M5     S S S 5        [        TU ],  " S0 UD6  U $ ! , (       d  f       N = f)Nr   r   )ÚsetattrÚpopr   Ú
isinstanceÚlistr   r   ÚzipÚkeysÚ_replace_estimatorr   Ú
set_params)r   r!   Úparamsr    Ú
item_namesÚ_r$   r(   s          €r   Ú_set_paramsÚ_BaseComposition._set_params9   s«   ø€ ð ‹>Ü�D §
¡
¨4Ó 0Ô1ä˜Ó#ˆÜ�eœT×"Ñ"¦uô œ)Õ$Ü # U ‘�
Ü  §¡£Ö/�DØ 4Õ'¨DÕ,>Ø×/Ñ/°¸F¿J¹JÀtÓ<LÖMñ 0÷ %ô 	‰ÒÑ$˜VÒ$Øˆ÷ %Õ$ús   Á+CÂCÂ%CÃ
Cc                 óŠ   • [        [        X5      5      n[        U5       H  u  nu  pgXb:X  d  M  X#4XE'     O   [        XU5        g r   )r/   r   Ú	enumerater,   )r   r!   r$   Únew_valÚnew_estimatorsÚiÚestimator_namer6   s           r   r2   Ú#_BaseComposition._replace_estimatorN   sH   € äœg dÓ1Ó2ˆÜ&/°Ö&?Ñ"ˆAÑ"�ØÕ%Ø%) O�Ñ!Ùñ '@ô 	�˜NÕ+r   c                 ó®  • [        [        U5      5      [        U5      :w  a#  [        SR                  [	        U5      5      5      e[        U5      R                  U R                  SS95      nU(       a#  [        SR                  [        U5      5      5      eU Vs/ s H  nSU;   d  M  UPM     nnU(       a  [        SR                  U5      5      eg s  snf )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}r   z.Estimator names must not contain __: got {0!r})ÚlenÚsetr   Úformatr/   Úintersectionr   Úsorted)r   ÚnamesÚinvalid_namesr$   s       r   Ú_validate_namesÚ _BaseComposition._validate_namesW   s¼   € ÜŒs�5‹z‹?œc %›jÓ(ÜÐC×JÑJÌ4ÐPUË;ÓWÓXÐXÜ˜E›
×/Ñ/°·±ÀU°Ð0KÓLˆÞÜØL×SÑSÜ˜=Ó)óóð ñ
 +0Ó@ª% $°4¸4±<Ÿ©%ˆÐ@ÞÜØ@×GÑGÈÓVóð ð ùò As   Â
CÂ(Cr   )T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r)   r7   r2   rH   Ú__static_attributes__Ú__classcell__)r(   s   @r   r   r      s5   ø† ñ	ð ñó ð÷õ,ò*,÷ð r   r   )Ú	metaclassc                 óˆ  • [        U 5      R                  R                  (       a~  [        US5      (       d  [	        S5      eUR
                  S   UR
                  S   :w  a  [	        S5      eUc  U[        R                  " X35         nO%U[        R                  " X45         nO[        X5      nUb  [        X#5      nXV4$ SnXV4$ )aa  Create subset of dataset and properly handle kernels.

Slice X, y according to indices for cross-validation, but take care of
precomputed kernel-matrices or pairwise affinities / distances.

If ``estimator._pairwise is True``, X needs to be square and
we slice rows and columns. If ``train_indices`` is not None,
we slice rows using ``indices`` (assumed the test set) and columns
using ``train_indices``, indicating the training set.

Labels y will always be indexed only along the first axis.

Parameters
----------
estimator : object
    Estimator to determine whether we should slice only rows or rows and
    columns.

X : array-like, sparse matrix or iterable
    Data to be indexed. If ``estimator._pairwise is True``,
    this needs to be a square array-like or sparse matrix.

y : array-like, sparse matrix or iterable
    Targets to be indexed.

indices : array of int
    Rows to select from X and y.
    If ``estimator._pairwise is True`` and ``train_indices is None``
    then ``indices`` will also be used to slice columns.

train_indices : array of int or None, default=None
    If ``estimator._pairwise is True`` and ``train_indices is not None``,
    then ``train_indices`` will be use to slice the columns of X.

Returns
-------
X_subset : array-like, sparse matrix or list
    Indexed data.

y_subset : array-like, sparse matrix or list
    Indexed targets.

ÚshapezXPrecomputed kernels or affinity matrices have to be passed as arrays or sparse matrices.r   é   z"X should be a square kernel matrixN)	r	   Ú
input_tagsÚpairwiser   r   rS   ÚnpÚix_r   )r%   ÚXÚyÚindicesÚtrain_indicesÚX_subsetÚy_subsets          r   Ú_safe_splitr_   h   s¾   € ôX �	Ó×%Ñ%×.×.Ü�q˜'×"Ñ"Üð=óð ð
 �7‰7�1‰:˜Ÿ™ ™Ó#ÜÐAÓBÐBØÑ ØœŸš Ó1Ñ2‰HàœŸš Ó7Ñ8‰Hä! !Ó-ˆà�}Ü! !Ó-ˆð ÐÐð ˆàÐÐr   r   )rN   Úabcr   r   Ú
contextlibr   ÚnumpyrW   Úsklearn.baser   Úsklearn.utilsr   Úsklearn.utils._available_ifr   Úsklearn.utils._tagsr	   Ú__all__r   r_   r   r   r   Ú<module>rh      s>   ðÙ $÷
 (Ý ã å &Ý (Ý 4Ý (àÐ
€ôR�}°ò RõjAr   