Ë
    êÿæi¦  ã                   ó¤   — d Z ddlZddlZddlmZ ddlZddlmZ ddlmZm	Z	 da
d„ Z G d„ dej                  «      Zd	„ Z G d
„ d«      Zd„ Zdd„Zy)zWCustomizations of :mod:`joblib` and :mod:`threadpoolctl` tools for scikit-learn
usage.
é    N)Úupdate_wrapper)ÚThreadpoolController)Úconfig_contextÚ
get_configc                 óv   — t        | d«      r| j                  ||«      S t        j                  dt        «       | S )zFHelper function that intends to attach a config to a delayed function.Úwith_config_and_warning_filterszÐ`sklearn.utils.parallel.Parallel` needs to be used in conjunction with `sklearn.utils.parallel.delayed` instead of `joblib.delayed` to correctly propagate the scikit-learn configuration to the joblib workers.)Úhasattrr   ÚwarningsÚwarnÚUserWarning)Údelayed_funcÚconfigÚwarning_filterss      úk/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/sklearn/utils/parallel.pyÚ _with_config_and_warning_filtersr      s>   € äˆ|Ð>Ô?Ø×;Ñ;¸FÀOÓTÐTä�‰ð7ô
 ô	
ð Ðó    c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚParallela»  Tweak of :class:`joblib.Parallel` that propagates the scikit-learn configuration.

    This subclass of :class:`joblib.Parallel` ensures that the active configuration
    (thread-local) of scikit-learn is propagated to the parallel workers for the
    duration of the execution of the parallel tasks.

    The API does not change and you can refer to :class:`joblib.Parallel`
    documentation for more details.

    .. versionadded:: 1.3
    c                 ó¦   •‡‡— t        «       Št        t        dd«      }|� |«       nt        j                  Šˆˆfd„|D «       }t        ‰| �  |«      S )aH  Dispatch the tasks and return the results.

        Parameters
        ----------
        iterable : iterable
            Iterable containing tuples of (delayed_function, args, kwargs) that should
            be consumed.

        Returns
        -------
        results : list
            List of results of the tasks.
        Ú_get_filtersNc              3   óF   •K  — | ]  \  }}}t        |‰‰«      ||f–— Œ y ­w©N)r   )Ú.0r   ÚargsÚkwargsr   r   s       €€r   Ú	<genexpr>z$Parallel.__call__.<locals>.<genexpr>S   s8   øè ø€ ð 4
