B
     \                 @   s"  d dl mZmZ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yd dlZW n ek
r   dZY nX yd dlZW n ek
r   dZY nX 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 d dlmZ d dl m!Z! dd	l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d d
l*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dlm2Z2 ddl3m4Z4 ddl"m5Z5 d dl6m7Z8 e9 dkZ:dd Z;dd Z<dd Z=dIddZ>dJddZ?dKdd Z@dLd!d"ZAdMd#d$ZBG d%d& d&e#ZCd'd( ZDeD ZEd)ZFeGeEeFZHG d*d+ d+eCZIG d,d- d-eCZJG d.d/ d/eJZKG d0d1 d1e#ZLG d2d3 d3e#ZMG d4d5 d5e#ZNG d6d7 d7eNZOG d8d9 d9eOZPe5G d:d; d;eOZQG d<d= d=eOZRG d>d? d?eNZSG d@dA dAej#ZTdBdC ZUG dDdE dEe#ZVG dFdG dGej#ZWeXdHkreY  dS )N    )print_functiondivisionabsolute_importN)unittest_support)utilsjitgenerated_jittypestypeof)_dispatcher)compile_isolated)NumbaWarning   )TestCasetagtemp_directoryimport_dynamicoverride_env_configcapture_cache_logcaptured_stdout)as_dtype)codegen)_UserWideCacheLocator)
Dispatcher)parfor)needs_lapack)skip_parfors_unsupportedZarmv7lc             C   s   | S )N )xr   r   :lib/python3.7/site-packages/numba/tests/test_dispatcher.pydummy/   s    r    c             C   s   | | S )Nr   )r   yr   r   r   add3   s    r"   c             C   s   | | | S )Nr   )r   r!   zr   r   r   addsub7   s    r$         c             C   s   | | | S )Nr   )r   r!   r#   r   r   r   addsub_defaults;   s    r'   c             G   s
   | ||fS )Nr   )r   r!   r#   r   r   r   star_defaults?   s    r(      c             C   s"   t | tjrdd }ndd }|S )Nc             S   s   | | S )Nr   )r   r!   r   r   r   implE   s    zgenerated_usecase.<locals>.implc             S   s   | | S )Nr   )r   r!   r   r   r   r*   H   s    )
isinstancer	   Complex)r   r!   r*   r   r   r   generated_usecaseC   s    
r-   c             C   s$   t | tjrdd }n
ddd}|S )Nc             S   s   | S )Nr   )r   r   r   r   r*   O   s    z#bad_generated_usecase.<locals>.impl   c             S   s   | | S )Nr   )r   r!   r   r   r   r*   R   s    )r.   )r+   r	   r,   )r   r!   r*   r   r   r   bad_generated_usecaseM   s    

r/   c                sn   t |tjjtjjfr0tjdd | |fD   n,t |tjtjfrLt	| nt
dt| d fdd	}|S )Nc             s   s   | ]}t |jjV  qd S )N)npdtypename).0aryr   r   r   	<genexpr>Y   s   z*dtype_generated_usecase.<locals>.<genexpr>zUnhandled Type %sc                s   t j| j dS )N)r1   )r0   onesshape)abr1   )	out_dtyper   r   _fn`   s    z$dtype_generated_usecase.<locals>._fn)N)r+   r	   ZmiscZNoneTypeZOmittedr0   Zresult_typeZDTypeZNumberClassr   	TypeErrortype)r8   r9   r1   r;   r   )r:   r   dtype_generated_usecaseW   s    

r>   c               @   s   e Zd ZeddZdd ZdS )BaseTestT)nopythonc                s(    fdd}t f j  |fS )Nc                 s$   | |} | |} || d S )N)assertPreciseEqual)argskwargsexpectedresult)fpyfuncselfr   r   checkk   s    

z$BaseTest.compile_func.<locals>.check)r   jit_args)rH   rG   rI   r   )rF   rG   rH   r   compile_funcj   s    zBaseTest.compile_funcN)__name__
__module____qualname__dictrJ   rK   r   r   r   r   r?   f   s   
r?   c           
   C   s   t d} tj| d}t| d}ttj|dd}|d W d Q R X t|d zzy.ttj|dd}|d	 W d Q R X W nF tt	fk
r } z$t
|d
d }|tjtjfkrd}W d d }~X Y nX W d t|d t| X |S )N
test_cacheZwritable_testFZwrite_okZwtZcheck1i@  Zwrite_forbiddenZcheck2errnoTi  )r   ospathjoinmkdiropenwritechmodOSErrorIOErrorgetattrrQ   ZEACCESZEPERMshutilrmtree)tempdirZtest_dirZretrF   eZenor   r   r   check_access_is_preventabler   s"    
r`   z9Cannot create a directory to which writes are preventablec               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zeeeddd Zeeddd Zeeedd d! Zd"d# Zd$S )%TestDispatcherc             C   s8   t dd }|d |j \}| |jj|jj d S )Nc             S   s   | S )Nr   )r   r   r   r   foo   s    z+TestDispatcher.test_dyn_pyfunc.<locals>.foor   )r   	overloadsvaluesassertEqualentry_pointrM   py_func)rH   rb   crr   r   r   test_dyn_pyfunc   s    zTestDispatcher.test_dyn_pyfuncc             C   s   t dd }|  d S )Nc               S   s   dS )Nr   r   r   r   r   r   rb      s    z,TestDispatcher.test_no_argument.<locals>.foo)r   )rH   rb   r   r   r   test_no_argument   s    zTestDispatcher.test_no_argumentc          	   C   s   t ddt}| |ddtdd | |ddtdd | |ddtdd | |ddtdd t d	ddt}| |ddtdd | |ddtd
d | t |dd W d Q R X d S )NT)r@   {   i  g(@gF@y        F@l    F: z(i4, i4)   -   )r   r"   rA   assertRaisesr<   )rH   Zc_addr   r   r   test_coerce_input_types   s    z&TestDispatcher.test_coerce_input_typesc             C   s   t dd }d}d}| |||||  | t|jd | |||||  | t|jd | |||||  | t|jd | |dd||  | t|jdd d	S )
z8Test compiling new version in an ambiguous case
        c             S   s   | | S )Nr   )r8   r9   r   r   r   rb      s    z6TestDispatcher.test_ambiguous_new_version.<locals>.foor   g      ?r%   r&      zdidn't compile a new versionN)r   ZassertAlmostEqualre   lenrc   )rH   rb   ZINTZFLTr   r   r   test_ambiguous_new_version   s    z)TestDispatcher.test_ambiguous_new_versionc                sp   g  t dd  fddfddtdD }x|D ]}|  q<W x|D ]}|  qRW   dS )	zz
        Test that (lazy) compiling from several threads at once doesn't
        produce errors (see issue #908).
        c             S   s   | d S )Nr   r   )r   r   r   r   rb      s    z%TestDispatcher.test_lock.<locals>.fooc           
      sF   y dd W n, tk
