
    J/Ph                     z   d Z ddlZddlZddlmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlZddlZddlZddlmZ ddlZddl m!Z!mZ ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) dd	l*m+Z+m,Z,m-Z-m.Z.m/Z/ dd
l0m1Z1 ddl2m3Z3 ddl4Z4ddl5m6Z6 ddl7m8Z8 ddl5m9Z: ddl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZC 	 ddlDZDn# eE$ r dZDY nw xY w	 ddlFZF eFjG                     n# eE$ r Y nw xY w e,            ZHdeH_I         e,            ZJdeJ_K         e,            ZL e,            ZMdeM_N         e!jO        g d          ZP ePd          ZQejR        dk    ZSeSZT e4jU        eTd          ZV e4jW        e%jX        dk    d          ZY e4jW        e%jX        dk    d          ZZ e4jW        e%jX        dk    d          Z[ e4jU        eSd          Z\e8j]        dk    Z^ e4jU        e^d          Z_d Z`d Zad  Zbd! Zcd"Zd e4jU        eDdu ed          Ze e4jW        e)jf        d#          Zgd$Zh e4jU        ej        i                    d%           eh          Zjd&Zk e4jU        ej        i                    d'           ek          Zl ejm                    d(k    Zn e4jU        dd)          Zo e4jU         ejm                    d*k    d+          Zp eqe	jr        s                    d,d                    Zt e4jW        etd-          Zu e4jU        etd.          Zv e4jU         ejm                    d*k    d/          Zw e4jU         ejm                    d*k    d0          Zx ejy                    Zzezj{        d1k    Z| e4jU        e|d2          Z}e|o
ezjm        d3k    Z~	 ddlZDdZn# eE$ r d4ZY nw xY w e4jW        ed5          Z	 ddlZDdZn# eE$ r d4ZY nw xY w e4jW        ed6          Ze	jr        s                    d7d          d8k    Z e4jW        ed9          Z	 ddlZdZn# eE$ r d4ZY nw xY w e4jW        ed:          Zd; Z G d< d=e4j                  Z G d> d?e          Zej        d@             Zej        dA             ZdB ZdCZe	j        dDk    r)e	j                             ej                    e          Zn:e	j                             ej                    edE e	j                              ZdFZdG ZdH ZdI ZdJ ZdK Zej        dL             ZdM ZdN Zej        dO             Z G dP dQe          Z G dR dSe          Z G dT dUee          Zej        dV             Zej        dW             ZdX ZdY ZedfdZZdid[Zd\ Z G d] d^e          Zd_ Zej        d`             ZdjdbZdkddZde Z G df dge.          Zdh ZdS )lz&
Assorted utilities for use in tests.
    N)defaultdict)contextmanager)cached_property)testingtypes)errorstypingutilsconfigcpu)
cffi_utils)compile_extraFlagsDEFAULT_FLAGSCompilerBaseDefaultPassBuilder)IRLegalization)
PreserveIR)rtsys)numpy_support)_nrt_python)overload_methodtypeof_implregister_modelunboxNativeValuemodels)OpaqueModelT)	importantlong_runningalways_testr!           zparfors not supported)   
   zneeds Python 3.10 or laterzneeds Python 3.10r#      zneeds Python 3.12zNot supported on 32 bit   r   zNot supported on numpy 2.0+c                 N    t           j        dk    rt          j        |           S | S )N)r#      r
   	PYVERSIONunittestexpectedFailurefns    S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/support.pyexpected_failure_py311r2   q   %    '!!'+++	    c                 N    t           j        dk    rt          j        |           S | S )Nr%   r+   r/   s    r1   expected_failure_py312r6   x   r3   r4   c                 N    t           j        dk    rt          j        |           S | S )N)r#      r+   r/   s    r1   expected_failure_py313r9      r3   r4   c                 N    t           j        dk    rt          j        |           S | S )Nr'   )r   numpy_versionr-   r.   r/   s    r1   expected_failure_np2r<      s&    "f,,'+++	r4   zSciPy needed for testzrequires cffizlinux only testlinuxzWindows-only testwinarmv7lzTest disabledppc64lez?Hits: 'Parameter area must exist to pass an argument in memory'NUMBA_USE_TYPEGUARDzTypeguard is not enabledzBroken if Typeguard is enabledz>Hits: 'mismatch in size of parameter area' in LowerCall_64SVR4zInvalid PPC CTR loopDarwinz-fenv.h-like functionality unreliable on macOSarm64FzLAPACK needs SciPy 1.0+zBLAS needs SciPy 1.0+SUBPROC_TEST1zneeds subprocess harnesszTest needs setuptoolsc                  v    t          j        dd           t          j        ddt          j        d           dS )zUse in testing within a ` warnings.catch_warnings` block to filter out
    warnings that are unrelated/internally generated by Numba.
    ignore	typeguard)modulez.*TBB_INTERFACE_VERSION.*znumba\.np\.ufunc\.parallel.*)actionmessagecategoryrI   N)warningsfilterwarningsr   NumbaWarning r4   r1   ignore_internal_warningsrQ      sR    
 H[99998$@%+%8#BD D D D D Dr4   c                   n   e Zd ZdZed             Zd Zej        d             Z	ej        d             Z
d Zej        d             Zeej        fZeefefej        feej        fgZefefej        gZeefgZeej        fZeej         fZ!d Z"d	 Z#d
 Z$d Z%	 	 	 ddZ&	 	 	 ddZ'	 	 	 ddZ(ddZ)d Z*d Z+dS )TestCaseTc                 @    t           j                            d          S )N*   )nprandomRandomStateselfs    r1   rW   zTestCase.random   s    y$$R(((r4   c                 |    t          |t                    rt          j        |         }	 |`dS # t
          $ r Y dS w xY w)z
        Reset the warnings registry of a module.  This can be necessary
        as the warnings module is buggy in that regard.
        See http://bugs.python.org/issue4180
        N)
