ó
    Ñ]j¦  ã                   ó¦   • S r SSKrSSKrSSKJr  SSKrSSKJr  SSKJrJ	r	  Sq
S r " S S\R                  5      rS	 r " S
 S5      rS rSS jrg)zWCustomizations of :mod:`joblib` and :mod:`threadpoolctl` tools for scikit-learn
usage.
é    N)Úupdate_wrapper)ÚThreadpoolController)Úconfig_contextÚ
get_configc                 ó€   • [        U S5      (       a  U R                  X5      $ [        R                  " S[        5        U $ )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      ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/utils/parallel.pyÚ _with_config_and_warning_filtersr      s?   € äˆ|Ð>×?Ñ?Ø×;Ñ;¸FÓTÐTä�Šð7ô
 ô	
ð Ðó    c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )ÚParallelé)   aŸ  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                 óª   >^^• [        5       m[        [        SS5      nUb  U" 5       O[        R                  mUU4S jU 5       n[        TU ]  U5      $ )zø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   óJ   >#   • U  H  u  pn[        UTT5      UU4v •  M     g 7f©N)r   )Ú.0r   ÚargsÚkwargsr   r   s       €€r   Ú	<genexpr>Ú$Parallel.__call__.<locals>.<genexpr>S   s5   øé € ð 4
ò /7Ñ*� 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"   ÚParallel.__call__6   sX   ú€ ô$ “ˆô œx¨¸Ó>ˆà*Ñ6‰LŒN¼H×<LÑ<Lð 	õ4
ñ /7ó4
Ð0ô ‰wÑÐ HÓIÐIr   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   Ú__static_attributes__Ú__classcell__)r'   s   @r   r   r   )   s   ø† ñ
÷%Jó %Jr   r   c                 óF   ^ • [         R                  " T 5      U 4S j5       nU$ )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5      X4$ r   )Ú_FuncWrapper)r   r   Úfunctions     €r   Údelayed_functionÚ!delayed.<locals>.delayed_functiony   s   ø€ ä˜HÓ% tÐ3Ð3r   ©Ú	functoolsÚwraps)r4   r5   s   ` r   Údelayedr:   _   s(   ø€ ô4 ‡_‚_�XÓô4ó ð4ð Ðr   c                   ó*   • \ rS rSrSrS rS rS rSrg)r3   é€   z:Load the global configuration before calling the function.c                 ó:   • Xl         [        X R                   5        g r   )r4   r   )r#   r4   s     r   Ú__init__Ú_FuncWrapper.__init__ƒ   s   € Ø ŒÜ�tŸ]™]Õ+r   c                 ó   • Xl         X l        U $ r   )r   r   )r#   r   r   s      r   r   Ú,_FuncWrapper.with_config_and_warning_filters‡   s   € ØŒØ.ÔØˆr   c           	      ó  • [        U S0 5      n[        U S/ 5      nU(       a  U(       d  [        R                  " S[        5        [	        S
0 UD6   [        R
                  " 5          [        R                  " 5         / SQnU H­  n[        XV5       VVs0 s H  u  pxUc  M
  Xx_M     n	nnSU	;  a"  SU	;  a  [        R                  " S
0 U	DSS0D6  MO  S	 H>  n
U	R                  U
5      nUc  M  [        U[        5      (       a  M0  UR                  Xš'   M@     [        R                  " S
0 U	DSS0D6  M¯     U R                  " U0 UD6sS S S 5        sS S S 5        $ s  snnf ! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f)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ÚlinenorD   rF   ÚappendT)rD   rF   r)   )r   r
   r   r   r   Úcatch_warningsÚresetwarningsÚzipÚsimplefilterÚgetÚ
isinstanceÚstrÚpatternÚfilterwarningsr4   )r#   r   r   r   r   Úwarning_filter_keysÚfilter_argsÚkÚvÚthis_warning_filter_dictÚspecial_keyÚ
this_values               r   r"   Ú_FuncWrapper.__call__Œ   s\  € Ü˜˜x¨Ó,ˆÜ! $Ð(9¸2Ó>ˆÞž_Ü�MŠMð+ô
 ôô Ñ%˜fÓ%¤x×'>Ò'>Õ'@ä×"Ò"Ô$Ú"WÐÛ.�ô !$Ð$7Ô Eô,â E™˜Øó �A’DÙ Eð )ñ ,ð Ð%=Ó=Ø Ð(@Ó@ä×)Ò)ÑRÐ,DÑRÈTÕRó (=˜Ø%=×%AÑ%AÀ+Ó%N˜
Ø%Ó1¼*ÀZÔQT×:UÓ:UØDN×DVÑDVÐ4ÓAñ (=ô
 ×+Ò+ÑTÐ.FÑTÈtÕTñ1  /ð4 —=’= $Ð1¨&Ñ1÷= (AÐ'@×%Ñ%ùó
,÷ (AÕ'@ú×%×%Ö%úsJ   ÁE6Á%-EÂ	EÂEÂ%AEÃ+EÄAEÅ	E6ÅEÅ
E*	Å&E6Å6
F)r   r4   r   N)	r*   r+   r,   r-   r.   r>   r   r"   r/   r)   r   r   r3   r3   €   s   † ÙDò,òõ
,2r   r3   c                  ó0   • [         c
  [        5       q [         $ )z1Return the global threadpool controller instance.)Ú_threadpool_controllerr   r)   r   r   Ú_get_threadpool_controllerr\   »   s   € ô Ñ%Ü!5Ó!7Ðä!Ð!r   c                 ó   ^ ^• U U4S jnU$ )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                 óL   >^ • [         R                  " T 5      U UU4S j5       nU$ )Nc                  ó~   >• [        5       nUR                  TTS9   T" U 0 UD6sS S S 5        $ ! , (       d  f       g = f)N)ÚlimitsÚuser_api)r\   Úlimit)r   r   Ú
controllerÚfuncr`   ra   s      €€€r   ÚwrapperÚD_threadpool_controller_decorator.<locals>.decorator.<locals>.wrapperÎ   s8   ø€ ä3Ó5ˆJØ×!Ñ!¨¸(Ð!ÒCÙ˜TÐ, VÑ,÷ D×C×Cús   œ.®
<r7   )rd   re   r`   ra   s   ` €€r   Ú	decoratorÚ3_threadpool_controller_decorator.<locals>.decoratorÍ   s%   ù€ Ü	�Š˜Ó	ö	-ó 
ð	-ð
 ˆr   r)   )r`   ra   rg   s   `` r   Ú _threadpool_controller_decoratorri   Å   s   ù€ öð Ðr   )é   Úblas)r.   r8   r
   r   ÚjoblibÚthreadpoolctlr   Úsklearn._configr   r   r[   r   r   r:   r3   r\   ri   r)   r   r   Ú<module>ro      sY   ðñó Û Ý $ã Ý .ç 6ð Ð òô"2Jˆv�‰ô 2Jòl÷B82ñ 82òv"õr   