a
    –§»apˆ  ã                   @   sx  d 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ZddlmZ ddlmZmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'Z'ddl(m)Z) ddl*m+Z+ dd	l,m-Z- zddl.Z.W n e/�yH   dZ.Y n0 e%ƒ Z0d
e0_1e%ƒ Z2d
e2_3e%ƒ Z4e%ƒ Z5d
e5_6e 7ddg¡Z8e
j9dkZ:e:Z;e' <e;d¡Z=e' <ej>dkd¡Z?dZ@e' <e.du e@¡ZAdZBe' <e
j Cd¡ eB¡ZDe E¡ dkZFe' <d
d¡ZGe' <e E¡ dkd¡ZHeIejJ Kdd¡ƒZLe' MeLd¡ZNe' <eLd¡ZOe' <e E¡ dkd¡ZPzddlQZ.d
ZRW n e/�yn   dZRY n0 e' MeRd¡ZSzddlTZ.d
ZUW n e/�y¤   dZUY n0 e' MeUd¡ZVejJ Kdd¡d kZWe' MeWd!¡ZXe' <e- d"¡ZYd#d$„ ZZG d%d&„ d&e[ƒZ\G d'd(„ d(e'j]ƒZ]G d)d*„ d*e[ƒZ^ejd+d,„ ƒZ_ejd-d.„ ƒZ`d/d0„ Zadad1d2„Zbd3Zcejdd4k�rjeje fe g¡ ec¡Zcneje fe g¡ d5ece h¡ f ¡Zcd6Zid7d8„ Zjd9d:„ Zkd;d<„ Zld=d>„ Zmd?d@„ ZnejdAdB„ ƒZodCdD„ ZpdEdF„ ZqejdGdH„ ƒZrG dIdJ„ dJe[ƒZsG dKdL„ dLesƒZtejdMdN„ ƒZuejdOdP„ ƒZvdQdR„ Zwexd
fdSdT„ZydbdUdV„ZzdWdX„ Z{G dYdZ„ dZe[ƒZ|d[d\„ Z}ejd]d^„ ƒZ~dcd_d`„ZdS )dz&
Assorted utilities for use in tests.
é    N)Úcontextmanager)Útesting)ÚerrorsÚtypingÚutilsÚconfigÚcpu)Úcompile_extraÚcompile_isolatedÚFlagsÚDEFAULT_FLAGS)Úrtsys)Únumpy_support)Ú_external_compiler_okTZ	importantZlong_runningì        zparfors not supported©é   é   zunsupported on py3.8 or laterzSciPy needed for testzlinux only testÚlinuxÚarmv7lzTest disabledÚppc64lez?Hits: 'Parameter area must exist to pass an argument in memory'ZNUMBA_USE_TYPEGUARDzTypeguard is not enabledzBroken if Typeguard is enabledz>Hits: 'mismatch in size of parameter area' in LowerCall_64SVR4FzLAPACK needs SciPy 1.0+zBLAS needs SciPy 1.0+ÚSUBPROC_TESTÚ1zneeds subprocess harnessz)Compatible external compilers are missingc                   C   s&   t jddd� t jddtjdd� dS )zŠUse in testing within a ` warnings.catch_warnings` block to filter out
    warnings that are unrelated/internally generated by Numba.
    ÚignoreZ	typeguard)Úmodulez.*TBB_INTERFACE_VERSION.*znumba\.np\.ufunc\.parallel.*)ÚactionÚmessageÚcategoryr   N)ÚwarningsÚfilterwarningsr   ZNumbaWarning© r    r    úM/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/support.pyÚignore_internal_warnings„   s    ýr"   c                   @   s&   e Zd ZdZdd„ Zdefdd„ZdS )ÚCompilationCachez‡
    A cache of compilation results for various signatures and flags.
    This can make tests significantly faster (or less slow).
    c                 C   s$   t  ¡ | _t | jd¡| _i | _d S )Nr   )r   ÚContextÚ	typingctxr   Z
CPUContextÚ	targetctxÚcr_cache©Úselfr    r    r!   Ú__init__—   s    
zCompilationCache.__init__Nc              
   C   s†   ddl m} ||||f}|| jv r.| j| }nT| | j| j¡�* t| j| j||||i d�}W d  ƒ n1 sn0    Y  || j|< |S )ze
        Compile the function or retrieve an already compiled result
        from the cache.
        r   )Ú
cpu_target)ÚlocalsN)Znumba.core.registryr+   r'   Znested_contextr%   r&   r	   )r)   ÚfuncÚargsÚreturn_typeÚflagsr+   Ú	cache_keyÚcrr    r    r!   Úcompileœ   s    
ÿ$
zCompilationCache.compile)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   r   r3   r    r    r    r!   r#   ‘   s   r#   c                   @   sê   e Zd ZdZejdd„ ƒZdd„ Zej	dd„ ƒZ
ej	dd	„ ƒZej	d
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d„ Z"dd„ Z#dd„ Z$dd„ Z%d!dd„Z&d"dd„Z'dd„ Z(d#dd „Z)dS )$ÚTestCaseTc                 C   s   t j d¡S )Né*   )ÚnpÚrandomZRandomStater(   r    r    r!   r;   ¶   s    zTestCase.randomc                 C   s4   t |tƒrtj| }z|`W n ty.   Y n0 dS )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)r)   r   r    r    r!   Úreset_module_warningsº   s    