isinstancestrsysmodules__warningregistry__AttributeError)rZ   rI   s     r1   reset_module_warningszTestCase.reset_module_warnings   sU     fc"" 	)[(F	*** 	 	 	DD	s   - 
;;c              #      K   t           j        t           j        t          t          f}|                     |          5 }|V  ddd           dS # 1 swxY w Y   dS )zr
        A context manager that asserts the enclosed code block fails
        compiling in nopython mode.
        N)r   LoweringErrorTypingError	TypeErrorNotImplementedErrorassertRaises)rZ   _accepted_errorscms      r1   assertTypingErrorzTestCase.assertTypingError	  s       #0&2D%':</00 	BHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc              '      K   d |D             }dV  t          j                     d |D             }t          |||          D ]'\  }}}||k    r|                     d|||fz             (dS )z
        A context manager that asserts the given objects have the
        same reference counts before and after executing the
        enclosed block.
        c                 6    g | ]}t          j        |          S rP   r^   getrefcount.0xs     r1   
<listcomp>z+TestCase.assertRefCount.<locals>.<listcomp>  "    ===++===r4   Nc                 6    g | ]}t          j        |          S rP   rn   rp   s     r1   rs   z+TestCase.assertRefCount.<locals>.<listcomp>  rt   r4   z-Refcount changed from %d to %d for object: %r)gccollectzipfail)rZ   objectsold_refcountsnew_refcountsoldnewobjs          r1   assertRefCountzTestCase.assertRefCount  s       >=W===

==W=== wGG 	- 	-MCcczz		I #sO, - - -	- 	-r4   c           
          t          j                     d |D             }|d         }t          t          |                    dd          D ]/}||         }||k    r|                     d| d| d| d           0d S )Nc                 6    g | ]}t          j        |          S rP   rn   rp   s     r1   rs   z0TestCase.assertRefCountEqual.<locals>.<listcomp>&  s"    222Qcoa  222r4   r      z(Refcount for objects does not match. #0(z) != #(z) does not match.)rv   rw   rangelenry   )rZ   rz   rcrc_0irc_is         r1   assertRefCountEqualzTestCase.assertRefCountEqual$  s    

22'222!us7||$$QRR( 	I 	IAa5Dt||		 H $H H,-H H04H H H I I I	I 	Ir4   c              #   2  K   t          j                    }dV  t          j                    }|j        |j        z
  }|j        |j        z
  }|j        |j        z
  }|j        |j        z
  }|                     ||d           |                     ||d           dS )z|
        A context manager that asserts no NRT leak was created during
        the execution of the enclosed block.
        Nz-number of data allocs != number of data freesz3number of meminfo allocs != number of meminfo frees)r   get_allocation_statsallocfreemi_allocmi_freeassertEqualrZ   r}   r~   total_alloc
total_freetotal_mi_alloctotal_mi_frees          r1   assertNoNRTLeakzTestCase.assertNoNRTLeak.  s       (**(**i#)+X(
4ck1jH	J 	J 	JN	P 	P 	P 	P 	Pr4   c                 ^   t          |t          j                  rdS t          |t          j                  rdS | j        D ]}t          ||          r dS | j        D ]}t          ||          r dS | j        D ]}t          ||          r dS | j        D ]}t          ||          r dS dS )z
        This function returns a string description of the type family
        that the object in question belongs to.  Possible return values
        are: "exact", "complex", "approximate", "sequence", and "unknown"
        ndarrayenumsequenceexactcomplexapproximateunknown)	r\   rV   r   r   Enum_sequence_typesets_exact_typesets_complex_types_approx_typesets)rZ   numeric_objecttps      r1   _detect_familyzTestCase._detect_familyI  s    nbj11 	9ndi00 	6) 	" 	"B."-- "!zz" & 	 	B."-- ww % 	! 	!B."-- ! yy! ' 	% 	%B."-- %$}}% yr4   c                     t           j        dk    r<t           j        dk    r,|t          j        d          k    rt          j        d          S |S )z7
        Fix the given *dtype* for comparison.
        win32r"   int32int64)r^   platformmaxsizerV   dtype)rZ   r   s     r1   
_fix_dtypezTestCase._fix_dtypeg  sG     LG##e(;(;RXg&&&&8G$$$Lr4   c                 |    j         dk    rdgj        z  S fdt          j        j                  D             S )z
        Return the strides of the given array, fixed for comparison.
        Strides for 0- or 1-sized dimensions are ignored.
        r   c                 6    g | ]\  }}|d k    |j         z  S )r   )itemsize)rq   strideshapearrs      r1   rs   z)TestCase._fix_strides.<locals>.<listcomp>{  s5     " " "'qyy S\) yyr4   )sizendimrx   stridesr   )rZ   r   s    `r1   _fix_strideszTestCase._fix_stridess  sW    
 8q==3>!" " " "+.s{CI+F+F" " " "r4   c                    |                      |j        |j        d           |                      |j        |j        d           |                      |                     |          |                     |          d           dS )zG
        Test that two arrays have the same shape and strides.
        zshapes differzitemsizes differzstrides differN)r   r   r   r   )rZ   firstseconds      r1   assertStridesEqualzTestCase.assertStridesEqual  s     	flODDD:LMMM**51143D3DV3L3L)	+ 	+ 	+ 	+ 	+r4   r   r   NFc           	          	 |                      |||||||           dS # t          $ r}t          |          }	Y d}~nd}~ww xY w|                     d|d|d|	           dS )ag  
        Versatile equality testing function with more built-in checks than
        standard assertEqual().

        For arrays, test that layout, dtype, shape are identical, and
        recursively call assertPreciseEqual() on the contents.

        For other sequences, recursively call assertPreciseEqual() on
        the contents.

        For scalars, test that two scalars or have similar types and are
        equal up to a computed precision.
        If the scalars are instances of exact types or if *prec* is
        'exact', they are compared exactly.
        If the scalars are instances of inexact types (float, complex)
        and *prec* is not 'exact', then the number of significant bits
        is computed according to the value of *prec*: 53 bits if *prec*
        is 'double', 24 bits if *prec* is single.  This number of bits
        can be lowered by raising the *ulps* value.
        ignore_sign_on_zero can be set to True if zeros are to be considered
        equal regardless of their sign bit.
        abs_tol if this is set to a float value its value is used in the
        following. If, however, this is set to the string "eps" then machine
        precision of the type(first) is used in the following instead. This
        kwarg is used to check if the absolute difference in value between first
        and second is less than the value set, if so the numbers being compared
        are considered equal. (This is to handle small numbers typically of
        magnitude less than machine precision).

        Any value of *prec* other than 'exact', 'single' or 'double'
        will raise an error.
        Nzwhen comparing z and : )_assertPreciseEqualAssertionErrorr]   ry   )
