`L idZddlZddlZddlmZddlZddlmZddlmZm Z da dZ Gdd ejZ d Z Gd d Zd ZddZy)zWCustomizations of :mod:`joblib` and :mod:`threadpoolctl` tools for scikit-learn usage. N)update_wrapper)ThreadpoolController)config_context get_configcvt|dr|j||Stjdt|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 warningswarn UserWarning) delayed_funcconfigwarning_filterss \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/parallel.py _with_config_and_warning_filtersrs>|>?;;FOTT 7  c"eZdZdZfdZxZS)ParallelaTweak 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 crttjfd|D}t||S)aHDispatch 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. c3FK|]\}}}t|||fywN)r).0rargskwargsrrs r z$Parallel.__call__..Js54 + dF 1vW 4 s!)rr filterssuper__call__)selfiterable(iterable_with_config_and_warning_filtersrr __class__s @@rrzParallel.__call__6s<$"**4 /7 4 0w HIIr)__name__ __module__ __qualname____doc__r __classcell__)r#s@rrr)s JJrrcBtjfd}|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||fSr) _FuncWrapper)rrfunctions rdelayed_functionz!delayed..delayed_functionpsH%tV33r functoolswraps)r,r-s` rdelayedr1Vs(4__X44 rc"eZdZdZdZdZdZy)r+z:Load the global configuration before calling the function.c>||_t||jyr)r,r)r r,s r__init__z_FuncWrapper.__init__zs  tT]]+rc"||_||_|Sr)rr)r rrs rr z,_FuncWrapper.with_config_and_warning_filters~s . rcTt|di}t|dg}|r|stjdtt di|5tj 5|t_|j|i|cdddcdddS#1swYnxYwdddy#1swYyxYw)Nrrz`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.)getattrr r r rcatch_warningsrr,)r rrrrs rrz_FuncWrapper.__call__sx,!$(92>_ MM+   %f % 2x'>'>'@ 2.H  4==$1&1 2 2 2 2 2 2 2s$BB 6 B B BB'N)r$r%r&r'r4r rr7rrr+r+wsD, 2rr+c.t tatS)z1Return the global threadpool controller instance.)_threadpool_controllerrr7rr_get_threadpool_controllerr<s%!5!7 !!rcfd}|S)aDecorator 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. cHtjfd}|S)Nczt}|j5|i|cdddS#1swYyxYw)N)limitsuser_api)r<limit)rr controllerfuncr@rAs rwrapperzD_threadpool_controller_decorator..decorator..wrappers@35J!!(!C -T,V, - - -s1:r.)rDrEr@rAs` r decoratorz3_threadpool_controller_decorator..decorators%   -  - rr7)r@rArFs`` r _threadpool_controller_decoratorrGs r)blas)r'r/r rjoblib threadpoolctlr_configrrr;rrr1r+r<rGr7rrrMsX$ .0 ")Jv)JZB22>"r