zTestCase.reset_module_warningsc                 c   sD   t jt jttf}|  |¡�}|V  W d  ƒ n1 s60    Y  dS )zr
        A context manager that asserts the enclosed code block fails
        compiling in nopython mode.
        N)r   ZLoweringErrorZTypingErrorÚ	TypeErrorÚNotImplementedErrorÚassertRaises)r)   Z_accepted_errorsÚcmr    r    r!   ÚassertTypingErrorÇ   s
    ÿzTestCase.assertTypingErrorc                 g   sZ   dd„ |D ƒ}dV  dd„ |D ƒ}t |||ƒD ]&\}}}||kr.|  d|||f ¡ q.dS )z 
        A context manager that asserts the given objects have the
        same reference counts before and after executing the
        enclosed block.
        c                 S   s   g | ]}t  |¡‘qS r    ©r>   Úgetrefcount©Ú.0Úxr    r    r!   Ú
<listcomp>Ù   ó    z+TestCase.assertRefCount.<locals>.<listcomp>Nc                 S   s   g | ]}t  |¡‘qS r    rH   rJ   r    r    r!   rM   Û   rN   z-Refcount changed from %d to %d for object: %r)ÚzipÚfail)r)   ZobjectsZold_refcountsZnew_refcountsÚoldÚnewÚobjr    r    r!   ÚassertRefCountÒ   s    ÿzTestCase.assertRefCountc                 c   sf   t  ¡ }dV  t  ¡ }|j|j }|j|j }|j|j }|j|j }|  ||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©r)   rQ   rR   Ztotal_allocZ
total_freeZtotal_mi_allocZtotal_mi_freer    r    r!   ÚassertNoNRTLeaká   s    ÿÿzTestCase.assertNoNRTLeakc                 C   s”   t |tjƒrdS t |tjƒr dS | jD ]}t ||ƒr& dS q&| jD ]}t ||ƒrB dS qB| jD ]}t ||ƒr^ dS q^| jD ]}t ||ƒrz dS qzd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<   r:   r]   r^   ÚEnumÚ_sequence_typesetsÚ_exact_typesetsÚ_complex_typesÚ_approx_typesets)r)   Znumeric_objectÚtpr    r    r!   Ú_detect_familyü   s"    







zTestCase._detect_familyc                 C   s4   t jdkr,t jdkr,|t d¡kr,t d¡S |S dS )z7
        Fix the given *dtype* for comparison.
        Úwin32r   Úint32Úint64N)r>   ÚplatformÚmaxsizer:   Údtype)r)   rp   r    r    r!   Ú
_fix_dtype  s
    ÿ
zTestCase._fix_dtypec                    s6   ˆ j dkrdgˆ j S ‡ fdd„tˆ jˆ jƒD ƒS dS )zˆ
        Return the strides of the given array, fixed for comparison.
        Strides for 0- or 1-sized dimensions are ignored.
        r   c                    s"   g | ]\}}|d kr|ˆ j  ‘qS )é   )Úitemsize)rK   ZstrideÚshape©Úarrr    r!   rM   .  s   þz)TestCase._fix_strides.<locals>.<listcomp>N)ÚsizeÚndimrO   Ústridesrt   )r)   rv   r    ru   r!   Ú_fix_strides&  s
    