r@ }  z |  W d d } ~ X Y nX d S )Nr   r%   )re   BaseExceptionappend)r_   )errorsrb   rH   r   r   wrapper   s    z)TestDispatcher.test_lock.<locals>.wrapperc                s   g | ]}t j d qS ))target)	threadingZThread)r3   i)rv   r   r   
<listcomp>   s    z,TestDispatcher.test_lock.<locals>.<listcomp>   N)r   rangestartrT   ZassertFalse)rH   Zthreadstr   )ru   rb   rH   rv   r   	test_lock   s    

zTestDispatcher.test_lockc          	   C   sb  t dt}| |ddd | t|jd|j t ddgt}| |ddd | |ddd | |tddd	 | t	}|d
d
 W d Q R X | 
dt|j | t|jd|j t ddgt}| |tdtdd | |ddd t dddgt}| t	}|dd W d Q R X | t|jd | dt|j d S )Nz(int64,int64)g      ?g      @r&   r   z(float64,float64)r%   g      @g      @y              ?zNo matching definitionz(float32,float32)g      `>g      ?g     ?z(float32,float64)z(float64,float32)g       @zAmbiguous overloading for <function add [^>]*> \(float64, float64\):\n\(float32, float64\) -> float64\n\(float64, float32\) -> float64Zint64)r   r"   rA   re   rq   rc   r0   int32rn   r<   assertInstr	exceptionfloat32assertRegexpMatchesassertNotIn)rH   rF   cmr   r   r   test_explicit_signatures   s.    z'TestDispatcher.test_explicit_signaturesc          	   C   s   d}|  t}tdt W d Q R X | |d t|j |  t}tdt W d Q R X | |d t|j |  t}tdt W d Q R X | |d t|j tddd	t |  t}tddd	t W d Q R X | |d t|j d S )
NzKSignature mismatch: %d argument types given, but function takes 2 argumentsz()r   z(intc,)r   z(intc,intc,intc)r&   T)forceobj)rn   r<   r   r"   r   r   r   )rH   Ztmplr   r   r   r   test_signature_mismatch  s    z&TestDispatcher.test_signature_mismatchc          	   C   sB   t dt}| t}|dd W d Q R X | t|jd d S )Nz(intc,intc)y              ?zBNo matching definition for argument type(s) complex128, complex128)r   r"   rn   r<   re   r   r   )rH   rF   r   r   r   r   test_matching_error_message   s
    z*TestDispatcher.test_matching_error_messagec          	   C   sf   t dd }|d |  | t}|d W d Q R X | t|jd | t|j	d d S )Nc             S   s   | S )Nr   )r8   r   r   r   rb   )  s    z5TestDispatcher.test_disabled_compilation.<locals>.fooz
(float32,)z(int32,)zcompilation disabledr   )
r   compileZdisable_compilern   RuntimeErrorre   r   r   rq   
signatures)rH   rb   raisesr   r   r   test_disabled_compilation(  s    
z(TestDispatcher.test_disabled_compilationc          	   C   s\   t ddgdd }| t}|d W d Q R X | t|jd | t|jd d S )Nz
(float32,)z(int32,)c             S   s   | S )Nr   )r8   r   r   r   rb   5  s    zBTestDispatcher.test_disabled_compilation_through_list.<locals>.fooz(complex64,)zcompilation disabledr%   )	r   rn   r   r   re   r   r   rq   r   )rH   rb   r   r   r   r   &test_disabled_compilation_through_list4  s
    z5TestDispatcher.test_disabled_compilation_through_listc          	      sX   t dgdd  t  fdd}| t}|  W d Q R X d}| t|j| d S )Nz(intp,)c             S   s   | S )Nr   )r8   r   r   r   rb   ?  s    zATestDispatcher.test_disabled_compilation_nested_call.<locals>.fooc                  s    d  t d d S )Nr   )r0   r6   r   )rb   r   r   barC  s    zATestDispatcher.test_disabled_compilation_nested_call.<locals>.barzANo matching definition for argument type(s) array(float64, 1d, C))r   rn   r<   re   r   r   )rH   r   r   mr   )rb   r   %test_disabled_compilation_nested_call>  s    z4TestDispatcher.test_disabled_compilation_nested_callc          	      s   t dd  d}| t}tg  W dQ R X | |t|j |  g g  t dd j	}| t}|g  W dQ R X | |t|j t  fdd}| | g  |j
 \}| t|jd	 dS )
z
        Failure in computing the fingerprint cannot affect a nopython=False
        function.  On the other hand, with nopython=True, a ValueError should
        be raised to report the failure with fingerprint.
        c             S   s   | S )Nr   )r   r   r   r   rb   S  s    z4TestDispatcher.test_fingerprint_failure.<locals>.fooz(cannot compute fingerprint of empty listNT)r@   c                 s(   t   g } xtdD ]} | } qW | S )N
   )objectr|   )r   ry   )rb   r   r   r   e  s
    z4TestDispatcher.test_fingerprint_failure.<locals>.barr   )r   rn   
ValueErrorr   Zcompute_fingerprintr   r   r   re   rg   rc   rd   rq   Zlifted)rH   errmsgr   Z
strict_foor   rh   r   )rb   r   test_fingerprint_failureM  s    z'TestDispatcher.test_fingerprint_failurec       
      C   s   t dddd }| |dd tj}tj  t|}t|}| |d t| t	|}| |d t| | 
|| t|}~~| |d t| t	|}| |t| t|}~tj  | |t| t	|}	| 
| d dS )z:
        Test serialization of Dispatcher objects
        T)r@   c             S   s   | d S )Nr   r   )r   r   r   r   rb   v  s    z.TestDispatcher.test_serialization.<locals>.foor   r%   N)r   re   r   Z_memoZ_recentclearrq   pickledumpsloadsZassertIsidweakrefref)
rH   rb   memoZ	memo_sizeZserialized_fooZfoo_rebuiltZid_origZnew_foor   Z	newer_foor   r   r   test_serializationr  s,    






z!TestDispatcher.test_serializationzUnaligned loads unsupportedc       	         s   dd  t dd dtttj}t j| j }tj| d |d}|d d tj	}|dd  tj	}|j
}|j
} fd	d
}|d| |d| |d| |d| d S )Nc             S   s   t j| dS )Nr   )r0   linalgmatrix_power)r8   r   r   r   rb     s    z:TestDispatcher.test_misaligned_array_dispatch.<locals>.fooT)r@   @   r   )r1   c                sJ   t jt jd|d d d d f<  |}|}t j|| d S )N)r1   )r0   arange
complex128reshapetestingassert_allclose)r2   r8   rD   got)rb   jitfoonrr   r   rI     s    (z<TestDispatcher.test_misaligned_array_dispatch.<locals>.checkC_contig_alignedF_contig_alignedC_contig_misalignedF_contig_misaligned)r   intr0   sqrtint8r   itemsizer   viewr   T)	rH   dtcounttmpr   r   r   r   rI   r   )rb   r   r   r   r   test_misaligned_array_dispatch  s     


z-TestDispatcher.test_misaligned_array_dispatchc       	         s   dd  t dd dtttj}t j| j }tj| d |d}|d d tj	}|dd  tj	}|j
}|j
}d fd
d	}|d|dd |d|dd |d|dd |d|dd d S )Nc             S   s
   t | S )N)r0   sum)r8   r   r   r   rb     s    z?TestDispatcher.test_immutability_in_array_dispatch.<locals>.fooT)r@   r   r   )r1   r   Fc                sV   t jt jd|d d d d f< |r4d|j_ |}|}t j|| d S )N)r1   F)r0   r   r   r   flagsZ	writeabler   r   )r2   r8   disable_write_bitrD   r   )rb   r   r   r   r   r   rI     s    (zATestDispatcher.test_immutability_in_array_dispatch.<locals>.checkr   )r   r   r   r   )F)r   r   r0   r   r   r   r   r   r   r   r   )	rH   r   r   r   r   r   r   r   rI   r   )rb   r   r   r   r   #test_immutability_in_array_dispatch  s$    
z2TestDispatcher.test_immutability_in_array_dispatchc       
         s  dd  t dd fdd}ddtj}t j| j }tj| d	 |d
}|d d tj}||dd |d	d  tj}||dd |j}||dd |j}||dd  fdd}	|	d| |	d| |	d| |	d| d S )Nc          
   S   s&   t j| ddddd d d d f dS )Nr   r   )r0   r   r   )r8   r   r   r   rb     s    zITestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.fooT)r@   c                sD     | jj| |dkr(  | jjd |dkr@  | jjd d S )NCTF)re   r   alignedc_contiguousf_contiguous)ZarrZlayoutr   )rH   r   r   check_properties  s
    zVTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.check_propertiesi  r&   r   )r1   r   r   Fr   c                sR   t jt jd|d d d d f<  |}|}t j|| d S )N)r1   )r0   r   r   r   r   r   )r2   r8   rD   r   )rb   r   r   r   r   r   rI     s
     zKTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.checkr   r   r   r   )	r   r0   r   r   r   r   r   r   r   )
rH   r   r   r   r   r   r   r   r   rI   r   )rb   r   r   r   rH   r   -test_misaligned_high_dimension_array_dispatch  s.    	


z<TestDispatcher.test_misaligned_high_dimension_array_dispatchc             C   s   dd }t dd|}|td |td |td | t|jd tjftjftjfg}| |j| t tjfgdd|}|td |td |td | t|jd	 tjfg}| |j| d S )
Nc             S   s   | S )Nr   )r   r   r   r   rb   (  s    z@TestDispatcher.test_dispatch_recompiles_for_scalars.<locals>.fooT)r@   y      ?       @r   Fr&   r   )	r   r0   r   r   Zbool_re   rq   r   r	   )rH   rb   r   Zexpected_sigsr   r   r   $test_dispatch_recompiles_for_scalars"  s    
z3TestDispatcher.test_dispatch_recompiles_for_scalarsN)rL   rM   rN   ri   rj   ro   rr   r   r   r   r   r   r   r   r   r   r   unittestskipIf
_is_armv7lr   r   r   r   r   r   r   r   ra      s&   
%
%,')2ra   c               @   s0   e Zd ZdZeddd Zdd Zdd Zd	S )
TestSignatureHandlingz<
    Test support for various parameter passing styles.
    	importantc          	   C   s   |  t\}}|dddd |ddd |dddd | t|jd | t}|ddddd	 W d
Q R X | dt|j	 | t}|  W d
Q R X | dt|j	 | t}|dddd W d
Q R X | dt|j	 d
S )z?
        Test passing named arguments to a dispatcher.
        r&   r   rp   )r#   r!   )r   r!   r#   r   r.      )r!   r#   Nz%too many arguments: expected 3, got 4z'not enough arguments: expected 3, got 0)r!   zmissing argument 'z')
rK   r$   re   rq   rc   rn   r<   r   r   r   )rH   rF   rI   r   r   r   r   test_named_argsC  s     z%TestSignatureHandling.test_named_argsc          	   C   s  |  t\}}|dddd |ddd |dddd |ddd |dd |ddd |d |dd | t}|ddd	d
d W dQ R X | dt|j | t}|  W dQ R X | dt|j | t}|d	d
d W dQ R X | dt|j dS )z?
        Test omitting arguments with a default value.
        r&   r   rp   )r#   r!   )r   r!   r#   )r#   )r   r!   )r   r.   r   )r!   r#   Nz%too many arguments: expected 3, got 4z0not enough arguments: expected at least 1, got 0zmissing argument 'x')rK   r'   rn   r<   r   r   r   )rH   rF   rI   r   r   r   r   test_default_args[  s(    

z'TestSignatureHandling.test_default_argsc          	   C   s  |  t\}}|d |dd |ddd |dddd |ddddd |dd |ddd |ddd | t}|dddd W d	Q R X | d
t|j | t}|dddd W d	Q R X | d
t|j | t}|ddd W d	Q R X | d
t|j d	S )zJ
        Test a compiled function with starargs in the signature.
        rp   r)   r.   r      )r   )r   r!   )r!   Nz!some keyword arguments unexpected)r#   )rK   r(   rn   r<   r   r   r   )rH   rF   rI   r   r   r   r   test_star_argsv  s$    

z$TestSignatureHandling.test_star_argsN)rL   rM   rN   __doc__r   r   r   r   r   r   r   r   r   >  s   r   c               @   s   e Zd ZdZeddZdS )TestSignatureHandlingObjectModez<
    Sams as TestSignatureHandling, but in object mode.
    T)r   N)rL   rM   rN   r   rO   rJ   r   r   r   r   r     s   r   c               @   s8   e Zd ZdZeddd Zeddd Zdd Zd	S )
TestGeneratedDispatcherz#
    Tests for @generated_jit.
    r   c             C   s~   t ddt}| |dd | |ddd | |dddd | |dd	 | |dd
d | |dddd d S )NT)r@   r   r&   )r   rp   )r   r!   y              ?y      @      ?*   y      E@      ?r   y      @      ?)r   r-   re   )rH   rF   r   r   r   test_generated  s    z&TestGeneratedDispatcher.test_generatedc             C   s   t ddt}tjdtjd}tjdtjd}| |||jtj | |||tddjtj | |||tjdjtj d S )NT)r@   )r   )r1   r   )	r   r>   r0   r6   r   Zfloat64re   r1   r   )rH   rF   r8   r9   r   r   r   test_generated_dtype  s     z,TestGeneratedDispatcher.test_generated_dtypec          	   C   sr   t ddt}| t}|d W dQ R X | dt|j | t}|d W dQ R X | dt|j dS )zz
        Check error reporting when implementation signature doesn't match
        generating function signature.
        T)r@   y              ?NzGshould be compatible with signature '(x, y=5)', but has signature '(x)'r   zLshould be compatible with signature '(x, y=5)', but has signature '(x, y=6)')r   r/   rn   r<   r   r   r   )rH   rF   r   r   r   r   test_signature_errors  s    z-TestGeneratedDispatcher.test_signature_errorsN)rL   rM   rN   r   r   r   r   r   r   r   r   r   r     s   	r   c               @   s   e Zd Zdd Zdd Zeddd Zdd	 ZdddZdd Z	dd Z
dd Zeedkdeedkddd Zdd ZdS )TestDispatcherMethodsc                s   d t  fdd}| |dd | |dd | t|jd d | |dd |  | t|jd | |dd | |dd d S )	Nr   c                s   |   S )Nr   )r   )closurer   r   rb     s    z1TestDispatcherMethods.test_recompile.<locals>.foor%   g      ?g      @r&   g      @)r   rA   re   rq   r   	recompile)rH   rb   r   )r   r   test_recompile  s    z$TestDispatcherMethods.test_recompilec                sx   d t d fdd}| |dd | |dd d | |dd |  | |dd | |dd d S )Nr   zint32(int32)c                s   |   S )Nr   )r   )r   r   r   rb     s    z<TestDispatcherMethods.test_recompile_signatures.<locals>.foor%   g      ?r&   )r   rA   r   )rH   rb   r   )r   r   test_recompile_signatures  s    z/TestDispatcherMethods.test_recompile_signaturesr   c             C   s|   t dd }|dd |dd |dd | }| t|d x4| D ](}| d| | d| | d| qLW d S )	Nc             S   s   | | S )Nr   )explicit_arg1explicit_arg2r   r   r   rb     s    z4TestDispatcherMethods.test_inspect_llvm.<locals>.foor   g      ?r&   rb   r   r   )r   Zinspect_llvmre   rq   rd   r   )rH   rb   ZllvmsZllvm_bcr   r   r   test_inspect_llvm  s    


z'TestDispatcherMethods.test_inspect_llvmc             C   sf   t dd }|dd |dd |dd | }| t|d x| D ]}| d|k qLW d S )Nc             S   s   | | S )Nr   )r   r   r   r   r   rb      s    z3TestDispatcherMethods.test_inspect_asm.<locals>.foor   g      ?r&   rb   )r   Zinspect_asmre   rq   rd   
assertTrue)rH   rb   ZasmsZasmr   r   r   test_inspect_asm  s    


z&TestDispatcherMethods.test_inspect_asm c             C   s^   |rd t||}tddd }t|}d |||}| t|| | t|j d S )Nz{}{}.r   r   z^digraph "CFG for \'_ZN{}{}{})	formatrq   rL   splitr   r   r   callableZdisplay)rH   cfgrv   Zmodule_nameZ
module_lenprefixr   r   r   _check_cfg_display  s    z(TestDispatcherMethods._check_cfg_displayc       
   	   C   s   t dd }td}td}td}|| || || | }| t|d | \}}}| t|||gttdd |||g x|	 D ]}	| 
|	 qW | tt|	 d |j|jd	 d
}	| 
|	 d S )Nc             S   s   |   S )N)r   )	the_arrayr   r   r   rb   !  s    z3TestDispatcherMethods.test_inspect_cfg.<locals>.foor   )r   r   )r   r   r   r&   c             S   s
   t | fS )N)r
   )r   r   r   r   <lambda>6  s    z8TestDispatcherMethods.test_inspect_cfg.<locals>.<lambda>r   )	signature)r   r0   r6   inspect_cfgre   rq   keyssetmaprd   r   listr   )
rH   rb   a1a2a3Zcfgss1s2Zs3r   r   r   r   test_inspect_cfg  s"    


z&TestDispatcherMethods.test_inspect_cfgc             C   sh   t dd }td}td}td}|| || || |j|jd dd}| j|d	d
 d S )Nc             S   s   |   S )N)r   )r   r   r   r   rb   D  s    zGTestDispatcherMethods.test_inspect_cfg_with_python_wrapper.<locals>.foor   )r   r   )r   r   r   r   Zpython)r   Zshow_wrapperZcpython)rv   )r   r0   r6   r   r   r   )rH   rb   r   r   r   r   r   r   r   $test_inspect_cfg_with_python_wrapper@  s    


z:TestDispatcherMethods.test_inspect_cfg_with_python_wrapperc             C   s(   t dd }|dd |t  d S )Nc             S   s   | | S )Nr   )r8   r9   r   r   r   rb   V  s    z5TestDispatcherMethods.test_inspect_types.<locals>.foor   r%   )r   inspect_typesr   StringIO)rH   rb   r   r   r   test_inspect_typesU  s    
z(TestDispatcherMethods.test_inspect_typesNz#please install the 'jinja2' packagez%please install the 'pygments' packagec          	   C   s   t dd }|dd t  |jdd}W d Q R X xF|j D ]8\}}d}x |d D ]}d	|d krVd}qVW | | q@W | t}|jt	 dd
 W d Q R X | 
dt|j d S )Nc             S   s   | | S )Nr   )r8   r9   r   r   r   rb   a  s    z<TestDispatcherMethods.test_inspect_types_pretty.<locals>.foor   r%   T)prettyFZpygments_linesspan)filer   z$`file` must be None if `pretty=True`)r   r   r   annitemsr   rn   r   r   r   r   r   r   )rH   rb   r  kvZ
span_foundliner   r   r   r   test_inspect_types_pretty^  s    
z/TestDispatcherMethods.test_inspect_types_prettyc       
      C   s   dd }t |}tdgg}tjddgddggdd}tjddgddggd	d}||d
d}||d
d}| d||dd ||d
d}||d
d}	| || | ||	 dS )aO  
        This test an issue with the dispatcher when an array that is both
        C and F contiguous is supplied as the first signature.
        The dispatcher checks for F contiguous first but the compiler checks
        for C contiguous first. This results in an C contiguous code inserted
        as F contiguous function.
        c             S   s   | ||f S )Nr   )Ary   jr   r   r   rG     s    zKTestDispatcherMethods.test_issue_with_array_layout_conflict.<locals>.pyfuncg      ?g        g       @g      @r   )orderr   r   r   N)r   r0   Zarrayre   )
rH   rG   ZcfuncZary_c_and_fZary_cZary_fZexp_cZexp_fZgot_cZgot_fr   r   r   %test_issue_with_array_layout_conflictz  s    z;TestDispatcherMethods.test_issue_with_array_layout_conflict)r   )rL   rM   rN   r   r   r   r   r   r   r   r   r   r   r   jinja2pygmentsr  r  r   r   r   r   r     s   
"	r   c               @   sL   e Zd ZdZdZdd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd ZdS )BaseCacheTestNc             C   s^   t d| _tjd| j tj| j| jd | _tj| jd| _	t
| j| j d | _d S )NrP   r   z.py__pycache__)r   r^   sysrS   insertrR   rT   modnamemodfile	cache_dirr\   copyusecases_fileZmaxDiff)rH   r   r   r   setUp  s    
zBaseCacheTest.setUpc             C   s"   t j| jd  t j| j d S )N)r  modulespopr  rS   remover^   )rH   r   r   r   tearDown  s    zBaseCacheTest.tearDownc             C   s   t j| jd }|d k	rt jdkr,|jg}n*|jdrB|jg}n|jd |jd g}xL|D ]D}yt	| W q\ t
k
r } z|jtjkr W d d }~X Y q\X q\W t| j}| |jd| j |S )N)r&   )z.pycz.pyococo)r  r  r  r  version_info
__cached____file__endswithrR   unlinkrY   rQ   ENOENTr   re   rstripr  )rH   oldcachedfnr_   modr   r   r   import_module  s     




zBaseCacheTest.import_modulec          
   C   sL   ydd t | jD S  tk
rF } z|jtjkr6 g S d }~X Y nX d S )Nc             S   s   g | ]}| d s|qS ))z.pycz.pyo)r"  )r3   r(  r   r   r   rz     s    z0BaseCacheTest.cache_contents.<locals>.<listcomp>)rR   listdirr  rY   rQ   r$  )rH   r_   r   r   r   cache_contents  s    zBaseCacheTest.cache_contentsc                s   t  fddt  D S )Nc             3   s*   | ]"}|t jt j j|fV  qd S )N)rR   rS   getmtimerT   r  )r3   r(  )rH   r   r   r5     s   z1BaseCacheTest.get_cache_mtimes.<locals>.<genexpr>)rO   sortedr,  )rH   r   )rH   r   get_cache_mtimes  s    zBaseCacheTest.get_cache_mtimesc             C   s   |   }| t||| d S )N)r,  re   rq   )rH   r   r  r   r   r   check_pycache  s    zBaseCacheTest.check_pycachec             C   s   d S )Nr   )rH   r   r   r   
dummy_test  s    zBaseCacheTest.dummy_test)rL   rM   rN   r  r  r  r  r*  r,  r/  r0  r1  r   r   r   r   r    s   	r  c               @   sD   e Zd ZejeZejedZ	dZ
dd Zdd Zd
dd	ZdS )BaseCacheUsecasesTestzcache_usecases.pydispatcher_caching_test_fodderc             C   s`   dt | j| jd }tjtjd|gtjtjd}| \}}|j	dkr\t
d|j	| f d S )Nzif 1:
            import sys

            sys.path.insert(0, %(tempdir)r)
            mod = __import__(%(modname)r)
            mod.self_test()
            )r^   r  z-c)stdoutstderrr   z/process failed with code %s: stderr follows