rZ   r   r   preculpsmsgignore_sign_on_zeroabs_tolexcfailure_msgs
             r1   assertPreciseEqualzTestCase.assertPreciseEqual  s    H	$$UFD$#W. . . F  	# 	# 	#c((KKKKKK	# 				EEE666;;OPPPPPs    
A=Ac           
      
    d" fd	}                      |          }	                      |          }
d|	d|
d}r|dz  }                     |	|
|           |	}|dk    ro                     |j                  }                     |                     |j                                                  |j        |j        d	                                |j        |j        d
                                |j        j        |j        j        d                                                     |                               |          d           |j        |k    r|	                    |          }|j        |k    r|	                    |          }t          |j        |j                  D ] \  }}                     |||||           !dS |dk    re                     t          |          t          |                     t          ||          D ] \  }}                     |||||           !dS |dk    rd}n|dv rd}n|dk    rG                     |j        |j                                        |j        |j        |||           dS |dk    r#                     |j        |j                   d}n
J d            t#          |d          r0t#          |d          r                      |j        |j                   t%          | j                  t%          | j                  k    r2d|j        d|j        d}r|dz  }                     |           	 t+          j        |          rt+          j        |          rdS n# t.          $ r Y nw xY w|o|dk    r't1          j        t5          |                    j        }n*t%          |t8                    r|}nt;          d|z            t=          ||z
            |k     rdS |p|dk    }|sX|dk    rR|dk    rd}n|dk    rd}nt;          d|          d ||z
  d!z
  z  }|t=          |          t=          |          z   z  }nd}t%          | j                  r0 ||j         |j         |            ||j!        |j!        |           dS t%          |t0          j"        t0          j#        f          r_t1          j$        |          r<                     t1          j$        |          t1          j$        |                     dS  ||||           dS  ||||           dS )#z-Recursive workhorse for assertPreciseEqual().Nc                    |7| |cxk    rdk    s*n t          j        |           st          j        |          r                    | |           sp	 t          j        d|           t          j        d|          k    r0                                        | d|                     d S d S # t          $ r Y d S w xY wd S                     | ||           d S )Ng        r   r    != )deltar   )mathisinfr   copysignry   _formatMessagerf   assertAlmostEqual)r   r   r   r   r   rZ   s      r1   _assertNumberEqualz8TestCase._assertPreciseEqual.<locals>._assertNumberEqual  s>   &!7!7!7!7C!7!7!7!7:e$$ "8(,
6(:(: "8  C 888* =E22dmAv6N6NNN II $ 3 3C5:UUFF5D!E !EF F F F F ON
 %     &&ufEs&KKKKKs   AB4 4
CCzType Family mismatch. (r   )r   r   r   zdifferent number of dimensionszdifferent shapeszdifferent mutabilityzdifferent stridesr   r   T)r   r   Fr   r   r   zunexpected familyr   zMismatching return types (z vs. epsz)abs_tol is not "eps" or a float, found %ssingle   double5   zunsupported precision r(   r   N)%r   r   r   r   r   r   flags	writeabler   astyperx   flatr   r   assertIs	__class__valuehasattrr\   _bool_typesry   cmathisnanrf   rV   finfotyper   float
ValueErrorabsr   realimagtimedelta64
datetime64isnat)rZ   r   r   r   r   r   r   r   r   first_familysecond_familyassertion_messagecompare_familyr   abexact_comparisonrtolbitskr   s   `    ``              r1   r   zTestCase._assertPreciseEqual  st   
	L 	L 	L 	L 	L 	L 	L 	L" **511++F33BN,,MM 	1330}:KLLL & Y&&OOEK00EUDOOFL$A$ABBBUZ=? ? ?U[&,/1 1 1U[2FL4J35 5 5 T..u55!!&))+>@ @ @{e##U++|u$$u--EJ44 G G1((AtT3)<gG G G GFz))SZZV#>>>E6** G G1((AtT3)<gG G G GFw&&#999$v%%MM%/6+;<<<$$U[&,%)4%8'C C C Fy(( MM%/6+;<<<# *)))) 5'"" 	8wvw'?'? 	8U[&,777 ud.//vt/001 1 1 %*OOOV5E5E5E"G 5!!ss_4!II'(((	{5!! ek&&9&9  	 	 	D	
 %xU,,0GU++  !N"   56>""T))+>tw 
	DGOOx!! jtt!EFFFdTkAo&AUc&kk12EEEeT011 
	5uz6;>>>uz6;>>>>>>?? 	5x 9  %"(62B2BCCCCC""5&%88888ufe44444s   3(N 
N+*N+<   rE   c                 `   | j         }t          |           j        }	|||f}
d                    d |
D                       }g }|F|                                D ]1\  }}|                    |            |                    |            2t          j        g|dd|}t          j	        
                                }||d<   	 t          j	        d         |d<   n# t          $ r Y nw xY wt          j        |i n|          }|                    |           t          j        |t          j        t          j        ||d	
          }d|j         d|j         }|                     |j        d|           d}||j        v r|                     |           n|                     d|j                   |S )a  
        Runs named unit test(s) as specified in the arguments as:
        test_module.test_class.test_name. test_module must always be supplied
        and if no further refinement is made with test_class and test_name then
        all tests in the module will be run. The tests will be run in a
        subprocess with environment variables specified in `envvars`.
        If given, envvars must be a map of form:
            environment variable name (str) -> value (str)
        If given, flags must be a map of form:
            flag including the `-` (str) -> value (str)
        It is most convenient to use this method in conjunction with
        @needs_subprocess as the decorator will cause the decorated test to be
        skipped unless the `SUBPROC_TEST` environment variable is set to
        the same value of ``_subproc_test_env``
        (this special environment variable is set by this method such that the
        specified test(s) will not be skipped in the subprocess).


        Following execution in the subprocess this method will check the test(s)
        executed without error. The timeout kwarg can be used to allow more time
        for longer running tests, it defaults to 60 seconds.
        .c              3      K   | ]}||V  	d S r   rP   rp   s     r1   	<genexpr>z2TestCase.subprocess_test_runner.<locals>.<genexpr>d  s"      'J'JaAMMMMM'J'Jr4   Nz-mznumba.runtestsrD   COVERAGE_RCFILECOVERAGE_PROCESS_STARTT)stdoutstderrtimeoutenvuniversal_newlinesz