ÿzTestCase._fix_stridesc                 C   sB   |   |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)rZ   rt   rs   rz   )r)   ÚfirstÚsecondr    r    r!   ÚassertStridesEqual2  s
    ÿzTestCase.assertStridesEqualr`   rr   NFc           
   
   C   sd   z|   |||||||¡ W n, tyF } zt|ƒ}	W Y d}~nd}~0 0 dS |  d|||	f ¡ 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 %s and %s: %s)Ú_assertPreciseEqualÚAssertionErrorr=   rP   )
r)   r{   r|   ÚprecÚulpsÚmsgÚignore_sign_on_zeroÚabs_tolÚexcZfailure_msgr    r    r!   ÚassertPreciseEqual;  s    $ÿzTestCase.assertPreciseEqualc              
      s  d!‡ ‡‡fdd„	}ˆ  |¡}	ˆ  |¡}
d|	|
f }ˆrD|dˆf 7 }ˆj|	|
|d� |	}|dk�r4ˆ |j¡}ˆ |ˆ |j¡¡ ˆ |j|jd¡ ˆ |j|jd	¡ ˆ |jj|jjd
¡ ˆ ˆ |¡ˆ |¡d¡ |j|krê| 	|¡}|j|k�r | 	|¡}t
|j|jƒD ] \}}ˆ ||||ˆˆ |¡ �qdS |dk�r†ˆjt|ƒt|ƒˆd� t
||ƒD ] \}}ˆ ||||ˆˆ |¡ �q`dS |dk�r–d}nv|dv �r¦d}nf|dk�rÞˆ |j|j¡ ˆ |j|j||ˆˆ |¡ dS |dk�rþˆ |j|j¡ d}nd�sJ dƒ‚t|dƒ�r4t|dƒ�r4ˆ |j|j¡ t|ˆjƒt|ˆjƒk�r|d|j|jf }ˆ�rr|dˆf 7 }ˆ |¡ z"t |¡�rœt |¡�rœW dS W n t�y²   Y n0 |du�r|dk�rÚt t|ƒ¡j}nt|tƒ�rì|}ntd| ƒ‚t|| ƒ|k �rdS |�p|dk}|�s€|dk�r€|dk�r<d}n|dk�rLd}ntd|f ƒ‚d|| d  }|t|ƒt|ƒ  }nd}t|ˆjƒ�r´||j |j |ƒ ||j!|j!|ƒ n`t|tj"tj#fƒ�rt$j%d k�rút &|¡�rúˆ t &|¡t &|¡¡ n||||ƒ n||||ƒ dS )"z-Recursive workhorse for assertPreciseEqual().Nc                    s¨   |d u s2| |  krdks2n t  | ¡s2t  |¡r’ˆj| |ˆd� ˆ s¤z6t  d| ¡t  d|¡krzˆ ˆ ˆd| |f ¡¡ W q¤ tyŽ   Y q¤0 nˆj| ||ˆd� d S )Ng        ©r‚   rr   z%s != %s)Údeltar‚   )ÚmathÚisinfrZ   ÚcopysignrP   Z_formatMessagerC   ZassertAlmostEqual)r{   r|   rˆ   ©rƒ   r‚   r)   r    r!   Ú_assertNumberEqualp  s&    ÿÿÿÿÿz8TestCase._assertPreciseEqual.<locals>._assertNumberEqualz Type Family mismatch. (%s != %s)z: %sr‡   r]   zdifferent number of dimensionszdifferent shapeszdifferent mutabilityzdifferent stridesr_   r`   T)ra   rb   Fr^   rc   r   zunexpected familyrp   z$Mismatching return types (%s vs. %s)Úepsz)abs_tol is not "eps" or a float, found %sÚsingleé   Údoubleé5   zunsupported precision %ré   rr   )rr   é   )N)'rj   rZ   rq   rp   rx   rt   r0   Z	writeablerz   ZastyperO   Zflatr~   ÚlenZassertIsÚ	__class__ÚvalueÚhasattrr<   Ú_bool_typesrP   ÚcmathÚisnanrC   r:   ZfinfoÚtyperŽ   ÚfloatÚ
ValueErrorÚabsrg   ÚrealÚimagZtimedelta64Z
datetime64r   Znumpy_versionZisnat)r)   r{   r|   r€   r�   r‚   rƒ   r„   r�   Zfirst_familyZsecond_familyZassertion_messageZcompare_familyrp   ÚaÚbZexact_comparisonZrtolÚbitsÚkrˆ   r    rŒ   r!   r~   k  sÈ    

ÿ
ÿÿÿ
ÿ


ÿ
ÿ


þ


ÿ
ÿ



ÿ

zTestCase._assertPreciseEqualc                 C   s4   t |d|d�}|j}|ƒ }|ƒ }|  ||¡ ||fS )zÆ
        Compile the 0-argument *pyfunc* with the given *flags*, and check
        it returns the same result as the pure Python function.
        The got and expected results are returned.
        r    )r0   )r
   Úentry_pointr†   )r)   Zpyfuncr0   r2   ZcfuncÚexpectedÚgotr    r    r!   Úrun_nullary_funcû  s    zTestCase.run_nullary_funcé<   c                 C   sÚ   | j }t| ƒj}|||f}d dd„ |D ƒ¡}	tjdd|	g}