%s
)rO   r^   r  
subprocessPopenr  
executablePIPEcommunicate
returncodeAssertionErrordecode)rH   codepopenouterrr   r   r   run_in_separate_process  s    

z-BaseCacheUsecasesTest.run_in_separate_processc             C   s   |  d |j}| |ddd |  d | |ddd |  d |j}| |ddd |  d | |ddd |  d |  d S )Nr   r%   r&   r.   g      @g      @r)   )r0  add_usecaserA   add_objmode_usecase	self_test)rH   r)  rF   r   r   r   check_module  s    




z"BaseCacheUsecasesTest.check_moduleNc             C   sF   |j }| t|j ||j |d k	rB| t|j ||j d S )N)statsre   r   Z
cache_hitsrd   Zcache_misses)rH   funchitsmissesstr   r   r   
check_hits  s
    z BaseCacheUsecasesTest.check_hits)N)rL   rM   rN   rR   rS   dirnamer!  hererT   r  r  rB  rF  rL  r   r   r   r   r2    s   r2  c               @   s   e Zd Zeddd Zeddd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zeeejd kd!d"d# Zeeejd kd!d$d% Zd&d' Zd(S ))	TestCacher   c             C   s@  |  d |  }|  d |j}| |ddd |  d | |ddd |  d | |dd |j}| |ddd |  d | |ddd |  d | |dd |j}||jd}| t|d	 ||j	d}| t|d	 |  d
 | |dd |j
}| |ddd | |ddd |   d S )Nr   r%   r&   r.   g      @g      @r)   r   )r%   g     E@	   y              @y       @      @)r0  r*  rC  rA   rL  rD  record_returnaligned_arrtuple
packed_arrr-   rB  )rH   r)  rF   Zrecr   r   r   test_caching	  s4    