ñ /7Ñ*�˜d Fô	 1°¸vÀÓWØØôñ
 /7ùs   ƒ!)r   Úgetattrr
   ÚfiltersÚsuperÚ__call__)ÚselfÚiterableÚfilters_funcÚ(iterable_with_config_and_warning_filtersr   r   Ú	__class__s       @@€r   r    zParallel.__call__6   sX   ú€ ô$ “ˆô œx¨¸Ó>ˆà*Ð6‰LŒN¼H×<LÑ<Lð 	ô4
ñ /7ó4
Ð0ô ‰wÑÐ HÓIÐIr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    Ú__classcell__)r%   s   @r   r   r   )   s   ø„ ñ
÷%Jð %Jr   r   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )a^  Decorator used to capture the arguments of a function.

    This alternative to `joblib.delayed` is meant to be used in conjunction
    with `sklearn.utils.parallel.Parallel`. The latter captures the scikit-
    learn configuration by calling `sklearn.get_config()` in the current
    thread, prior to dispatching the first task. The captured configuration is
    then propagated and enabled for the duration of the execution of the
    delayed function in the joblib workers.

    .. versionchanged:: 1.3
       `delayed` was moved from `sklearn.utils.fixes` to `sklearn.utils.parallel`
       in scikit-learn 1.3.

    Parameters
    ----------
    function : callable
        The function to be delayed.

    Returns
    -------
    output: tuple
        Tuple containing the delayed function, the positional arguments, and the
        keyword arguments.
    c                  ó    •— t        ‰«      | |fS r   )Ú_FuncWrapper)r   r   Úfunctions     €r   Údelayed_functionz!delayed.<locals>.delayed_functiony   s   ø€ ä˜HÓ% t¨VÐ3Ð3r   ©Ú	functoolsÚwraps)r.   r/   s   ` r   Údelayedr3   _   s(   ø€ ô4 ‡_�_�XÓó4ó ð4ð Ðr   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)r-   z:Load the global configuration before calling the function.c                 ó>   — || _         t        | | j                   «       y r   )r.   r   )r!   r.   s     r   Ú__init__z_FuncWrapper.__init__ƒ   s   € Ø ˆŒÜ�t˜TŸ]™]Õ+r   c                 ó"   — || _         || _        | S r   )r   r   )r!   r   r   s      r   r   z,_FuncWrapper.with_config_and_warning_filters‡   s   € ØˆŒØ.ˆÔØˆr   c           	      ó¶  — t        | di «      }t        | dg «      }|r|st        j                  dt        «       t	        d
i |¤Ž5  t        j
                  «       5  t        j                  «        g d¢}|D ]™  }t        ||«      D ��ci c]
  \  }}|�||“Œ }	}}d|	vrd|	vrt        j                  d
i |	¤ddi¤Ž ŒFd	D ]6  }
|	j                  |
«      }|€Œt        |t        «      rŒ(|j                  |	|
<   Œ8 t        j                  d
i |	¤ddi¤Ž Œ›  | j                  |i |¤Žcd d d «       cd d d «       S c c}}w # 1 sw Y   nxY wd d d «       y # 1 sw Y   y xY w)Nr   r   zÃ`sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel` to make it possible to propagate the scikit-learn configuration of the current thread to the joblib workers.)ÚactionÚmessageÚcategoryÚmoduleÚlinenor:   r<   ÚappendT)r:   r<   © )r   r
   r   r   r   Úcatch_warningsÚresetwarningsÚzipÚsimplefilterÚgetÚ
isinstanceÚstrÚpatternÚfilterwarningsr.   )r!   r   r   r   r   Úwarning_filter_keysÚfilter_argsÚkÚvÚthis_warning_filter_dictÚspecial_keyÚ
this_values               r   r    z_FuncWrapper.__call__Œ   sc  € Ü˜˜x¨Ó,ˆÜ! $Ð(9¸2Ó>ˆÙ™_Ü�M‰Mð+ô
 ôô Ñ%˜fÓ%¤x×'>Ñ'>Õ'@ä×"Ñ"Ô$Ú"WÐÛ.�ô !$Ð$7¸Ô Eô,á E™˜˜1Ø�}ð �q‘DØ Eð )ñ ,ð Ð%=Ñ=Ø Ð(@Ñ@ä×)Ñ)ÑRÐ,DÑRÈTÔRó (=˜Ø%=×%AÑ%AÀ+Ó%N˜
Ø%Ñ1¼*ÀZÔQTÕ:UØDN×DVÑDVÐ4°[ÒAð (=ô
 ×+Ñ+ÑTÐ.FÑTÈtÔTð1  /ð4 !�4—=‘= $Ð1¨&Ñ1÷= (AÐ'@×%Ñ%ùó
,÷ (AÐ'@ú×%×%Ñ%úsB   ÁEÁ-D:ÂD4Â=D:ÃD:Ã$=D:Ä!	EÄ4D:Ä:E	Ä?EÅEN)r&   r'   r(   r)   r6   r   r    r?   r   r   r-   r-   €   s   „ ÙDò,òó
,2r   r-   c                  ó.   — t         €
t        «       a t         S )z1Return the global threadpool controller instance.)Ú_threadpool_controllerr   r?   r   r   Ú_get_threadpool_controllerrR   »   s   € ô Ð%Ü!5Ó!7Ðä!Ð!r   c                 ó   ‡ ‡— ˆ ˆfd„}|S )a  Decorator to limit the number of threads used at the function level.

    It should be preferred over `threadpoolctl.ThreadpoolController.wrap` because this
    one only loads the shared libraries when the function is called while the latter
    loads them at import time.
    c                 óH   •‡ — t        j                  ‰ «      ˆ ˆˆfd„«       }|S )Nc                  óz   •— t        «       }|j                  ‰‰¬«      5   ‰| i |¤Žcd d d «       S # 1 sw Y   y xY w)N)ÚlimitsÚuser_api)rR   Úlimit)r   r   Ú
controllerÚfuncrV   rW   s      €€€r   ÚwrapperzD_threadpool_controller_decorator.<locals>.decorator.<locals>.wrapperÎ   s8   ø€ ä3Ó5ˆJØ×!Ñ!¨¸(Ð!ÕCÙ˜TÐ, VÑ,÷ D×CÒCús   Ÿ1±:r0   )rZ   r[   rV   rW   s   ` €€r   Ú	decoratorz3_threadpool_controller_decorator.<locals>.decoratorÍ   s%   ù€ Ü	�‰˜Ó	õ	-ó 
ð	-ð
 ˆr   r?   )rV   rW   r\   s   `` r   Ú _threadpool_controller_decoratorr]   Å   s   ù€ õð Ðr   )é   Úblas)r)   r1   r
   r   ÚjoblibÚthreadpoolctlr   Úsklearn._configr   r   rQ   r   r   r3   r-   rR   r]   r?   r   r   Ú<module>rc      sY   ðñó Û Ý $ã Ý .ç 6ð Ð òô"2Jˆv�‰ô 2Jòl÷B82ñ 82òv"ôr   