captured stdout: z
captured stderr: r   zNO TESTS RANOK)
__module__r   __name__joinitemsappendr^   
executableosenvironcopyKeyErrorpytypesMappingProxyTypeupdate
subprocessrunPIPEr  r  r   
returncodeskipTestassertIn)rZ   test_module
test_class	test_nameenvvarsr  r   _subproc_test_envthemodtheclspartsfully_qualified_test
flags_argsflagr   cmdenv_copystatusstreamsno_tests_rans                       r1   subprocess_test_runnerzTestCase.subprocess_test_runnerH  s   2 d$j)4"xx'J'J5'J'J'JJJ
${{}} . .e!!T),,,!!U*----~ %
 %D %2B %#%:??$$#4 	13<M1NH-.. 	 	 	D	*22gNN   JO'1$,G G G7 7 7'-}7 7*Aw777%6=((MM,''''MM$...s   C 
C&%C&c                 `    fd}t          | t          j                  r ||           S |S )zRuns the decorated test in a subprocess via invoking numba's test
        runner. kwargs timeout and envvars are passed through to
        subprocess_test_runner.c                       fd}|S )Nc                     t           j                            dd           j        k    r8| j        j        }|                     | j        |j        j                   d S  |            d S )NrD   )r  r  r  r  r  r   )r  r  getr
  r   r,  r	  )rZ   argskwargs
class_namer  funcr  s       r1   innerz?TestCase.run_test_in_subprocess.<locals>.wrapper.<locals>.inner  s~    :>>.$774=HH "&!8J//$(O#-"&- ' '*.- 0      DJJJJJr4   rP   )r4  r5  r  r  s   ` r1   wrapperz0TestCase.run_test_in_subprocess.<locals>.wrapper  s.          " Lr4   )r\   r  FunctionType)	maybefuncr  r  r6  s    `` r1   run_test_in_subprocesszTestCase.run_test_in_subprocess  sN    	 	 	 	 	 	( i!566 	79%%%Nr4   c                 v   |                                  }t          d                    |          t          j        fi           } |d           t          |          t                      G d dt                    }t          j	        |          fd            }t          |          d             }||fS )zUse to generate a dummy type unique to this test. Returns a python
        Dummy class and a corresponding Numba type DummyType.zDummyTypeFor{}my_dummyc                       e Zd ZdS )'TestCase.make_dummy_type.<locals>.DummyN)r
  r	  __qualname__rP   r4   r1   Dummyr=    s        Dr4   r?  c                     S r   rP   )valc
dummy_types     r1   typeof_dummyz.TestCase.make_dummy_type.<locals>.typeof_dummy  s	    r4   c                 N    t          |j                                                  S r   )r   contextget_dummy_value)typr   rB  s      r1   unbox_dummyz-TestCase.make_dummy_type.<locals>.unbox_dummy  s    qy88::;;;r4   )idr   formatr   Opaquer   r   objectr   registerr   )rZ   test_id	DummyTyper?  rD  rI  rC  s         @r1   make_dummy_typezTestCase.make_dummy_type  s    
 '')))0099EL?BOO	Yz**
!y!!+...	 	 	 	 	F 	 	 	 
	e	$	$	 	 	 	 
%	$	 
y			< 	< 
		< ir4   c                 T    ddl m}  |            s|                     d           dS dS )a  
        Call this to ensure the test is skipped if no suitable external compiler
        is found. This is a method on the TestCase opposed to a stand-alone
        decorator so as to make it "lazy" via runtime evaluation opposed to
        running at test-discovery time.
        r   )external_compiler_worksz(No suitable external compiler was found.N)numba.pycc.platformrS  r  )rZ   rS  s     r1   skip_if_no_external_compilerz%TestCase.skip_if_no_external_compiler  sN     	@?????&&(( 	FMMDEEEEE	F 	Fr4   )r   r   NFN)NNNr   NrE   )Nr   N),r
  r	  r>  longMessager   rW   rb   
contextlibr   rk   r   r   r   boolrV   bool_r   intr]   integerbytesbytes_r   r   r   inexactr   tuplelistr   floating_float_typescomplexfloatingr   r   r   r   r   r   r   r,  r9  rQ  rU  rP   r4   r1   rS   rS      s       K ) ) _)      - - -I I I P P P$ "K"SFSFRZMry)+O7*rz; $-2;'Lr12N  <
 
 