zTestCache.test_cachingc             C   s   |  d |  }|  d |j}| |ddd |  d | |dtddtd d  |  d | |dd d S )Nr   r%   r&   r.   r   )r0  r*  rC  rA   r0   r   rL  )rH   r)  rF   r   r   r   test_caching_nrt_pruned,  s    


&
z!TestCache.test_caching_nrt_prunedc             C   s   |   }| |ddd | d |j}| |ddd | d |   }|j}| |ddd | d |j}| |ddd | d | |ddd | d d S )Nr&   r%   r.   rp   g      @g      @)r*  rA   innerr0  outer_uncachedouter)rH   r)  rF   r   r   r   test_inner_then_outer:  s    



zTestCache.test_inner_then_outerc             C   s   |   }| |ddd | d | |ddd | d |   }|j}| |ddd | d | |ddd | d d S )Nr&   r%   rp   r.   g      @g      @r)   )r*  rA   rY  r0  rX  rW  )rH   r)  rF   r   r   r   test_outer_then_innerN  s    


zTestCache.test_outer_then_innerc             C   s.   |   }|j}| |ddd | d d S )Nr%   r&   r.   r   )r*  Zadd_nocache_usecaserA   r0  )rH   r)  rF   r   r   r   test_no_caching\  s    zTestCache.test_no_cachingc          	   C   sv   |   }tjdd2}tdt |j}| |dd | d W d Q R X | t	|d | t
|d jd d S )	NT)recordalwaysrp   r.   r   r   zCCannot cache compiled function "looplifted" as it uses lifted loops)r*  warningscatch_warningssimplefilterr   Z
loopliftedrA   r0  re   rq   r   message)rH   r)  wrF   r   r   r   test_loopliftedc  s    zTestCache.test_loopliftedc          	   C   sx   |   }tjdd4}tdt |j}tj| |j	 | 
d W d Q R X | t|d | dt|d j d S )NT)r]  r^  r   r   zICannot cache compiled function "use_big_array" as it uses dynamic globals)r*  r_  r`  ra  r   Zuse_big_arrayr0   r   Zassert_equalZbiggier0  re   rq   r   r   rb  )rH   r)  rc  rF   r   r   r   test_big_arrays  s    zTestCache.test_big_arrayc          
   C   s   |   }x|j|j|jgD ]p}tjdd,}tdt | |dd | 	d W d Q R X | 
t|d | d|jt|d j qW d S )NT)r]  r^  g        r   r   z#Cannot cache compiled function "{}")r*  Z	use_c_sinZuse_c_sin_nest1Zuse_c_sin_nest2r_  r`  ra  r   rA   r0  re   rq   r   r   rL   r   rb  )rH   r)  rF   rc  r   r   r   test_ctypes  s    
zTestCache.test_ctypesc          	   C   s   |   }tjddH}tdt |j}| |dd |j}| |dd | d W d Q R X | 	t
|d x|D ]}| d	t|j qxW d S )
NT)r]  r^  r&   r.   r   r   r%   z(Cannot cache compiled function "closure")r*  r_  r`  ra  r   Zclosure1rA   Zclosure2r0  re   rq   r   r   rb  )rH   r)  rc  rF   itemr   r   r   test_closure  s    
zTestCache.test_closurec             C   s  |   }|dd |dd |dd |dd |dd ||jd ||jd |dd | 	 }| 
|jdd |   }| || |j}|dd | 
|dd |dd | 
|dd |j}|dd | 
|dd | | 	 | |   | | 	 | d S )Nr%   r&   g      @g      @r   r   )r*  rC  rD  rX  rY  rQ  rT  rR  r-   r/  rL  ZassertIsNotre   rB  )rH   r)  mtimesmod2rF   r   r   r   test_cache_reuse  s0    


zTestCache.test_cache_reusec          	   C   s~   |   }|j}| |ddd t| jd}|d W d Q R X |   }|j}| |ddd |j}| |ddd d S )Nr%   r&   r.   r8   z
Z = 10
   )r*  rC  rA   rV   r  rW   rD  )rH   r)  rF   r   r   r   test_cache_invalidate  s    zTestCache.test_cache_invalidatec             C   s   |   }|j}| |ddd |   }|j}d|_| |ddd |  | |ddd |   }|j}| |ddd d S )Nr%   r&   r.   r   rl  )r*  rC  rA   Zr   )rH   r)  rF   r   r   r   r     s    zTestCache.test_recompilec             C   s8   |   }|j}| |dd |j}| |dd d S )Nr%   rp   r   )r*  Zrenamed_function1rA   Zrenamed_function2)rH   r)  rF   r   r   r   test_same_names  s
    zTestCache.test_same_namesc             C   sx   ddl m} |j}tddd}zH||_t|}t||}| | dt	_
t||}| |t W d ||_t	`
X d S )Nr   )functionpassztests/dummy_module.pyexecT)Zdummy_modulerp  __code__r   inspectZgetfiler   Zfrom_functionZassertIsNoner  frozenZassertIsInstance)rH   rp  Zold_codeZcode_objsourceZlocatorr   r   r   test_frozen  s    

