
    -i                         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      I/var/www/html/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                 t   >^^ [        5       m[        R                  mUU4S jU 5       n[        TU ]  U5      $ )zDispatch 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.
c              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>J   s5      4
 /7*F	 1vW
 /7s    #)r   r   filterssuper__call__)selfiterable(iterable_with_config_and_warning_filtersr   r   	__class__s      @@r   r!   Parallel.__call__6   s<    $ "**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_functionp   s    H%t33r   	functoolswraps)r2   r3   s   ` r   delayedr8   V   s(    4 __X4 4 r   c                   *    \ rS rSrSrS rS rS rSrg)r1   w   z:Load the global configuration before calling the function.c                 :    Xl         [        X R                   5        g r   )r2   r   )r"   r2   s     r   __init___FuncWrapper.__init__z   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          U[        l        U R                  " U0 UD6sS S S 5        sS S S 5        $ ! , (       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.r'   )getattrr   r   r   r   catch_warningsr   r2   )r"   r   r   r   r   s        r   r!   _FuncWrapper.__call__   s    x,!$(92>_MM+
  %f%x'>'>'@.H==$1&1 (A'@%%'@'@%%%s$   B/%B	B/
B#	B//
B=)r   r2   r   N)	r(   r)   r*   r+   r,   r<   r	   r!   r-   r'   r   r   r1   r1   w   s    D,
2r   r1   c                  0    [         c
  [        5       q [         $ )z1Return the global threadpool controller instance.)_threadpool_controllerr   r'   r   r   _get_threadpool_controllerrF      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)rF   limit)r   r   
controllerfuncrJ   rK   s      r   wrapperD_threadpool_controller_decorator.<locals>.decorator.<locals>.wrapper   s8    35J!!(!CT,V, DCCs   .
<r5   )rN   rO   rJ   rK   s   ` r   	decorator3_threadpool_controller_decorator.<locals>.decorator   s%    			- 
	-
 r   r'   )rJ   rK   rQ   s   `` r    _threadpool_controller_decoratorrS      s     r   )   blas)r,   r6   r   r   joblibthreadpoolctlr   _configr   r   rE   r   r   r8   r1   rF   rS   r'   r   r   <module>rY      sX      $  . 0  ")Jv )JZB2 2>"r   