" 
" 
"+ + + DE9>#'.Q .Q .Q .Q` EF:?$(N5 N5 N5 N5` >BEG=@8 8 8 8t   :     0F F F F Fr4   rS   c                       e Zd ZdZdZdS )SerialMixinz-Mixin to mark test for serial execution.
    FN)r
  r	  r>  __doc___numba_parallel_test_rP   r4   r1   re  re    s          !r4   re  c              #      K   t          t          |           }t          t          | |           	 dV  t          t          | |           dS # t          t          | |           w xY w)z
    Return a context manager that temporarily sets Numba config variable
    *name* to *value*.  *name* must be the name of an existing variable
    in numba.config.
    N)getattrr   setattr)namer   	old_values      r1   override_configrm    sg       %%IFD%   )i(((((i((((s   A A#c              #   h  K   t           j                            |           }|t           j        | <   t          j                     	 dV  |t           j        | = n|t           j        | <   t          j                     dS # |t           j        | = n|t           j        | <   t          j                     w xY w)zk
    Return a context manager that temporarily sets an Numba config environment
    *name* to *value*.
    N)r  r  r0  r   reload_config)rk  r   r}   s      r1   override_env_configrp    s       *..

CBJt

;
4    #BJt ;
4    #BJts   A= =4B1c                 ~    t          |                                dd          }i }t          |||           ||          S )zj
    Given a *code* string, compile it with globals *globs* and return
    the function named *name*.
    z<string>r   )compilerstripeval)rk  codeglobsconss        r1   compile_functionry    s=    
 

H	5	5B	BUBd8Or4   znumba-testsntr   iQ c                  \    	 t          j        t                     d S # t          $ r Y d S w xY wr   )r  mkdir_trashcan_dirFileExistsErrorrP   r4   r1   _create_trashcan_dirr    s?    
   s    
++c                  r   t          j                     t          z
  } t          t          j        t
                              D ]t}t          j                            t
          |          }	 t          j        |          }|j	        | k     rt          j        |d           ^# t          $ r
}Y d }~md }~ww xY wd S )NT)ignore_errors)time_trashcan_timeoutsortedr  listdirr}  pathr  statst_mtimeshutilrmtreeOSError)freshness_thresholdr0   stes       r1   _purge_trashcan_dirr    s    )++(99RZ..// 	 	W\\-,,	B{000b5555 	 	 	 DDDD		 	s   *5B  
B4/B4c                 ^    t                       t          j        | dz   t                    }|S )N-)prefixdir)r  tempfilemkdtempr}  )r  r  s     r1   _create_trashcan_subdirr     s,    6C<]CCCDKr4   c                 <    t                       t          |           S )a  
    Create a temporary directory with the given *prefix* that will survive
    at least as long as this process invocation.  The temporary directory
    will be eventually deleted when it becomes stale enough.

    This is necessary because a DLL file can't be deleted while in use
    under Windows.

    An interesting side-effect is to be able to inspect the test files
    shortly after a test suite run.
    )r  r  )r  s    r1   temp_directoryr  %  s     "6***r4   c                 j    ddl } |j                     t          |            t          j        |          S )z
    Import and return a module of the given name.  Care is taken to
    avoid issues due to Python's internal directory caching.
    r   N)	importlibinvalidate_caches
__import__r^   r_   )modnamer  s     r1   import_dynamicr  5  s<    
 I!!!w;wr4   c              #     K   t          t          |           }t          t          | t          j                               	 t          t          |           V  t          t          | |           dS # t          t          | |           w xY w)zReturn a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.N)ri  r^   rj  ioStringIO)stream_nameorig_stdouts     r1   captured_outputr  B  sz       #{++KCbkmm,,,/c;'''''[+.....[+....s    A/ /Bc                       t          d          S )zCapture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    r  r  rP   r4   r1   captured_stdoutr  M       8$$$r4   c                       t          d          S )zCapture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    r  r  rP   r4   r1   captured_stderrr  V  r  r4   c               #      K   t                      5 } t          dd          5  | V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NDEBUG_CACHET)r  rm  )outs    r1   capture_cache_logr  `  s      			 c]D11 	 	III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s,   A3A7	A7	AAAc                       e Zd ZdZd Zd ZdS )EnableNRTStatsMixinz,Mixin to enable the NRT statistics counters.c                 ,    t          j                     d S r   )_nrtmemsys_enable_statsrY   s    r1   setUpzEnableNRTStatsMixin.setUpj  s     """""r4   c                 ,    t          j                     d S r   )r  memsys_disable_statsrY   s    r1   tearDownzEnableNRTStatsMixin.tearDownm  s    !#####r4   N)r
  r	  r>  rf  r  r  rP   r4   r1   r  r  g  s8        66# # #$ $ $ $ $r4   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )
MemoryLeakTc                 \    t          j                     t          j                    | _        d S r   )rv   rw   r   r   _MemoryLeak__init_statsrY   s    r1   memory_leak_setupzMemoryLeak.memory_leak_setupu  s$    

!688r4   c                 @    | j         r|                                  d S d S r   )_MemoryLeak__enable_leak_checkassert_no_memory_leakrY   s    r1   memory_leak_teardownzMemoryLeak.memory_leak_teardownz  s/    # 	)&&(((((	) 	)r4   c                 
   | j         }t          j                    }|j        |j        z
  }|j        |j        z
  }|j        |j        z
  }|j        |j        z
  }|                     ||           |                     ||           d S r   )r  r   r   r   r   r   r   r   r   s          r1   r  z MemoryLeak.assert_no_memory_leak~  s    (**i#)+X(
4ck1j11177777r4   c                     d| _         d S )NF)r  rY   s    r1   disable_leak_checkzMemoryLeak.disable_leak_check  s    #(   r4   N)r
  r	  r>  r  r  r  r  r  rP   r4   r1   r  r  q  sV        9 9 9
) ) )8 8 8) ) ) ) )r4   r  c                   (     e Zd Z fdZ fdZ xZS )MemoryLeakMixinc                 ~    t          t          |                                            |                                  d S r   )superr  r  r  rZ   r   s    r1   r  zMemoryLeakMixin.setUp  s7    ot$$**,,,     r4   c                     t          j                     |                                  t          t          |                                            d S r   )rv   rw   r  r  r  r  r  s    r1   r  zMemoryLeakMixin.tearDown  sB    