zTestCache.test_frozenc             C   s   |   }|j}| jtj|jjdd | |ddd | |dd |   }|j}| |ddd | |dd | 	d dS )	zy
        With a disabled __pycache__, test there is a working fallback
        (e.g. on the user-wide cache dir)
        T)ignore_errorsr%   r&   r.   r   r   N)
r*  rC  
addCleanupr\   r]   rG  
cache_pathrA   rL  r0  )rH   r)  rF   rj  r   r   r   _test_pycache_fallback  s    z TestCache._test_pycache_fallbackntz3cannot easily make a directory read-only on Windowsc             C   s:   t | jj}t | jd | t j| j| |   d S )Ni@  )rR   statr^   st_moderX   ry  r{  )rH   	old_permsr   r   r   test_non_creatable_pycache  s    z$TestCache.test_non_creatable_pycachec             C   sN   t j| jd}t | t |j}t |d | t j|| | 	  d S )Nr  i@  )
rR   rS   rT   r^   rU   r}  r~  rX   ry  r{  )rH   pycacher  r   r   r   test_non_writable_pycache&  s    
z#TestCache.test_non_writable_pycachec          
      s   t jddg  ddddg7  yt dg }W n4 tjk
rd } zd|j  W d d }~X Y nX |  }t	d	| t
jjd
td}|d W d Q R X  fdd}|  | }d|  d S )Nz-mZIPythonz--quietz--quickz--no-bannerz--colors=NoColorz	--versionz%ipython not available: return code %dzipython version:zipython_cache_usecase.txtrc  a}  
                import os
                import sys

                from numba import jit

                # IPython 5 does not support multiline input if stdin isn't
                # a tty (https://github.com/ipython/ipython/issues/9752)
                f = jit(cache=True)(lambda: 42)

                res = f()
                # IPython writes on stdout, so use stderr instead
                sys.stderr.write(u"cache hits = %d\n" % f.stats.cache_hits[()])

                # IPython hijacks sys.exit(), bypass it
                sys.stdout.flush()
                sys.stderr.flush()
                os._exit(res)
                c           	      s^   t dJ} tj | tjtjdd}| \}}|jdkrPd|j||f  |S Q R X d S )NrbT)stdinr4  r5  Zuniversal_newlinesr   z6unexpected return code %d