tj ¡ }d|d< t	 
|du r^i n|¡}| |¡ tj|
tjtj||d	d
�}d|j› d|j› �}|  |jd|¡ |  d|j¡ |  d|j¡ |  d|j¡ d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)
        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
        (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                 s   s   | ]}|d ur|V  qd S ©Nr    rJ   r    r    r!   Ú	<genexpr>   rN   z2TestCase.subprocess_test_runner.<locals>.<genexpr>z-mznumba.runtestsr   r   NT)ÚstdoutÚstderrÚtimeoutÚenvÚuniversal_newlinesz
captured stdout: z
captured stderr: r   ÚOKÚFAILÚERROR)r5   rœ   r4   Újoinr>   Ú
executableÚosÚenvironÚcopyÚpytypesÚMappingProxyTypeÚupdateÚ
subprocessÚrunÚPIPEr®   r¯   rZ   Ú
returncodeZassertInZassertNotIn)r)   Útest_moduleZ
test_classZ	test_nameÚenvvarsr°   ZthemodZtheclsÚpartsZfully_qualified_testÚcmdZenv_copyÚstatusZstreamsr    r    r!   Úsubprocess_test_runner  s(    




þ
ÿzTestCase.subprocess_test_runner)r`   rr   NFN)r`   rr   NFN)NNNrª   )*r4   r5   r6   ZlongMessager   Úcached_propertyr;   rB   Ú
contextlibr   rG   rT   r\   Úboolr:   Zbool_r™   Úintr=   ÚintegerÚbytesÚbytes_rf   r�   ra   Zinexactrh   ÚtupleÚlistre   ZfloatingZ_float_typesZcomplexfloatingrg   rj   rq   rz   r}   r†   r~   r©   rÇ   r    r    r    r!   r8   °   sF   





ÿ


	   þ
0   þ
   ÿr8   c                   @   s   e Zd ZdZdZdS )ÚSerialMixinz-Mixin to mark test for serial execution.
    FN)r4   r5   r6   r7   Z_numba_parallel_test_r    r    r    r!   rÑ   1  s   rÑ   c              
   c   s@   t t| ƒ}tt| |ƒ zdV  W tt| |ƒ ntt| |ƒ 0 dS )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_valuer    r    r!   Úoverride_config9  s
    