!!###ot$$--/////r4   )r
  r	  r>  r  r  __classcell__)r   s   @r1   r  r    sQ        ! ! ! ! !0 0 0 0 0 0 0 0 0r4   r  c               #     K   ddl m}  dg}i }d }	 |D ]}|                    d          }| }|dd         D ]}t          ||          }|d         }t          ||          }t	          |          sJ d|z              ||||f<   t          |||           dV  |                                D ]\  \  }}}t          |||           dS # |                                D ]\  \  }}}t          |||           w xY w)	z
    Forbid LLVM code generation during the execution of the context
    manager's enclosed block.

    If code generation is invoked, a RuntimeError is raised.
    r   )codegenz%CPUCodeLibrary._finalize_final_modulec                       t          d          )Nzcodegen forbidden by test case)RuntimeError)r1  r2  s     r1   ry   zforbid_codegen.<locals>.fail  s    ;<<<r4   r   Nz%r should be callable)
numba.corer  splitri  callablerj  r  )	r  patchpointsr}   ry   rk  r#  r   attrnamer   s	            r1   forbid_codegenr    sf      #""""":;K
C= = =* 		) 		)DJJsOOEC!#2#J - -c8,,RyHC**EE??DD%<t%CDDD!&CXC4((((&)iikk 	* 	*"OS(UC5))))	* 	*ciikk 	* 	*"OS(UC5))))	*s   B	C 0C;c              #   l  K   ddl m} t          j        |j                  }|                                 t          j        |           }t          j                    \  }}	 t          j	        ||            t          j        |d          V  |                                 t          j        |           t          j	        ||            t          j        |           dS # |                                 t          j        |           t          j	        ||            t          j        |           w xY w)zt
    Temporarily redirect *fd* to a pipe's write end and return a file object
    wrapping the pipe's read end.
    r   )
_helperlibrN)numbar  ctypesCDLL__file___numba_flush_stdoutr  duppipedup2r  openclose)fdr  libnumbasaver  ws         r1   redirect_fdr    s      !     {:.//H  """6"::D799DAq
2gaoo$$&&&

b
 	$$&&&

b
s   !,C   AD3c                  \    t           j                                        } t          |           S )zRedirect C stdout
    )r^   
__stdout__filenor  r  s    r1   redirect_c_stdoutr    #     
			 	 Br??r4   c                  \    t           j                                        } t          |           S )zRedirect C stderr
    )r^   
__stderr__r  r  r  s    r1   redirect_c_stderrr    r  r4   c                 D    t          |          }t          | ||          S )aK  Spawn a new process to run `func` with a temporary cache directory.

    The childprocess's stdout and stderr will be captured and redirected to
    the current process's stdout and stderr.

    Returns
    -------
    ret : dict
        exitcode: 0 for success. 1 for exception-raised.
        stdout: str
        stderr: str
    )verbose)r  run_in_new_process_in_cache_dir)r4  cache_dir_prefixr  	cache_dirs       r1   run_in_new_process_cachingr    s'     /00I*4GLLLLr4   c                 4   t          j        d          }|                                }t          d|          5  |                    t
          | |g          }|                                 |                                 |                                }|                                }|rT|	                                r@t                       t          d                    dd                     t          |           |rx|	                                rdt          t          j                   t          d                    dd          t          j                   t          |t          j                   d	d	d	           n# 1 swxY w Y   |j        ||d
S )a  Spawn a new process to run `func` with a temporary cache directory.

    The childprocess's stdout and stderr will be captured and redirected to
    the current process's stdout and stderr.

    Similar to ``run_in_new_process_caching()`` but the ``cache_dir`` is a
    directory path instead of a name prefix for the directory path.

    Returns
    -------
    ret : dict
        exitcode: 0 for success. 1 for exception-raised.
        stdout: str
        stderr: str
    spawnNUMBA_CACHE_DIR)targetr1  STDOUTP   r  )fileSTDERRN)exitcoder  r  )mpget_contextQueuerp  Process_remote_runnerstartr  
