
    0Ph                        d dl Z d dlZd dlmZ d dlZd dlZd dlmZmZmZ d dl	m
Z
 d dlmZmZ d Zd Zd Zd	 Zej                            d
g d          d             Zej                            e
d          d             Zd Zd ZdS )    N)ThreadPoolExecutor)config_context
get_config
set_config)_IS_WASM)Paralleldelayedc                  r   t                      dd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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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enable_metadata_routingskip_parameter_validationr   r   do_something_else)r   r   r   pytestraises	TypeError	__enter__     Y/var/www/html/test/jupyter/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	8G9	C/#G9/C3	3G96C3	7+G9")G	AFG	FG	 F!G	=G9	G	G9G	G99G= G=<III<#J,,J03J0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%   Y   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'   d   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,   t   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皙?皙?r4   r5      )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@   {   s~     0//N***O/HWQ/// 0 0(+NO(L(L0 0 0  E
 .........r    zcannot start threads)reasonc                      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`.r2   r3   r6   )max_workersc                     g | ]}|S r   r   )r9   outputs     r!   
<listcomp>z*test_config_threadsafe.<locals>.<listcomp>   s(     
 
 
 
 
 
r    N)r   mapr,   )r=   r>   er?   s       r!   test_config_threadsaferI      s     0//N***O		*	*	* 
a
 
%% 1>?SS
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 .........s   'AAAc                    t           j        fd}|                     t           d|           t          j        t
          d          5  t          d          5  	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        t
          d          5  t          d           ddd           dS # 1 swxY w Y   dS )z=Check error is raised when array_api_compat is not installed.c                 6    | dk    rt            | g|R i |S Narray_api_compat)ImportErrornameargskwargsorig_imports      r!   mocked_importz;test_config_array_api_dispatch_error.<locals>.mocked_import   s5    %%%{41$111&111r    
__import__zarray_api_compat is requiredmatchTr   N)builtinsrU   setattrr   r   rN   r   r   monkeypatchrT   rS   s     @r!   $test_config_array_api_dispatch_errorr]      s    %K2 2 2 2 2
 ,>>>	{*H	I	I	I  t444 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	               
{*H	I	I	I , ,d++++, , , , , , , , , , , , , , , , , ,sH   
B A)B )A-	-B 0A-	1B  BB&CCCc                    t           j        fd}|                     t           d|           |                     t          j        j        j        dd           t          j        t          d          5  t          d          5  	 d	d	d	           n# 1 swxY w Y   d	d	d	           n# 1 swxY w Y   t          j        t          d          5  t          d           d	d	d	           d	S # 1 swxY w Y   d	S )
z!Check error when NumPy is too oldc                 D    | dk    rt                      S  | g|R i |S rL   )objectrO   s      r!   rT   zAtest_config_array_api_dispatch_error_numpy.<locals>.mocked_import   s8    %%%88O{41$111&111r    rU   __version__z1.20zNumPy must be 1.21 or newerrV   TrX   N)rY   rU   rZ   sklearnutils
_array_apinumpyr   r   rN   r   r   r[   s     @r!   *test_config_array_api_dispatch_error_numpyrf      s    %K2 2 2 2 2
 ,>>>06vNNN	{*G	H	H	H  t444 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	               
{*G	H	H	H , ,d++++, , , , , , , , , , , , , , , , , ,sH   5B+BB+B	B+B	B++B/2B/C//C36C3)rY   r)   concurrent.futuresr   r   rb   r   r   r   sklearn.utils.fixesr   sklearn.utils.parallelr   r	   r"   r%   r'   r,   markparametrizer@   xfailrI   r]   rf   r   r    r!   <module>rm      sS     1 1 1 1 1 1   : : : : : : : : : : ( ( ( ( ( ( 4 4 4 4 4 4 4 4I; I; I;X2 2 2+ + + - - - $L$L$LMM/ / NM/$ 8$:;;/ / <;/", , ,*, , , , ,r    