rÖ   c              	   c   sx   t j | ¡}|t j| < t ¡  z.dV  W |du r:t j| = n
|t j| < t ¡  n&|du r`t j| = n
|t j| < t ¡  0 dS )zk
    Return a context manager that temporarily sets an Numba config environment
    *name* to *value*.
    N)r¸   r¹   Úgetr   Zreload_config)rÔ   r—   rQ   r    r    r!   Úoverride_env_configH  s    



ù

rØ   c                 C   s(   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�   )r3   ÚrstripÚeval)rÔ   ÚcodeZglobsÚcoÚnsr    r    r!   Úcompile_function_  s    rÞ   c                 C   s°   | j }t|ƒ}|du r|j}|du r*|j}tjdkrp||j|j|j|j	|j
|j|||j|j|j|j|j|jƒ}n6||j|j|j	|j
|j|||j|j|j|j|j|jƒ}|| _ dS )zˆ
    Tweak the code object of the given function by replacing its
    *codestring* (a bytes object) and *consts* tuple, optionally.
    Nr   )Ú__code__rœ   Úco_codeÚ	co_constsr   Ú	PYVERSIONÚco_argcountÚco_posonlyargcountÚco_kwonlyargcountÚ
co_nlocalsÚco_stacksizeÚco_flagsÚco_namesÚco_varnamesÚco_filenameÚco_nameÚco_firstlinenoÚ	co_lnotab)r-   Z
codestringZconstsrÜ   ri   Znew_coder    r    r!   Ú
tweak_codei  s*    



û

ürï   znumba-testsÚntz%s.%si€Q c                   C   s&   zt  t¡ W n ty    Y n0 d S r¬   )r¸   ÚmkdirÚ_trashcan_dirÚFileExistsErrorr    r    r    r!   Ú_create_trashcan_dir“  s    rô   c                  C   s~   t   ¡ t } tt t¡ƒD ]^}tj t|¡}z&t |¡}|j	| k rPt
j|dd� W q tyv } zW Y d }~qd }~0 0 qd S )NT)Úignore_errors)ÚtimeÚ_trashcan_timeoutÚsortedr¸   Úlistdirrò   Úpathr¶   ÚstatÚst_mtimeÚshutilÚrmtreeÚOSError)Zfreshness_thresholdÚfnÚstÚer    r    r!   Ú_purge_trashcan_dir™  s    

r  c                 C   s   t ƒ  tj| d td�}|S )Nú-)ÚprefixÚdir)r  ÚtempfileÚmkdtemprò   )r  rú   r    r    r!   Ú_create_trashcan_subdir¦  s    r	  c                 C   s   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  r    r    r!   Útemp_directory«  s    r
  c                 C   s"   ddl }| ¡  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  r    r    r!   Úimport_dynamic»  s    r  c              
   c   sJ   t t| ƒ}tt| t ¡ ƒ zt t| ƒV  W tt| |ƒ ntt| |ƒ 0 dS )z‰Return a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.N)rÒ   r>   rÓ   ÚioÚStringIO)Ústream_nameÚorig_stdoutr    r    r!   Úcaptured_outputÈ  s
    
r  c                   C   s   t dƒS )zŸCapture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello
")
    r®   ©r  r    r    r    r!   Úcaptured_stdoutÓ  s    r  c                   C   s   t dƒS )z°Capture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello
")
    r¯   r  r    r    r    r!   Úcaptured_stderrÜ  s    r  c               	   c   sZ   t ƒ �@} tddƒ� | V  W d   ƒ n1 s.0    Y  W d   ƒ n1 sL0    Y  d S )NZDEBUG_CACHET)r  rÖ   )Úoutr    r    r!   Úcapture_cache_logæ  s    r  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
MemoryLeakTc                 C   s   t  ¡  t ¡ | _d S r¬   )ÚgcÚcollectr   rU   Ú_MemoryLeak__init_statsr(   r    r    r!   Úmemory_leak_setupñ  s    zMemoryLeak.memory_leak_setupc                 C   s   | j r|  ¡  d S r¬   )Ú_MemoryLeak__enable_leak_checkÚassert_no_memory_leakr(   r    r    r!   Úmemory_leak_teardownö  s    zMemoryLeak.memory_leak_teardownc                 C   sZ   | j }t ¡ }|j|j }|j|j }|j|j }|j|j }|  ||¡ |  ||¡ d S r¬   )r  r   rU   rV   rW   rX   rY   rZ   r[   r    r    r!   r   ú  s    z MemoryLeak.assert_no_memory_leakc                 C   s
   d| _ d S )NF)r  r(   r    r    r!   Údisable_leak_check  s    zMemoryLeak.disable_leak_checkN)r4   r5   r6   r  r  r!  r   r"  r    r    r    r!   r  í  s
   
r  c                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚMemoryLeakMixinc                    s   t t| ƒ ¡  |  ¡  d S r¬   )Úsuperr#  ÚsetUpr  r(   ©r–   r    r!   r%    s    zMemoryLeakMixin.setUpc                    s"   t t| ƒ ¡  t ¡  |  ¡  d S r¬   )r$  r#  ÚtearDownr  r  r!  r(   r&  r    r!   r'    s    zMemoryLeakMixin.tearDown)r4   r5   r6   r%  r'  Ú__classcell__r    r    r&  r!   r#  	  s   r#  c            	      c   sæ   ddl m}  dg}i }dd„ }zž|D ]l}| d¡}| }|dd… D ]}t||ƒ}qB|d }t||ƒ}t|ƒsxJ d	| ƒ‚||||f< t|||ƒ q$dV  W | ¡ D ]\\}}}t|||ƒ q¢n$| ¡ D ]\\}}}t|||ƒ qÆ0 dS )
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                  _   s   t dƒ‚d S )Nzcodegen forbidden by test case)ÚRuntimeError)r.   Úkwargsr    r    r!   rP   !  s    zforbid_codegen.<locals>.failr«   Néÿÿÿÿz%r should be callable)Ú
numba.corer)  ÚsplitrÒ   ÚcallablerÓ   Úitems)	r)  ZpatchpointsrQ   rP   rÔ   rÄ   rS   Úattrnamer—   r    r    r!   Úforbid_codegen  s(    

ÿr2  c              
   c   s¬   ddl m} t |j¡}| ¡  t | ¡}t ¡ \}}zFt 	|| ¡ t
 |d¡V  W | ¡  t |¡ t 	|| ¡ t |¡ n*| ¡  t |¡ t 	|| ¡ t |¡ 0 dS )zt
    Temporarily redirect *fd* to a pipe's write end and return a file object
    wrapping the pipe's read end.
    r   )Ú
_helperlibÚrN)Únumbar3  ÚctypesÚCDLLÚ__file__Z_numba_flush_stdoutr¸   ÚdupÚpipeÚdup2r  ÚopenÚclose)Úfdr3  ZlibnumbaÚsaver4  Úwr    r    r!   Úredirect_fd8  s     

ý
rA  c                  C   s   t j ¡ } t| ƒS )zRedirect C stdout
    )r>   Ú
__stdout__ÚfilenorA  )r>  r    r    r!   Úredirect_c_stdoutO  s    
rD  c                 C   s   t |ƒ}t| ||d�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)r-   Zcache_dir_prefixrE  Ú	cache_dirr    r    r!   Úrun_in_new_process_cachingV  s    rH  c                 C   sâ   t  d¡}| ¡ }td|ƒ�¨ |jt| |gd�}| ¡  | ¡  | ¡ }| ¡ }|rz| 	¡ rzt
ƒ  t
d dd¡ƒ t
|ƒ |r¶| 	¡ r¶t
tjd� t
d dd¡tjd� t
|tjd� W d	  ƒ n1 sÊ0    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
    ÚspawnZNUMBA_CACHE_DIR)Útargetr.   ÚSTDOUTéP   r  )ÚfileÚSTDERRN)Úexitcoder®   r¯   )ÚmpZget_contextÚQueuerØ   ÚProcessÚ_remote_runnerÚstartr¶   Ú
get_nowaitÚstripÚprintÚcenterr>   r¯   rO  )r-   rG  rE  ÚctxÚqoutÚprocr®   r¯   r    r    r!   rF  g  s(    
,ýrF  c              
   C   s¤   t ƒ �r}tƒ �>}z
| ƒ  W n ty8   t ¡  d}Y n0 d}W d  ƒ n1 sR0    Y  | | ¡ ¡ W d  ƒ n1 s~0    Y  | | ¡ ¡ t |¡ dS )z+Used by `run_in_new_process_caching()`
    rr   r   N)	r  r  Ú	ExceptionÚ	tracebackÚ	print_excÚputÚgetvaluer>   Úexit)r   rZ  r¯   r®   rO  r    r    r!   rS  Ž  s    

",rS  c                   @   s   e Zd Zejefdd„ƒZdS )ÚCheckWarningsMixinc                 c   sŒ   t jdd�� }t  d¡ d V  W d   ƒ n1 s20    Y  d}|D ]2}|D ](}|t|jƒv rL|  |j|¡ |d7 }qLqD|  |t|ƒ¡ d S )NT)ÚrecordÚalwaysr   rr   )r   Úcatch_warningsÚsimplefilterr=   r   rZ   r   r•   )r)   Úmessagesr   ZcatchÚfoundr@  Úmr    r    r!   Úcheck_warningsŸ  s    
$z!CheckWarningsMixin.check_warningsN)r4   r5   r6   rÉ   r   ÚRuntimeWarningrj  r    r    r    r!   rb  ž  s   rb  c                  K   sN   | sdS g }|   ¡ D ].\}}t|tƒr0d |¡}| d ||¡¡ qd |¡S )NÚ z"{}"z{}={}z, )r0  r<   r=   ÚformatÚappendr¶   )Újit_optionsr  Úkeyr—   r    r    r!   Ú_format_jit_options­  s    

rq  c              
   k   sô   zÈt dƒ}d tt ¡ ƒ dd¡¡}tj ||d ¡}t	f i |¤Ž}t
|dƒ�&}| j|d�}| |¡ W d  ƒ n1 sz0    Y  tj d	|¡ t |¡}|V  W tj |d¡ tj |¡ t |¡ n&tj |d¡ tj |¡ t |¡ 0 dS )
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})``.
    Ztest_temp_moduleztest_temp_module_{}r  Ú_z.pyr@  )ro  Nr   )r
  rm  r=   ÚuuidÚuuid4Úreplacer¸   rú   r¶   rq  r<  Úwriter>   Úinsertr  Úimport_moduler?   ÚpopÚremoverý   rþ   )Zsource_linesro  ÚtempdirZtemp_module_nameZtemp_module_pathÚfÚlinesrÂ   r    r    r!   Úcreate_temp_module¸  s&    	ÿ(
þr~  c                 C   sl   |du rg }t jg| d| g }tj|tjtjd�}| ¡ \}}|jdkrdd}t||j| ¡ f ƒ‚||fS )zŸRun a snippet of Python code in a subprocess with flags, if any are
    given.

    Returns the stdout and stderr of the subprocess after its termination.
    Nz-c)r®   r¯   r   z/process failed with code %s: stderr follows
%s
)	r>   r·   r¾   ÚPopenrÀ   ÚcommunicaterÁ   r   Údecode)rÛ   r0   rÅ   Úpopenr  Úerrr‚   r    r    r!   Úrun_in_subprocessÖ  s    
ÿ
r„  )NN)T)N)€r7   rš   rÉ   r^   r  r‰   rn   r¸   rý   r¾   r>   r  rö   r  r6  ÚmultiprocessingrP  r   r]  r   rs  r  Útypesr»   Únumpyr:   r5  r   r-  r   r   r   r   r   Znumba.core.compilerr	   r
   r   r   ZunittestZnumba.core.runtimer   Znumba.npr   Znumba.pycc.platformr   ZscipyÚImportErrorZenable_pyobj_flagsZenable_pyobjectZforce_pyobj_flagsZforce_pyobjectZno_pyobj_flagsZ	nrt_flagsZnrtZmake_tag_decoratorÚtagro   Z_32bitZis_parfors_unsupportedZskipIfZskip_parfors_unsupportedrâ   Zskip_py38_or_laterÚ_msgZskip_unless_scipyZ_lnx_reasonÚ
startswithZ
linux_onlyÚmachineZ
_is_armv7lZdisabled_testZskip_ppc64le_issue4563rÊ   r¹   r×   Zhas_typeguardZ
skipUnlessZskip_unless_typeguardZskip_if_typeguardZskip_ppc64le_issue6465Zscipy.linalg.cython_lapackZ
has_lapackZneeds_lapackZscipy.linalg.cython_blasZhas_blasZ
needs_blasZ
_exec_condZneeds_subprocessZneeds_external_compilersr"   Úobjectr#   r8   rÑ   rÖ   rØ   rÞ   rï   rò   rÔ   rú   r¶   Ú
gettempdirÚgetuidr÷   rô   r  r	  r
  r  r  r  r  r  r  r#  r2  rA  rD  r4   rH  rF  rS  rb  rq  r~  r„  r    r    r    r!   Ú<module>   s  

þþÿÿÿÿ
ÿ
ÿ   



ÿ

	


"

'