-- stdout:
%s
-- stderr:
%s
)rV   r6  r7  r9  r:  r;  Zfail)r  pr@  rA  )base_cmdinputfnrH   r   r   execute_with_inputU  s    
z2TestCache.test_ipython.<locals>.execute_with_inputzcache hits = 1)r  r8  r6  Zcheck_outputZCalledProcessErrorZskipTestr;  stripr=  printrR   rS   rT   r^   rV   rW   r   )rH   Zverr_   rF   r  rA  r   )r  r  rH   r   test_ipython3  s"    
zTestCache.test_ipythonN)rL   rM   rN   r   rU  rV  rZ  r[  r\  rd  re  rf  rh  rk  rm  r   ro  rw  r{  skip_bad_accessr   r   rR   r2   r  r  r  r   r   r   r   rO    s,   #	rO  c                   s0   e Zd Z fddZ fddZdd Z  ZS )TestSequentialParForsCachec                s   t t|   dt_d S )NT)superr  r  r   sequential_parfor_lowering)rH   )	__class__r   r   r  l  s    z TestSequentialParForsCache.setUpc                s   t t|   dt_d S )NF)r  r  r  r   r  )rH   )r  r   r   r  q  s    z#TestSequentialParForsCache.tearDownc             C   sj   |   }| d |j}td}| |||| |  dd |j D }| |dg | d d S )Nr   r   c             S   s   g | ]}|j jqS r   )ZlibraryZhas_dynamic_globals)r3   cresr   r   r   rz   |  s   z;TestSequentialParForsCache.test_caching.<locals>.<listcomp>Fr%   )	r*  r0  Zparfor_usecaser0   r6   rA   rc   rd   re   )rH   r)  rF   r4   Zdynamic_globalsr   r   r   rU  v  s    

z'TestSequentialParForsCache.test_caching)rL   rM   rN   r  r  rU  __classcell__r   r   )r  r   r  j  s   r  c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestCacheWithCpuSettingFc             C   sR   d}x8|    D ](\}}||kr| |||  |d7 }qW | j|ddd d S )Nr   r   znothing to compare)msg)r/  r  ZassertGreaterEqualassertGreater)rH   Z
mtimes_oldZmatch_countr  r  r   r   r   check_later_mtimes  s    z*TestCacheWithCpuSetting.check_later_mtimesc          	   C   s"  |  d |  }|  t|  }|  }tdd |   W d Q R X | | | 	t|  | |j
j}|j}| }| t|d | \}}|d d t kr|| }	}
n
|| }	}
| |	d d t  | |	d d t  | |
d d d | |
d d d d S )Nr   ZNUMBA_CPU_NAMEZgenericr%   r   r   )r0  r*  rE  rq   r,  r/  r   rB  r  r  rC  _cache_cache_file_load_indexre   r   llget_host_cpu_namer   get_host_cpu_features)rH   r)  
cache_sizeri  cache
cache_filecache_indexkey_akey_bkey_hostkey_genericr   r   r   test_user_set_cpu_name  s*    


