
    3;jiZ                         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dS )zUtilities for meta-estimators.    )ABCMetaabstractmethod)suppressN)BaseEstimator)_safe_indexing)available_if)get_tagsr   c                   P     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                     d S N )selfs    V/root/voice-cloning/.venv/lib/python3.11/site-packages/sklearn/utils/metaestimators.py__init__z_BaseComposition.__init__   s        Tc                 t   t                                          |          }|s|S t          | |          }	 |                    |           n# t          t
          f$ r |cY S w xY w|D ]M\  }}t          |d          r8|                    d                                          D ]\  }}|||d|<   N|S )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    gg  d ++ 	JT4((
	JJz"""":& 	 	 	 JJJ	  * 	8 	8OD)y,// 8"+"6"6D"6"A"A"G"G"I"I 8 8JC27CDDD##.//
s   A A%$A%c           	         ||v r$t          | ||                    |                     t          | |          }t          |t                    r|rt          t                    5  t          | \  }}t	          |                                          D ]4}d|vr.||v r*| 	                    |||                    |                     5	 d d d            n# 1 swxY w Y    t                      j        di | | S )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 0111d##eT"" 	Nu 	N )$$ N N #U
A // N ND4''DJ,>,>//dFJJt<L<LMMMNN N N N N N N N N N N N N N N 	$$V$$$s   %A#CCCc                     t          t          | |                    }t          |          D ]\  }\  }}||k    r	||f||<    nt          | ||           d S r   )r,   r   	enumerater)   )r   r   r"   new_valnew_estimatorsiestimator_namer3   s           r   r/   z#_BaseComposition._replace_estimatorN   sw    gdD1122&/&?&? 	 	"A"%%%)7Oq! & 	dN+++++r   c                    t          t          |                    t          |          k    r/t          d                    t	          |                              t          |                              |                     d                    }|r/t          d                    t          |                              d |D             }|r"t          d                    |                    d S )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}c                     g | ]}d |v |	S )r   r   ).0r"   s     r   
<listcomp>z4_BaseComposition._validate_names.<locals>.<listcomp>a   s    @@@$44<<<<<r   z.Estimator names must not contain __: got {0!r})lensetr   formatr,   intersectionr   sorted)r   namesinvalid_namess      r   _validate_namesz _BaseComposition._validate_namesW   s    s5zz??c%jj((CJJ4PU;;WWXXXE

//U0K0KLL 	LSS=))   
 A@%@@@ 	@GGVV  	 	r   )T)__name__
__module____qualname____doc__r   r   r'   r4   r/   rF   __classcell__)r&   s   @r   r   r      s        	 	   ^     ,    *, , ,      r   r   )	metaclassc                    t          |           j        j        rt          |d          st	          d          |j        d         |j        d         k    rt	          d          ||t          j        ||                   }n,|t          j        ||                   }nt          ||          }|t          ||          }n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   rN   npix_r   )r#   Xyindicestrain_indicesX_subsety_subsets          r   _safe_splitrZ   h   s    X 	%. .q'"" 	=  
 71:##ABBB 112HH778HH!!W--}!!W--Xr   r   )rJ   abcr   r   
contextlibr   numpyrR   sklearn.baser   sklearn.utilsr   sklearn.utils._available_ifr   sklearn.utils._tagsr	   __all__r   rZ   r   r   r   <module>rc      s    $ $
 ( ' ' ' ' ' ' '           & & & & & & ( ( ( ( ( ( 4 4 4 4 4 4 ( ( ( ( ( (
R R R R R} R R R RjA A A A A Ar   