Ë
    êÿæiZ  ã                   ó„   — d Z ddlmZmZ 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	gZ G d
„ de	e¬«      Zdd„Zy)zUtilities for meta-estimators.é    )ÚABCMetaÚabstractmethod)ÚsuppressN)ÚBaseEstimator)Ú_safe_indexing)Úavailable_if)Úget_tagsr   c                   óJ   ‡ — e Zd ZdZed„ «       Zdˆ fd„	Zˆ fd„Zd„ Zd„ Z	ˆ xZ
S )Ú_BaseCompositionaÈ  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                  ó   — y ©N© )Úselfs    úq/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/sklearn/utils/metaestimators.pyÚ__init__z_BaseComposition.__init__   s   € àó    c                 ó,  •— t         ‰	| �  |¬«      }|s|S t        | |«      }	 |j                  |«       |D ]D  \  }}t        |d«      sŒ|j                  d¬«      j                  «       D ]  \  }}|||›d|›�<   Œ ŒF |S # t        t
        f$ r |cY S w xY w)N©ÚdeepÚ
get_paramsTÚ__)Úsuperr   ÚgetattrÚupdateÚ	TypeErrorÚ
ValueErrorÚhasattrÚitems)
r   Úattrr   ÚoutÚ
estimatorsÚnameÚ	estimatorÚkeyÚvalueÚ	__class__s
            €r   Ú_get_paramsz_BaseComposition._get_params#   s­   ø€ Ü‰gÑ  dÐ Ó+ˆÙØˆJä˜T 4Ó(ˆ
ð	Ø�J‰J�zÔ"ó  *‰OˆD�)Ü�y ,Õ/Ø"+×"6Ñ"6¸DÐ"6Ó"A×"GÑ"GÖ"I‘J�C˜Ø27�C¢D©#Ð.Ò/ñ #Jð  *ð ˆ
øô œ:Ð&ò 	ð ŠJð	ús   £A? Á?BÂBc           	      ó–  •— ||v rt        | ||j                  |«      «       t        | |«      }t        |t        «      rp|rnt        t        «      5  t        |Ž \  }}t	        |j                  «       «      D ].  }d|vsŒ||v sŒ| j                  |||j                  |«      «       Œ0 	 d d d «       t        ‰| �,  di |¤Ž | S # 1 sw Y   ŒxY w)Nr   r   )ÚsetattrÚpopr   Ú
isinstanceÚlistr   r   ÚzipÚkeysÚ_replace_estimatorr   Ú
set_params)r   r   Úparamsr   Ú
item_namesÚ_r"   r&   s          €r   Ú_set_paramsz_BaseComposition._set_params9   s´   ø€ ð �6‰>Ü�D˜$ §
¡
¨4Ó 0Ô1ä˜˜dÓ#ˆÜ�eœTÔ"¡uô œ)Õ$Ü # U ‘�
˜AÜ  §¡£Ö/�DØ 4Ò'¨D°JÒ,>Ø×/Ñ/°°d¸F¿J¹JÀtÓ<LÕMñ 0÷ %ô 	‰ÑÑ$˜VÒ$Øˆ÷ %Ð$ús   Á,B?Á<B?Â$B?Â?Cc                 ó�   — t        t        | |«      «      }t        |«      D ]  \  }\  }}||k(  sŒ||f||<    n t        | ||«       y r   )r,   r   Ú	enumerater)   )r   r   r"   Únew_valÚnew_estimatorsÚiÚestimator_namer3   s           r   r/   z#_BaseComposition._replace_estimatorN   sT   € äœg d¨DÓ1Ó2ˆÜ&/°Ö&?Ñ"ˆAÑ"� Ø Ó%Ø%)¨7 O�˜qÑ!Ùð '@ô 	��d˜NÕ+r   c                 ó’  — t        t        |«      «      t        |«      k7  r#t        dj                  t	        |«      «      «      ‚t        |«      j                  | j                  d¬«      «      }|r#t        dj                  t        |«      «      «      ‚|D �cg c]	  }d|v sŒ|‘Œ }}|rt        dj                  |«      «      ‚y c c}w )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_namesz _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)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r'   r4   r/   rC   Ú__classcell__)r&   s   @r   r   r      s0   ø„ ñ	ð ñó ðõô,ò*,ör   r   )Ú	metaclassc                 óv  — t        | «      j                  j                  rwt        |d«      st	        d«      ‚|j
                  d   |j
                  d   k7  rt	        d«      ‚|€|t        j                  ||«         }n&|t        j                  ||«         }nt        ||«      }|�t        ||«      }||fS d}||fS )aÝ  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   rK   ÚnpÚix_r   )r#   ÚXÚyÚindicesÚtrain_indicesÚX_subsetÚy_subsets          r   Ú_safe_splitrW   h   sÇ   € ôX �	Ó×%Ñ%×.Ò.Ü�q˜'Ô"Üð=óð ð
 �7‰7�1‰:˜Ÿ™ ™Ò#ÜÐAÓBÐBØÐ ØœŸ™ ¨Ó1Ñ2‰HàœŸ™ ¨Ó7Ñ8‰Hä! ! WÓ-ˆà€}Ü! ! WÓ-ˆð �XÐÐð ˆà�XÐÐr   r   )rG   Úabcr   r   Ú
contextlibr   ÚnumpyrO   Úsklearn.baser   Úsklearn.utilsr   Úsklearn.utils._available_ifr   Úsklearn.utils._tagsr	   Ú__all__r   rW   r   r   r   Ú<module>r`      s>   ðÙ $÷
 (Ý ã å &Ý (Ý 4Ý (àÐ
€ôR�}°õ RôjAr   