
     hT                         d dl Z d dlmZ d dlZd dlmZmZmZ d dlm	Z	m
Z
 d Zd Zd Zd Zej                            d	g d
          d             Zd ZdS )    N)ThreadPoolExecutor)
get_config
set_configconfig_context)delayedParallelc                  f   t                      dddddddddk    sJ t          d           t                      d	         du sJ t          d          5  t                      dddddddddk    sJ 	 d d d            n# 1 swxY w Y   t                      d	         du sJ t          d          5  t          d           5  t                      d	         du sJ 	 d d d            n# 1 swxY w Y   t                      d	         du sJ t          d          5  t                      d	         du sJ t          d           5  t                      d	         du sJ t          d           t                      d	         du sJ 	 d d d            n# 1 swxY w Y   t                      d	         du sJ 	 d d d            n# 1 swxY w Y   t                      d	         du sJ 	 d d d            n# 1 swxY w Y   t                      dddddddddk    sJ t          j        t
                    5  t          d           d d d            n# 1 swxY w Y   t          j        t
                    5  t          d
                                           d d d            d S # 1 swxY w Y   d S )NFi   Tdiagram   default)assume_finiteworking_memoryprint_changed_onlydisplayarray_api_dispatchpairwise_dist_chunk_sizeenable_cython_pairwise_disttransform_outputr   r   do_something_else)r   r   r   pytestraises	TypeError	__enter__     U/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/tests/test_config.pytest_config_contextr   
   s   <<"#$''+%	 	 	 	 	 	 &&&&<<(E1111	d	+	+	+ 

 

||!""& "'(++/ )	 
 	 
 	
 	
 	
 	
 	


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 <<(E1111	d	+	+	+ 5 5$/// 	9 	9<<0D88888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 ||O,4444%000 	: 	:<<0E9999d333 = =!||O4==== ....!||O4<<<<<= = = = = = = = = = = = = = = <<0E99999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: ||O,44444'5 5 5 5 5 5 5 5 5 5 5 5 5 5 5* <<"#$''+%	 	 	 	 	 	 
y	!	!  t               
y	!	! ; ;...88:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   BBB4G5C+G5+C/	/G52C/	3+G5)GAF	GFGFG9G5G			G5G		G55G9<G96III6#J&&J*-J*c                     t                      d         du sJ 	 t          d          5  t                      d         du sJ t                      # 1 swxY w Y   n# t          $ r Y nw xY wt                      d         du sJ d S )Nr   FTr   )r   r   
ValueErrorr   r   r   test_config_context_exceptionr"   P   s    <<(E1111$/// 	 	<<0D8888,,	 	 	 	 	 	 	 	 	    <<(E111111s.   A 'AAA AA 
A*)A*c                     t                      d         du sJ t          d            t                      d         du sJ t          d           t                      d         du sJ t          d            t                      d         du sJ t          d           t                      d         du sJ t          j        t                    5  t          d           d d d            d S # 1 swxY w Y   d S )Nr   Fr   Tr   )r   r   r   r   r   r   r   r   test_set_configr$   [   sO   <<(E1111T""""<<(E1111T""""<<(D0000T""""<<(D0000U####<<(E1111 
y	!	! + +T****+ + + + + + + + + + + + + + + + + +s   C00C47C4c                     t          |           5  t          j        |           t                      d         cddd           S # 1 swxY w Y   dS )zAReturn the value of assume_finite after waiting `sleep_duration`.r   r   N)r   timesleepr   )r   sleep_durations     r   set_assume_finiter)   k   s    	m	4	4	4 - -
>"""||O,- - - - - - - - - - - - - - - - - -s   (AA
A
backend)lokymultiprocessing	threadingc                     g d}g d} t          | d          d t          ||          D                       }|g dk    sJ dS )ao  Test that the global config is threadsafe with all joblib backends.
    Two jobs are spawned and sets assume_finite to two different values.
    When the job with a duration 0.1s completes, the assume_finite value
    should be the same as the value passed to the function. In other words,
    it is not influenced by the other job setting assume_finite to True.
    FTFT皙?皙?r1   r2      )r*   n_jobsc              3   X   K   | ]%\  }} t          t                    ||          V  &d S )N)r   r)   ).0r   	sleep_durs      r   	<genexpr>z0test_config_threadsafe_joblib.<locals>.<genexpr>}   sO       0 0$M9 	#!""=)<<0 0 0 0 0 0r   N)r   zip)r*   assume_finitessleep_durationsitemss       r   test_config_threadsafe_joblibr=   r   s~     0//N***O/HWQ/// 0 0(+NO(L(L0 0 0  E
 .........r   c                      g d} g d}t          d          5 }d |                    t          | |          D             }ddd           n# 1 swxY w Y   |g dk    sJ dS )zUses threads directly to test that the global config does not change
    between threads. Same test as `test_config_threadsafe_joblib` but with
    `ThreadPoolExecutor`.r/   r0   r3   )max_workersc                     g | ]}|S r   r   )r6   outputs     r   
<listcomp>z*test_config_threadsafe.<locals>.<listcomp>   s(     
 
 
 
 
 
r   N)r   mapr)   )r:   r;   er<   s       r   test_config_threadsaferE      s    
 0//N***O		*	*	* 
a
 
%% 1>?SS
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 .........s   'AAA)r&   concurrent.futuresr   r   sklearnr   r   r   sklearn.utils.parallelr   r   r   r"   r$   r)   markparametrizer=   rE   r   r   r   <module>rK      s     1 1 1 1 1 1  : : : : : : : : : : 4 4 4 4 4 4 4 4C; C; C;L2 2 2+ + + - - - $L$L$LMM/ / NM/$/ / / / /r   