z.TestCacheWithCpuSetting.test_user_set_cpu_namec          	   C   s6  |  d |  }|  t|  }|  }d}t }| || t	d| | 
  W d Q R X | | | t|  | |jj}|j}| }| t|d | \}	}
|	d d |kr|	|
 }}n
|
|	 }}| |d d t  | |d d | | |d d t  | |d d | d S )Nr   z	-sse;-avxZNUMBA_CPU_FEATURESr%   r   )r0  r*  rE  rq   r,  r/  r   r  assertNotEqualr   rB  r  r  rC  r  r  r  re   r   r  r  )rH   r)  r  ri  Zmy_cpu_featuresZsystem_featuresr  r  r  r  r  r  r  r   r   r   test_user_set_cpu_features  s0    


z2TestCacheWithCpuSetting.test_user_set_cpu_featuresN)rL   rM   rN   _numba_parallel_test_r  r  r  r   r   r   r   r    s   	r  c               @   s6   e Zd ZdZejeZej	edZ
dZdd ZdS )TestMultiprocessCacheFzcache_usecases.pyr3  c             C   s   |   }|j}d}ytd}W n tk
r8   t}Y nX ||}zt||t|}W d |	  X | 
|||d  d  d S )Nr&   spawnr   r%   )r*  Zsimple_usecase_callermultiprocessingget_contextAttributeErrorZPoolr   Zimapr|   closere   )rH   r)  rF   r   ZctxZpoolZresr   r   r   test_multiprocessing  s    


z*TestMultiprocessCache.test_multiprocessingN)rL   rM   rN   r  rR   rS   rM  r!  rN  rT   r  r  r  r   r   r   r   r    s
   r  c               @   sx   e Zd ZdZejeZej	edZ
dZdZdZdd Zdd	 Zd
d Zdd Zdd Zeeedddd ZdS )TestCacheFileCollisionFzcache_usecases.pyZcaching_file_loc_fodderzD
from numba import njit
@njit(cache=True)
def bar():
    return 123
zD
from numba import njit
@njit(cache=True)
def bar():
    return 321
c          	   C   s   t d| _tjd| j d| _| | jtj | j| _d	| jdg| _
tj	| j| j}t| ttj	|dd}t| j|d W d Q R X ttj	|d	d}t| j|d W d Q R X d S )
NZtest_cache_file_locr   Zmodule_name_that_is_unlikelyr   rb   z__init__.pyrc  )r  zfoo.py)r   r^   r  rS   r  r  r   r  modname_bar1rT   modname_bar2rR   rU   rV   r  source_text_1source_text_2)rH   ZfoomodZfoutr   r   r   r    s    

zTestCacheFileCollision.setUpc             C   s2   t j| jd  t j| jd  t j| j d S )N)r  r  r  r  r  rS   r  r^   )rH   r   r   r   r    s    zTestCacheFileCollision.tearDownc             C   s   t | jjS )N)r   r  r   )rH   r   r   r   import_bar1  s    z"TestCacheFileCollision.import_bar1c             C   s   t | jjS )N)r   r  r   )rH   r   r   r   import_bar2  s    z"TestCacheFileCollision.import_bar2c             C   sT   |   }|  }|jjj}|jjj}| || | |d | |d d S )Nz__init__.bar-3.pyzfoo.bar-3.py)r  r  r  r  Z_index_namer  r   
startswith)rH   bar1bar2Zidxname1Zidxname2r   r   r   test_file_location  s    