get_nowaitstripprintcenterr^   r  r  )r4  r  r  ctxqoutprocr  r  s           r1   r  r    s     .
!
!C99;;D	.		:	: + +{{.d|{DD

		"""" 	v||~~ 	GGG(//"c**+++&MMM 	+v||~~ 	+sz""""(//"c**<<<<&sz****+ + + + + + + + + + + + + + + M  s   D?FFFc                    t                      5 }t                      5 }	  |              d}n%# t          $ r t          j                     d}Y nw xY wddd           n# 1 swxY w Y   |                    |                                           ddd           n# 1 swxY w Y   |                    |                                           t          j        |           dS )z+Used by `run_in_new_process_caching()`
    r   r   N)	r  r  	Exception	traceback	print_excputgetvaluer^   exit)r0   r  r  r  r  s        r1   r  r    s`    
		 	$f 	&
 	    #%%%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	""###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	HHV__HXsT   BA
-AAAAABA"	"B%A"	&*BB #B c                   2    e Zd Zej        efd            ZdS )CheckWarningsMixinc              #   ^  K   t          j        d          5 }t          j        d           d V  d d d            n# 1 swxY w Y   d}|D ]=}|D ]8}|t          |j                  v r |                     |j        |           |dz  }9>|                     |t          |                     d S )NT)recordalwaysr   r   )rM   catch_warningssimplefilterr]   rK   r   rL   r   )rZ   messagesrL   catchfoundr  ms          r1   check_warningsz!CheckWarningsMixin.check_warnings*  s	     $D111 	U!(+++EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	 	A  AI&&$$QZ:::QJE 	H.....s   =AAN)r
  r	  r>  rW  r   RuntimeWarningr  rP   r4   r1   r  r  )  s9        0> 
/ 
/ 
/ 
/ 
/ 
/r4   r  c                     | sdS g }|                                  D ]X\  }}t          |t                    rd                    |          }|                    d                    ||                     Yd                    |          S )N z"{}"z{}={}z, )r  r\   r]   rK  r  r  )jit_optionsr  keyr   s       r1   _format_jit_optionsr%  8  s     r
C!'')) / /
UeS!! 	)MM%((E

7>>#u--....99S>>r4   c              +     K   	 t          d          }d                    t          t          j                                                  dd                    }t          j                            ||dz             }t          d
i |}t          |d          5 }|                     |          }|                    |           ddd           n# 1 swxY w Y   t          j                            d	|           t          j        |          }|V  t          j                            |d           t          j                            |           t'          j        |           dS # t          j                            |d           t          j                            |           t'          j        |           w xY w)a  A context manager that creates and imports a temporary module
    from sources provided in ``source_lines``.

    Optionally it is possible to provide jit options for ``jit_module`` if it
    is explicitly used in ``source_lines`` like ``jit_module({jit_options})``.
    test_temp_moduleztest_temp_module_{}r  _z.pyr  )r#  Nr   rP   )r  rK  r]   uuiduuid4replacer  r  r  r%  r  writer^   insertr  import_moduler_   popremover  r  )source_linesr#  tempdirtemp_module_nametemp_module_pathflinesr  s           r1   create_temp_moduler7  C  s      !344077
%%c3//1 17<<1AE1IJJ)88K88"C(( 	A ''K'@@EGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	7###-.>??($///   g 	($///   gs1   BE) ,CE) CE) C;E) )AF>   c                 6   |g }t           j        g|z   d| gz   }t          j        |t          j        t          j        |          }|                    |          \  }}|j        dk    r-d}t          ||j        |                                fz            ||fS )zRun a snippet of Python code in a subprocess with flags, if any are
    given. 'env' is passed to subprocess.Popen(). 'timeout' is passed to
    popen.communicate().

    Returns the stdout and stderr of the subprocess after its termination.
    N-c)r  r  r  )r  r   z/process failed with code %s: stderr follows
%s
)	r^   r  r  Popenr  communicater  r   decode)	ru  r   r  r  r'  popenr  errr   s	            r1   run_in_subprocessr@  a  s     }>
e
#tTl
2CS$.O> > >E   11HC1ASE$4cjjll#CCDDD8Or4   r$   c           	         t          j        d          5 }t          j                    }t	          j        d          }|t          d          |ddt          |          dd                    |          d	|j	        g}t          j        |t          j        
          j        }t          j        |j                  }|                                 dfd	}		 t          j        j                  }
|
                                  |              |                                                                  t          j        |t,          j                   nd} |	|                                             |	             |                                }|
                                 |                                 n-# |
                                 |                                 w xY w	 ddd           n# 1 swxY w Y   |S )a)  Runs strace whilst executing the function work() in the current process,
    captures the listed syscalls (list of strings). Takes an optional timeout in
    seconds, default is 10, if this is exceeded the process will be sent a
    SIGKILL. Returns a list of lines that are output by strace.
    zw+tstraceNz'No valid 'strace' binary could be foundz-qz-pz-e,z-o)r  r"  c                 P    j         }|dk    rd| d|  }t          |          d S )Nr   z0strace exited non-zero, process return code was:z. )r  r  )problemretr   r>  s      r1   check_returnzstrace.<locals>.check_return  sJ    "Caxx++ +!(+ +"3''' xr4   )r  z)If this is SIGKILL, increase the timeout?)r"  )r  NamedTemporaryFiler  getpidr  whichr   r]   r  rk  r  r;  r  pid	threadingTimerkillr  Threadr<  flushpollsignalSIGINTwait	readlinescancel)worksyscallsr  ntf
parent_pidstrace_binaryr'  
strace_pidthread_timeoutrG  thread_commsrE  strace_datar>  s                @r1   rB  rB  t  s:    
	$U	+	+ 4$sY[[
X.. FGGGS__SXXh''SX	  Z_>>>Y
"%*==	( 	( 	( 	( 	( 	(	$ %+53DEEEL    DFFFIIKKKzz||#
FM2222 DW%%% JJLLLLNNN--//K !!#### !!#####i4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$l s+   CG<B?G)G<*G,,G<<H H c                      t           j                            d          sdS d } d}	 t          | |g          }n# t          $ r Y dS w xY w|d                    |          v S )z)Checks if strace is supported and workingr=   Fc                  H    t          j        t          j        ddg           d S )Nr:  zexit())r  r  r^   r  rP   r4   r1   force_clonez%strace_supported.<locals>.force_clone  s!    h788888r4   cloner"  )r^   r   
startswithrB  r  r  )rb  syscalltraces      r1   strace_supportedrg    s    
 <""7++ u9 9 9 G{WJ//   uubggenn$$s   : 
AAc                       e Zd ZdZd ZdS )IRPreservingTestPipelinez Same as the standard pipeline, but preserves the func_ir into the
    metadata store after legalisation, useful for testing IR changesc                     t          j        | j        d          }d|_        |                    t
          t                     |                                 |gS )Nir_preserving_custom_pipeF)r   define_nopython_pipelinestate
_finalizedadd_pass_afterr   r   finalize)rZ   pipelines     r1   define_pipelinesz)IRPreservingTestPipeline.define_pipelines  sV    %>J35 5 $
N;;;zr4   N)r
  r	  r>  rf  rr  rP   r4   r1   ri  ri    s/        H H    r4   ri  c            
         ddl } ddl m} t          j                            t          j                            t                              }t          j                            |ddd          }t          j                            |          st          d          t          t          j                            |          d          5 }|                                }ddd           n# 1 swxY w Y   |                     ||          }|d         }t          d	           }|dd
         D ]I}	|	d         d         }
|
                                D ]$}||d                  |d         xx         dz  cc<   %Jg d}t          j        j        |g|R  }t          j                            |          st          d          t          t          j                            |          d          5 }|                                }ddd           n# 1 swxY w Y   |                     ||          }|d         d         d         d         }
|
                                D ]$}||d                  |d         xx         dz  cc<   %t          d           t          d           t!          |                                          D ]8\  }}|                                D ]\  }}t          d| d|dd|            9t          d           }t!          |                                          D ]*\  }}|                                D ]\  }}|||         |<   +t          d           t          d           d }t!          |                                |          D ]8\  }}|                                D ]\  }}t          d|dd| d|            9dS )a-  This is a utility function that prints out the map of NumPy to Python
    versions and how many of that combination are being tested across all the
    declared config for azure-pipelines. It is useful to run when updating the
    azure-pipelines config to be able to quickly see what the coverage is.r   N)Loader..zazure-pipelines.ymlz&'azure-pipelines.yml' is not availablertjobsc                  *    t          t                    S r   r   rZ  rP   r4   r1   <lambda>z$print_azure_matrix.<locals>.<lambda>  s    K$4$4 r4   r(   
parametersmatrixNUMPYPYTHONr   )ru  ru  buildscriptsazurezazure-windows.ymlz$'azure-windows.yml' is not availablestrategyzNumPy | Python | Countz----------------------- z |  z<4z  |   c                  *    t          t                    S r   ry  rP   r4   r1   rz  z$print_azure_matrix.<locals>.<lambda>  s    +c"2"2 r4   z
Python | NumPy | Countc                 ^    t          | d                             d          d                   S )Nr   r   r   )rZ  r  )rr   s    r1   rz  z$print_azure_matrix.<locals>.<lambda>  s!    s1Q4::c??1-.. r4   )r$  )yamlrt  r  r  dirnameabspathr  r  isfiler  r  readloadr   valuesr  r  r  )r  rt  	base_path
azure_piper5  datapipe_yml	templates	py2np_maptmpltr|  setupwinpathazure_windowswindows_ymlnpverpyspyvercountrev_mapsorternpss                         r1   print_azure_matrixr    sv   
 KKK 9 9::Iit5JKKJ7>>*%% ECDDD	bgooj))4	0	0 Avvxx              yyfy--H I4455I2A2 : :|$X.]]__ 	: 	:EeGn%eHo66696666	: IHHGGL5W555M7>>-(( CABBB	bgoom,,d	3	3 qvvxx              ))D)00K  #J/9F 6 6%.!%/222A52222	
"###	
#$$$Y__..// : :
sIIKK 	: 	:LE58e88888889999	: 2233GY__..// * *
sIIKK 	* 	*LE5$)GEN5!!	*	
$%%%	
#$$$..FW]]__&999 : :
sIIKK 	: 	:LE58e888E88889999	:: :s$   	C**C.1C..HHH)T)NNr8  )r$   )rf  r   rW  collectionsr   r   rv   r   r   r  rR  r  r  r^   r  rL  r  r  r  multiprocessingr   rM   r  r   r)  r  r   r  	functoolsr   numpyrV   r  r   r  r   r	   r
   r   r   numba.core.typingr   numba.core.compilerr   r   r   r   r   numba.core.typed_passesr   numba.core.untyped_passesr   r-   numba.core.runtimer   numba.npr   r   r  numba.core.extendingr   r   r   r   r   r   numba.core.datamodel.modelsr   scipyImportErrorcoverageprocess_startupenable_pyobj_flagsenable_pyobjectforce_pyobj_flagsforce_pyobjectno_pyobj_flags	nrt_flagsnrtmake_tag_decoratortagr!   r   _32bitis_parfors_unsupportedskipIfskip_parfors_unsupported
skipUnlessr,   skip_unless_py10_or_laterskip_unless_py10skip_unless_py312skip_if_32bitr;   
IS_NUMPY_2skip_if_numpy_2r2   r6   r9   r<   _msgskip_unless_scipy	SUPPORTEDskip_unless_cffi_lnx_reasonrd  
linux_only_win_reasonwindows_onlymachine
_is_armv7ldisabled_testskip_ppc64le_issue4563rX  r  r0  has_typeguardskip_unless_typeguardskip_if_typeguardskip_ppc64le_issue6465skip_ppc64le_invalid_ctr_loopuname_unamesystemIS_MACOSskip_macos_fenv_errorsIS_MACOS_ARM64scipy.linalg.cython_lapack
has_lapackneeds_lapackscipy.linalg.cython_blashas_blas
needs_blas
_exec_condneeds_subprocess
setuptoolshas_setuptoolsneeds_setuptoolsrQ   rS   rM  re  rm  rp  ry  r}  rk  r  r  
gettempdirgetuidr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r%  r7  r@  rB  rg  ri  r  rP   r4   r1   <module>r     s}         # # # # # #  				   				       



       				           % % % % % %          % % % % % %                     9 9 9 9 9 9 9 9 9 9 9 9 9 9 ( ( ( ( ( (5 5 5 5 5 5 5 5 5 5 5 5 5 5 3 2 2 2 2 2 0 0 0 0 0 0  $ $ $ $ $ $ " " " " " " 2 2 2 2 2 2                4 3 3 3 3 3LLLL   EEEOOO H  	 	 	D	
 UWW %)  "EGG #'   EGG		 !g !M!M!MNN c-  		 *8?  
 0H/	Ow   
 '8&	Ow  
 (H'	Ow  
  (ABB(F2
!(/*"?A A         #HOETM488 &8&z';_MM X_!8!8!A!AA;OO
!x3<#:#:5#A#AA;OOX8+
o66 ))9)9););y)H+KM M 
 RZ^^$91==>>++-   $HO3  
 ))9)9););y)H+=? ?  !0H)#! !  
		=H$(35 5 7fn7%%%%JJ   JJJ #x":#<> >####HH   HHH !X +BCC
 Z^^ND11S8
&8&z3MNN NN   NNN
 '8&~7NOO 
D 
D 
DPF PF PF PF PFx  PF PF PFf" " " " "& " " " ) ) )   ,   7d??GLL!4!4!6!6FFMM GLL!4!4!6!6,9MM929;;;!GI IM
        
+ + +       / / /% % %% % %   $ $ $ $ $& $ $ $) ) ) ) ) ) ) )8	0 	0 	0 	0 	0): 	0 	0 	0 * * *D   ,     7? M M M M"$ $ $ $N   / / / / / / / /     :   &> > > >B% % %&    |   $6: 6: 6: 6: 6:sZ   C C#"C#'C; ;DDN N"!N"7N> >OOP PP