z)TestCacheFileCollision.test_file_locationr  z)Test requires multiprocessing.get_contextc          	   C   s  |   }|  }t }| }W d Q R X | }| |dd | |dd | |dd | |dd t }| }W d Q R X | }| |dd | |dd | |dd | |dd | || ytd}W n t	k
r   t
d Y nX | }|jt|| j| j| jfd	}	|	  | }
| }| }| }|	  | || | || | |
dd | |
dd | |
dd | |
dd | |dd | |dd | |dd | |dd d S )
Nzindex savedr   z
data savedzindex loadedr   zdata loadedr  zmissing spawn context)rw   rB   )r  r  r   getvaluere   r   r  r  r  r   r  ZQueueZProcesscache_file_collision_testerr^   r  r  r}   getrT   )rH   r  r  bufZres1ZcachelogZres2ZmpqprocZlog1Zgot1Zlog2Zgot2r   r   r   test_no_collision!  sT    z(TestCacheFileCollision.test_no_collisionN)rL   rM   rN   r  rR   rS   rM  r!  rN  rT   r  r  r  r  r  r  r  r  r  r   
skipUnlesshasattrr  r  r   r   r   r   r    s   
r  c       	   	   C   s   t jd| t|j}t|j}t }| }W d Q R X | |  | | t }| }W d Q R X | |  | | d S )Nr   )r  rS   r  r   r   r   Zputr  )	r  r^   r  r  r  r  r  Zr1Zr2r   r   r   r  _  s    


r  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
 TestDispatcherFunctionBoundariesc                s   t dddd  t dddd t dd fdd}d	d
tdg}dd |D }x&t||D ]\}}| ||| qfW x(t||D ]\}}|  || qW d S )NT)r@   c             S   s   | d S )Nr   r   )r   r   r   r   add1p  s    zJTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.add1c             S   s   | |S )Nr   )r(  r   r   r   r   r   t  s    zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.barc                s
    | S )Nr   )r   )r  r   r   r   rb   x  s    zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.foor   g333333&@r   c             S   s   g | ]}|d  qS )r   r   )r3   r   r   r   r   rz   ~  s    zPTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.<listcomp>)r   r0   r   ziprA   )rH   rb   ZinputsZexpected_resultsargZexpectr   )r  r   r   test_pass_dispatcher_as_argn  s    z<TestDispatcherFunctionBoundaries.test_pass_dispatcher_as_argc             C   s   t dddd }|ddddgt d	d
 d}| |d |tttdtdd d d t dd
 d}| |d |tttdtdd d d t dd
 d}| |d d S )NT)r@   c             S   s8   | d }x*| dd  D ]}|||}|dk r|}qW |S )Nr   r   r   )seqcmpfnr   ZeachZcmpvalr   r   r   maximum  s    
zPTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.maximumr   r%   r&   rp   c             S   s   | | S )Nr   )r   r!   r   r   r   r     s    zQTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.<lambda>)r  r)   r   c             S   s   | d |d  S )Nr   r   )r   r!   r   r   r   r     s    )rp   r   c             S   s   | d |d  S )Nr   r   )r   r!   r   r   r   r     s    )r   rp   )r   re   r   r  r|   )rH   r  r   r   r   r   test_dispatcher_as_arg_usecase  s    	  z?TestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecasec          	   C   sR   t dddd }t dd }| t}|| W d Q R X | t|jd d S )NT)r@   c             S   s   | S )Nr   )r(  r   r   r   rb     s    zUTestDispatcherFunctionBoundaries.test_dispatcher_cannot_return_to_python.<locals>.fooc             S   s   | S )Nr   )r   r   r   r   r     s    zZTestDispatcherFunctionBoundaries.test_dispatcher_cannot_return_to_python.<locals>.<lambda>z)cannot convert native .* to Python object)r   rn   r<   r   r   r   )rH   rb   r(  r   r   r   r   'test_dispatcher_cannot_return_to_python  s    zHTestDispatcherFunctionBoundaries.test_dispatcher_cannot_return_to_pythonc                s   t dddd  t dd fdd}t dd fdd}t ddd	d
 }| | ||fdd | |   gdd d S )NT)r@   c             S   s   | d S )Nr   r   )r   r   r   r   one  s    zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.onec                s     | S )Nr   )r   )r  r   r   two  s    zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.twoc                s      | S )Nr   )r   )r  r   r   three  s    zOTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.threec             S   s"   | d || d || d |fS )Nr   r   r%   r   )Zfnsr   r   r   r   choose  s    zPTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.chooser   )r%   r&   rp   )r%   r%   r%   )r   re   )rH   r  r  r  r   )r  r   test_dispatcher_in_sequence_arg  s    z@TestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_argN)rL   rM   rN   r  r  r  r  r   r   r   r   r  m  s   r  c               @   s   e Zd Zdd Zdd ZdS )TestBoxingDefaultErrorc          	   C   sP   dd }t |tdf}| t}|d  W d Q R X | t|jd d S )Nc             S   s   d S )Nr   )r   r   r   r   rb     s    z<TestBoxingDefaultError.test_unbox_runtime_error.<locals>.fooZ
dummy_typezcan't unbox dummy_type type)	r   r	   ZDummyrn   r<   rf   re   r   r   )rH   rb   r  r   r   r   r   test_unbox_runtime_error  s
    z/TestBoxingDefaultError.test_unbox_runtime_errorc          	   C   sJ   dd }t |d}| t}|  W d Q R X d}| t|j| d S )Nc               S   s   t S )N)r   r   r   r   r   rb     s    z:TestBoxingDefaultError.test_box_runtime_error.<locals>.foor   z/cannot convert native Module.* to Python object)r   rn   r<   rf   r   r   r   )rH   rb   r  r   Zpatr   r   r   test_box_runtime_error  s    
z-TestBoxingDefaultError.test_box_runtime_errorN)rL   rM   rN   r  r  r   r   r   r   r    s   r  __main__)r%   r&   )r%   )r)   )r)   )N)ZZ
__future__r   r   r   rQ   r  rR   platformr\   r6  r  rx   r_  rt  r   r   r  ImportErrorr  Znumpyr0   Znumbar   r   r   r   r   r	   r
   r   Znumba.compilerr   Znumba.errorsr   Zsupportr   r   r   r   r   r   r   Znumba.numpy_supportr   Znumba.targetsr   Znumba.cachingr   Znumba.dispatcherr   r   Ztest_linalgr   r   Zllvmlite.bindingZbindingr  machiner   r    r"   r$   r'   r(   r-   r/   r>   r?   r`   Z_access_preventableZ_access_msgr  r  ra   r   r   r   r   r  r2  rO  r  r  r  r  r  r  r  rL   mainr   r   r   r   <module>   s   

$






    *P+ VA0  eLtP
