o
    8ήcM                     @   s  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mZ d dl	Z
d dlmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZmZ d dl m!Z" d dl#Z#e"d Z$zd dl%Z%W n e&y   dZ%Y nw zd dl'Z'W n e&y   dZ'Y nw e( dkZ)dd Z*dd Z+dd Z,dDddZ-dEddZ.dFddZ/dFddZ0dGd d!Z1G d"d# d#eZ2G d$d% d%e2Z3G d&d' d'e2Z4G d(d) d)e4Z5G d*d+ d+eZ6G d,d- d-eZ7G d.d/ d/eZ8G d0d1 d1e#jZ9G d2d3 d3e#jZ:edHd5d6Z;edGd7d8Z<ed9d: Z=ee=fd;d<Z>d=d> Z?G d?d@ d@ee#jZ@G dAdB dBe#jZAeBdCkrGe#C  dS dS )I    N)chain)StringIO)njitjitgenerated_jittypeof	vectorize)typeserrors)_dispatcher)compile_isolated)TestCasecaptured_stdout)as_dtype)
Dispatcher)needs_lapackSerialMixin)_TIMEOUTg      N@armv7lc                 C      | S N xr   r   B/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_dispatcher.pydummy'      r   c                 C      | | S r   r   r   yr   r   r   add+      r    c                 C      | | | S r   r   r   r   zr   r   r   addsub/      r%         c                 C   r"   r   r   r#   r   r   r   addsub_defaults3   r&   r)   c                 G   s
   | ||fS r   r   r#   r   r   r   star_defaults7      
r*      c                 C   s$   t | tjrdd }|S dd }|S )Nc                 S   r   r   r   r   r   r   r   impl=   r!   zgenerated_usecase.<locals>.implc                 S      | | S r   r   r   r   r   r   r-   @   r!   
isinstancer	   Complexr   r   r-   r   r   r   generated_usecase;   s
   r3   c                 C   s&   t | tjrdd }|S ddd}|S )Nc                 S   r   r   r   r   r   r   r   r-   G   r   z#bad_generated_usecase.<locals>.impl   c                 S   r.   r   r   r   r   r   r   r-   J   r!   )r4   r/   r2   r   r   r   bad_generated_usecaseE   s
   
r5   c                    sn   t |tjjtjjfrtjdd | |fD   nt |tjtjfr&t	| nt
dt| d fdd	}|S )Nc                 s   s    | ]
}t |jjV  qd S r   )npdtypename).0aryr   r   r   	<genexpr>Q       z*dtype_generated_usecase.<locals>.<genexpr>zUnhandled Type %sc                    s   t j| j dS Nr7   )r6   onesshape)abr7   	out_dtyper   r   _fnX   s   z$dtype_generated_usecase.<locals>._fnr   )r0   r	   miscNoneTypeOmittedr6   result_typeDTypeNumberClassr   	TypeErrortype)rA   rB   r7   rE   r   rC   r   dtype_generated_usecaseO   s   


rN   c                   @   s   e Zd ZeddZdd ZdS )BaseTestTnopythonc                    s,    fdd}t di j  |fS )Nc                     s,   | i |} | i |} || d S r   )assertPreciseEqual)argskwargsexpectedresultfpyfuncselfr   r   checkc   s   z$BaseTest.compile_func.<locals>.checkr   )r   jit_args)rZ   rY   r[   r   rW   r   compile_funcb   s   zBaseTest.compile_funcN)__name__
__module____qualname__dictr\   r]   r   r   r   r   rO   ^   s    
rO   c                   @   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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&d' Zd(S ))TestDispatcherc                 C   sL   t dd }t dd }| ||kd | ||kd | |d kd d S )Nc                 S   r   r   r   r   r   r   r   foon      z)TestDispatcher.test_equality.<locals>.fooc                 S   r   r   r   r   r   r   r   barr   rd   z)TestDispatcher.test_equality.<locals>.barTFr   assertEqual)rZ   rc   re   r   r   r   test_equalitym   s   

zTestDispatcher.test_equalityc                 C   s8   t dd }|d |j \}| |jj|jj d S )Nc                 S   r   r   r   r   r   r   r   rc   ~   rd   z+TestDispatcher.test_dyn_pyfunc.<locals>.foo   )r   	overloadsvaluesrg   entry_pointr_   py_func)rZ   rc   crr   r   r   test_dyn_pyfunc}   s
   
zTestDispatcher.test_dyn_pyfuncc                 C   s   t dd }|  d S )Nc                   S   s   dS Nri   r   r   r   r   r   rc      rd   z,TestDispatcher.test_no_argument.<locals>.foor   rZ   rc   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    d S 1 smw   Y  d S )NTrP   {   i  g(@gF@y        F@l    F: z(i4, i4)   -   )r   r    rR   assertRaisesrL   )rZ   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   r   r   r   rA   rB   r   r   r   rc         z6TestDispatcher.test_ambiguous_new_version.<locals>.foori         ?r'   r(      zdidn't compile a new versionN)r   assertAlmostEqualrg   lenrj   )rZ   rc   INTFLTr   r   r   test_ambiguous_new_version   s   
z)TestDispatcher.test_ambiguous_new_versionc                    sh   g  t dd  fddfddtdD }|D ]}|  q|D ]}|  q&  dS )	zz
        Test that (lazy) compiling from several threads at once doesn't
        produce errors (see issue #908).
        c                 S      | d S rp   r   r   r   r   r   rc      r{   z%TestDispatcher.test_lock.<locals>.fooc               
      sH   z dd W d S  ty# }  z |  W Y d } ~ d S d } ~ ww Nri   r'   )rg   	Exceptionappend)e)r
   rc   rZ   r   r   wrapper   s   z)TestDispatcher.test_lock.<locals>.wrapperc                    s   g | ]}t j d qS ))target)	threadingThreadr9   ir   r   r   
<listcomp>   s    z,TestDispatcher.test_lock.<locals>.<listcomp>   N)r   rangestartjoinassertFalse)rZ   threadstr   )r
   rc   rZ   r   r   	test_lock   s   


zTestDispatcher.test_lockc                 C   s  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    n1 sUw   Y  | 
dt|j | t|jd|j t ddgt}| |tdtdd | |ddd t g dt}| t	}|dd W d    n1 sw   Y  | t|jd | dt|j d S )N(int64,int64)r|         @r(   ri   z(float64,float64)r'   g      @      @              ?zNo matching definitionz(float32,float32)g      `>      ?g     ?)z(float32,float64)z(float64,float32)r          @zAmbiguous overloading for <function add [^>]*> \(float64, float64\):\n\(float32, float64\) -> float64\n\(float64, float32\) -> float64int64)r   r    rR   rg   r   rj   r6   int32rw   rL   assertInstr	exceptionfloat32assertRegexpMatchesassertNotInrZ   rX   cmr   r   r   test_explicit_signatures   s4   
z'TestDispatcher.test_explicit_signaturesc                 C   sL  d}|  t}tdt W d    n1 sw   Y  | |d t|j |  t}tdt W d    n1 s>w   Y  | |d t|j |  t}tdt W d    n1 sdw   Y  | |d t|j tddd	t |  t}tddd	t W d    n1 sw   Y  | |d t|j d S )
NzKSignature mismatch: %d argument types given, but function takes 2 argumentsz()r   z(intc,)ri   z(intc,intc,intc)r(   Tforceobj)rw   rL   r   r    r   r   r   )rZ   tmplr   r   r   r   test_signature_mismatch   s$   z&TestDispatcher.test_signature_mismatchc                 C   sV   t dt}| t}|dd W d    n1 sw   Y  | t|jd d S )Nz(intc,intc)r   zBNo matching definition for argument type(s) complex128, complex128)r   r    rw   rL   rg   r   r   r   r   r   r   test_matching_error_message  s   z*TestDispatcher.test_matching_error_messagec                 C   sz   t dd }|d |  | t}|d W d    n1 s$w   Y  | t|jd | t|j	d d S )Nc                 S   r   r   r   rA   r   r   r   rc     rd   z5TestDispatcher.test_disabled_compilation.<locals>.foo
(float32,)(int32,)compilation disabledri   )
r   compiledisable_compilerw   RuntimeErrorrg   r   r   r   
signaturesrZ   rc   raisesr   r   r   test_disabled_compilation  s   

z(TestDispatcher.test_disabled_compilationc                 C   sp   t ddgdd }| t}|d W d    n1 sw   Y  | t|jd | t|jd d S )Nr   r   c                 S   r   r   r   r   r   r   r   rc     rd   zBTestDispatcher.test_disabled_compilation_through_list.<locals>.fooz(complex64,)r   r'   )	r   rw   r   r   rg   r   r   r   r   r   r   r   r   &test_disabled_compilation_through_list  s   

z5TestDispatcher.test_disabled_compilation_through_listc                    sl   t dgdd  t  fdd}| t}|  W d    n1 s$w   Y  d}| t|j| d S )Nz(intp,)c                 S   r   r   r   r   r   r   r   rc   %  rd   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.fooc                      s    d  t d d S rp   )r6   r?   r   rc   r   r   re   )  s   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.barzANo matching definition for argument type(s) array(float64, 1d, C))r   rw   rL   rg   r   r   )rZ   re   r   mr   r   r   %test_disabled_compilation_nested_call$  s   
z4TestDispatcher.test_disabled_compilation_nested_callc                    s   t dd  d}| t}tg  W d   n1 sw   Y  | |t|j |  g g  t dd j	}| t}|g  W d   n1 sOw   Y  | |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   r   r   r   r   r   r   r   rc   9  rd   z4TestDispatcher.test_fingerprint_failure.<locals>.fooz(cannot compute fingerprint of empty listNTrP   c                     s$   t   g } tdD ]} | } q	| S )N
   )objectr   )r   r   r   r   r   re   K  s
   
z4TestDispatcher.test_fingerprint_failure.<locals>.barri   )r   rw   
ValueErrorr   compute_fingerprintr   r   r   rg   rm   rj   rk   r   lifted)rZ   errmsgr   
strict_foore   rn   r   r   r   test_fingerprint_failure3  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
        TrP   c                 S   r   rp   r   r   r   r   r   rc   \  r{   z.TestDispatcher.test_serialization.<locals>.foori   r'   N)r   rg   r   _memo_recentclearr   pickledumpsloadsassertIsidweakrefref)	rZ   rc   memo	memo_sizeserialized_foofoo_rebuiltid_orignew_foor   r   r   r   test_serializationX  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 rp   r6   linalgmatrix_powerr   r   r   r   rc     s   z:TestDispatcher.test_misaligned_array_dispatch.<locals>.fooTrP   @   ri   r>   c                    sJ   t jt jd|d d d d f<  |}|}t j|| d S r=   r6   arange
complex128reshapetestingassert_allcloser8   rA   rU   gotrc   jitfoonrr   r   r[     s   (z<TestDispatcher.test_misaligned_array_dispatch.<locals>.checkC_contig_alignedF_contig_alignedC_contig_misalignedF_contig_misalignedr   intr6   sqrtint8r   itemsizer   viewr   T	rZ   dtcounttmpr   r   r   r   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 r   )r6   sumr   r   r   r   rc     r+   z?TestDispatcher.test_immutability_in_array_dispatch.<locals>.fooTrP   r   ri   r>   r   Fc                    sV   t jt jd|d d d d f< |rd|j_ |}|}t j|| d S )Nr>   F)r6   r   r   r   flags	writeabler   r   )r8   rA   disable_write_bitrU   r   r   r   r   r[     s   (zATestDispatcher.test_immutability_in_array_dispatch.<locals>.checkr   )r   r   r   r   )Fr   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   ri   r   r   r   r   r   rc     s   &zITestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.fooTrP   c                    sH     | jj| |dkr  | jjd |dkr"  | jjd d S d S )NCTF)rg   r   alignedc_contiguousf_contiguous)arrlayoutr   rZ   r   r   check_properties  s   zVTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.check_propertiesi  r(   ri   r>   r   r   Fr   c                    sR   t jt jd|d d d d f<  |}|}t j|| d S r=   r   r   r   r   r   r[     s   zKTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.checkr   r   r   r   )	r   r6   r   r   r   r   r   r   r   )
rZ   r  r   r   r   r   r   r   r   r[   r   )rc   r   r   r   rZ   r   -test_misaligned_high_dimension_array_dispatch  s2   
	

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   r   r   r   r   r   r   r   rc     r   z@TestDispatcher.test_dispatch_recompiles_for_scalars.<locals>.fooTrP   y      ?       @r   Fr(   ri   )	r   r6   r   r   bool_rg   r   r   r	   )rZ   rc   r   expected_sigsr   r   r   $test_dispatch_recompiles_for_scalars	  s   
z3TestDispatcher.test_dispatch_recompiles_for_scalarsc                 C   s   t dddd }| t}t | W d    n1 sw   Y  t|j}| d| | d| | d| | t}t t W d    n1 sMw   Y  t|j}| d| | tt | d S )	NTrP   c                 S   r   r   r   r   r   r   r   rc   (  rd   zITestDispatcher.test_dispatcher_raises_for_invalid_decoration.<locals>.fooz8A jit decorator was called on an already jitted functionrc   z.py_funcz&The decorated object is not a function)r   rw   rL   r   r   r   rO   rM   )rZ   rc   r   err_msgr   r   r   -test_dispatcher_raises_for_invalid_decoration%  s"   




z<TestDispatcher.test_dispatcher_raises_for_invalid_decorationN)r^   r_   r`   rh   ro   rs   ry   r   r   r   r   r   r   r   r   r   r   r   unittestskipIf
_is_armv7lr   r   r  r	  r  r   r   r   r   rb   k   s2    
&
%-

&
(
1rb   c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	TestSignatureHandlingz<
    Test support for various parameter passing styles.
    c                 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
   n1 s<w   Y  | dt|j	 | t}|  W d
   n1 s]w   Y  | dt|j	 | t}|dddd W d
   n1 sw   Y  | dt|j	 d
S )z?
        Test passing named arguments to a dispatcher.
        r(   r   r}   r$   r   r#   ri   r4      r   r$   N%too many arguments: expected 3, got 4z'not enough arguments: expected 3, got 0r   zmissing argument 'z')
r]   r%   rg   r   rj   rw   rL   r   r   r   rZ   rX   r[   r   r   r   r   test_named_args@  s*   z%TestSignatureHandling.test_named_argsc                 C   sD  |  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   n1 sMw   Y  | dt|j | t}|  W d   n1 snw   Y  | dt|j | t}|d	d
d W d   n1 sw   Y  | dt|j dS )z?
        Test omitting arguments with a default value.
        r(   r   r}   r  r#   r$   r   r   r4   r  r  Nr  z0not enough arguments: expected at least 1, got 0zmissing argument 'x')r]   r)   rw   rL   r   r   r   r  r   r   r   test_default_argsW  s2   

z'TestSignatureHandling.test_default_argsc                 C   sL  |  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	   n1 sMw   Y  | d
t|j | t}|dddd W d	   n1 srw   Y  | d
t|j | t}|ddd W d	   n1 sw   Y  | d
t|j d	S )zJ
        Test a compiled function with starargs in the signature.
        r}   r,   r4   r     r   r   r  Nz!some keyword arguments unexpectedr  )r]   r*   rw   rL   r   r   r   r  r   r   r   test_star_argsr  s*   

z$TestSignatureHandling.test_star_argsN)r^   r_   r`   __doc__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.
    Tr   N)r^   r_   r`   r  ra   r\   r   r   r   r   r    s    r  c                   @   r  )	TestGeneratedDispatcherz#
    Tests for @generated_jit.
    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 )NTrP   r  r(   r   r}   r   r   y      @      ?*   y      E@      ?r  y      @      ?)r   r3   rg   )rZ   rX   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 )NTrP   )r   r>   r   )	r   rN   r6   r?   r   float64rg   r7   r   )rZ   rX   rA   rB   r   r   r   test_generated_dtype  s     z,TestGeneratedDispatcher.test_generated_dtypec                 C   s   t ddt}| t}|d W d   n1 sw   Y  | dt|j | t}|d W d   n1 s=w   Y  | dt|j dS )zz
        Check error reporting when implementation signature doesn't match
        generating function signature.
        TrP   r   NzGshould be compatible with signature '(x, y=5)', but has signature '(x)'ri   zLshould be compatible with signature '(x, y=5)', but has signature '(x, y=6)')r   r5   rw   rL   r   r   r   )rZ   rX   r   r   r   r   test_signature_errors  s   

z-TestGeneratedDispatcher.test_signature_errorsN)r^   r_   r`   r  r   r"  r#  r   r   r   r   r    s
    	r  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zdd
dZdd Zdd Z	dd Z
dd Zeedu deedu ddd Z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 )	Nri   c                       |   S r   r   r   closurer   r   rc     r{   z1TestDispatcherMethods.test_recompile.<locals>.foor'   r|   r   r(   r   )r   rR   rg   r   r   	recompilerr   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 )Nri   zint32(int32)c                    r%  r   r   r   r&  r   r   rc     r{   z<TestDispatcherMethods.test_recompile_signatures.<locals>.foor'   r|   r(   )r   rR   r(  rr   r   r&  r   test_recompile_signatures  s   z/TestDispatcherMethods.test_recompile_signaturesc                 C   sx   t dd }|dd |dd |dd | }| t|d | D ]}| d| | d| | d| q%d S )	Nc                 S   r   r   r   explicit_arg1explicit_arg2r   r   r   rc     r{   z4TestDispatcherMethods.test_inspect_llvm.<locals>.foori   r   r(   rc   r,  r-  )r   inspect_llvmrg   r   rk   r   )rZ   rc   llvmsllvm_bcr   r   r   test_inspect_llvm  s   



z'TestDispatcherMethods.test_inspect_llvmc                 C   sb   t dd }|dd |dd |dd | }| t|d | D ]	}| d|v  q%d S )Nc                 S   r   r   r   r+  r   r   r   rc     r{   z3TestDispatcherMethods.test_inspect_asm.<locals>.foori   r   r(   rc   )r   inspect_asmrg   r   rk   
assertTrue)rZ   rc   asms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{}{}.ri   r   z^digraph "CFG for \'_ZN{}{}{})	formatr   r^   splitr   r   r3  callabledisplay)rZ   cfgr   module_name
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 |	 D ]}	| 
|	 qM| tt|	 d |j|jd	 d
}	| 
|	 d S )Nc                 S      |   S r   r   	the_arrayr   r   r   rc     r{   z3TestDispatcherMethods.test_inspect_cfg.<locals>.foori   ri   ri   ri   ri   ri   r(   c                 S   s
   t | fS r   )r   r   r   r   r   <lambda>2  s   
 z8TestDispatcherMethods.test_inspect_cfg.<locals>.<lambda>r   	signature)r   r6   r?   inspect_cfgrg   r   keyssetmaprk   rA  listr   )
rZ   rc   a1a2a3cfgss1s2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   rB  r   rC  rD  r   r   r   rc   @  r{   zGTestDispatcherMethods.test_inspect_cfg_with_python_wrapper.<locals>.foori   rF  rG  r   python)rJ  show_wrappercpythonr   )r   r6   r?   rK  r   rA  )rZ   rc   rP  rQ  rR  r=  r   r   r   $test_inspect_cfg_with_python_wrapper<  s   



z:TestDispatcherMethods.test_inspect_cfg_with_python_wrapperc                 C   sz   t dd }|dd |t  t|j|jd  j}t }|  W d    n1 s.w   Y  || v s;J d S )Nc                 S   r   r   r   rz   r   r   r   rc   R  r{   z5TestDispatcherMethods.test_inspect_types.<locals>.foori   r'   r   )	r   inspect_typesr   r   rj   r   type_annotationr   getvalue)rZ   rc   rU   outr   r   r   test_inspect_typesQ  s   


z(TestDispatcherMethods.test_inspect_typesc                 C   s   t dd }|d |d t }|  W d    n1 s w   Y  t }|j|jd d W d    n1 s<w   Y  t }|j|jd d W d    n1 sXw   Y  | | | |   d S )Nc                 S   r   rp   r   r   r   r   r   rc   a  r{   zDTestDispatcherMethods.test_inspect_types_with_signature.<locals>.foori   r   r   rI  )r   r   r\  r   rg   r^  )rZ   rc   totalfirstsecondr   r   r   !test_inspect_types_with_signature`  s   

 z7TestDispatcherMethods.test_inspect_types_with_signatureNz#please install the 'jinja2' packagez%please install the 'pygments' packagec                 C   s   t dd }|dd t  |jdd}W d    n1 sw   Y  |j D ]\}}d}|d D ]
}d	|d v r=d}q3| | q)| t}|jt dd
 W d    n1 s\w   Y  | 	dt
|j d S )Nc                 S   r   r   r   rz   r   r   r   rc   v  r{   z<TestDispatcherMethods.test_inspect_types_pretty.<locals>.foori   r'   T)prettyFpygments_linesspan)filere  z$`file` must be None if `pretty=True`)r   r   r\  annitemsr3  rw   r   r   r   r   r   )rZ   rc   ri  kv
span_foundliner   r   r   r   test_inspect_types_prettys  s&   

z/TestDispatcherMethods.test_inspect_types_prettyc                    sR   t dd   d  d tt fdd jD }  }| || d S )Nc                 S   r   rp   r   r   r   r   r   rc     r{   z;TestDispatcherMethods.test_get_annotation_info.<locals>.foori   g?c                 3   s    | ]
}  | V  qd S r   )get_annotation_inforj  r   r   r   r   r;     r<   zATestDispatcherMethods.test_get_annotation_info.<locals>.<genexpr>)r   ra   r   from_iterabler   rp  rg   )rZ   rU   rV   r   r   r   test_get_annotation_info  s   

z.TestDispatcherMethods.test_get_annotation_infoc           
      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 r   r   )Ar   jr   r   r   rY     r&   zKTestDispatcherMethods.test_issue_with_array_layout_conflict.<locals>.pyfuncr   g        r   g      @r   )orderr   ri   r   N)r   r6   arrayrg   )
rZ   rY   cfuncary_c_and_fary_cary_fexp_cexp_fgot_cgot_fr   r   r   %test_issue_with_array_layout_conflict  s   z;TestDispatcherMethods.test_issue_with_array_layout_conflict)r7  )r^   r_   r`   r)  r*  r1  r6  rA  rW  r[  r`  rd  r  r  jinja2pygmentsro  rr  r  r   r   r   r   r$    s    
"r$  c                   @   ,   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 }t||D ]\}}| ||| q2t||D ]\}}|  || qDd S )NTrP   c                 S   r   rp   r   r   r   r   r   add1  r{   zJTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.add1c                 S   s   | |S r   r   )fnr   r   r   r   re     r{   zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.barc                    s
    | S r   r   r   r  re   r   r   rc     s   
zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.foori   g333333&@r   c                 S   s   g | ]}|d  qS ri   r   )r9   r   r   r   r   r     s    zPTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.<listcomp>)r   r6   r   ziprR   )rZ   rc   inputsexpected_resultsargexpectr   r  r   test_pass_dispatcher_as_arg  s   

z<TestDispatcherFunctionBoundaries.test_pass_dispatcher_as_argc                 C   s   t dddd }|g d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 )NTrP   c                 S   s4   | d }| dd  D ]}|||}|dk r|}q
|S r   r   )seqcmpfnr   eachcmpvalr   r   r   maximum  s   
zPTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.maximum)ri   r'   r(   r}   c                 S   r.   r   r   r   r   r   r   rH    s    zQTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.<lambda>)r  r}   r,   r   c                 S      | d |d  S Nr   r   r   r   r   r   rH        )r}   r   c                 S   r  rp   r   r   r   r   r   rH    r  )r   r}   )r   rg   rO  r  r   )rZ   r  r   r   r   r   test_dispatcher_as_arg_usecase  s   
 
 
z?TestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecasec                 C   s2   t dddd }t dd }| ||| d S )NTrP   c                 S   r   r   r   )r  r   r   r   rc     rd   zRTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.fooc                 S   r   r   r   r   r   r   r   rH        zWTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.<lambda>rf   )rZ   rc   r  r   r   r   $test_dispatcher_can_return_to_python  s   
zETestDispatcherFunctionBoundaries.test_dispatcher_can_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 )NTrP   c                 S   r   rp   r   r   r   r   r   one  r{   zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.onec                    s     | S r   r   r   r  r   r   two     zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.twoc                    s      | S r   r   r   r  r   r   three     zOTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.threec                 S   s"   | d || d || d |fS )Nr   ri   r'   r   )fnsr   r   r   r   choose  s   "zPTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.chooseri   )r'   r(   r}   )r'   r'   r'   rf   )rZ   r  r  r  r   r  r   test_dispatcher_in_sequence_arg  s   

z@TestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_argN)r^   r_   r`   r  r  r  r  r   r   r   r   r    s
    	r  c                   @   s   e Zd Zdd Zdd ZdS )TestBoxingDefaultErrorc                 C   sd   dd }t |tdf}| t}|d  W d    n1 s"w   Y  | t|jd d S )Nc                 S      d S r   r   r   r   r   r   rc   	  r   z<TestBoxingDefaultError.test_unbox_runtime_error.<locals>.foo
dummy_typezcan't unbox dummy_type type)	r   r	   Dummyrw   rL   rl   rg   r   r   )rZ   rc   cresr   r   r   r   test_unbox_runtime_error  s   z/TestBoxingDefaultError.test_unbox_runtime_errorc                 C   s^   dd }t |d}| t}|  W d    n1 sw   Y  d}| t|j| d S )Nc                   S   s   t S r   )r  r   r   r   r   rc     r   z:TestBoxingDefaultError.test_box_runtime_error.<locals>.foor   z/cannot convert native Module.* to Python object)r   rw   rL   rl   r   r   r   )rZ   rc   r  r   patr   r   r   test_box_runtime_error  s   

z-TestBoxingDefaultError.test_box_runtime_errorN)r^   r_   r`   r  r  r   r   r   r   r    s    r  c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestNoRetryFailedSignaturez?Test that failed-to-compile signatures are not recompiled.
    c                 C   s   |j }| t|jd | tj |d W d    n1 s!w   Y  | t|jd | tj |d W d    n1 sDw   Y  | t|jd | tj |d W d    n1 sgw   Y  | t|jd d S )Nr   ri   r   r'   )	_compilerrg   r   _failed_cacherw   r
   TypingError)rZ   funcfcomr   r   r   run_test"  s   


z#TestNoRetryFailedSignature.run_testc                 C   s    t dddd }| | d S )NTrP   c                 S      | d S r  r   r   r   r   r   rc   3  r{   z8TestNoRetryFailedSignature.test_direct_call.<locals>.foor   r  rr   r   r   r   test_direct_call2  s   
z+TestNoRetryFailedSignature.test_direct_callc                    sN   t dddd  t dd fddt dd fdd}| | d S )	NTrP   c                 S   r  r  r   r   r   r   r   re   :  r{   z8TestNoRetryFailedSignature.test_nested_call.<locals>.barc                    s    |  d S r   r   r   )re   r   r   foobar>  r  z;TestNoRetryFailedSignature.test_nested_call.<locals>.foobarc                    s    | |  S r   r   r   re   r  r   r   rc   B  r  z8TestNoRetryFailedSignature.test_nested_call.<locals>.foor  rr   r   r  r   test_nested_call9  s   
z+TestNoRetryFailedSignature.test_nested_callc                    s<    fdd}|dd}|dd}  |d   |d d S )Nc                    s   d}ddit fdd}tdddd	 }|f fd
d	  |f| }td}rVtj}||d W d    n1 sDw   Y  dt|j	 d S ||d d S )Nr   cr   c                    s&    d  d7  < rt ddd S )Nr  ri   invoke_failedc                 S   r   r   r   r   r   r   r   rH  W  r  z]TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.trigger.<locals>.<lambda>)r
   r  r   )counter
would_failr   r   triggerQ  s   
zKTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.triggerTrP   c                 S   r  r   r   r_  r   r   r   r   identY  rd   zITestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.identc                    s@   | d | d d }t dd fdd}|r||S |S )Nr   TrP   c                    s"    | | | d  |7  < d S r  r   r  innertab_headr   r   assign`  s   
z`TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assign.<locals>.assignrq   )fsr  tab_tailr  )chain_assignr  r   r  ]  s   
zPTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assignr'   ri   r  )
r   r   r6   r?   rw   r
   r  r   r   r   )fieldr  rk  r  r  r   r_  r   r  )r  r  r  r   r[   I  s"   


z:TestNoRetryFailedSignature.test_error_count.<locals>.checkrA   Fr  Tri   )rg   )rZ   r[   ct_okct_badr   r  r   test_error_countH  s
   
-
z+TestNoRetryFailedSignature.test_error_countN)r^   r_   r`   r  r  r  r  r  r   r   r   r   r    s    r  ri   c                 C   r   r   r   r   r   r   r   add_y1~  r{   r  c                 C   s   | |rd S d S r   r   r   r   r   r   	add_ynone  s   r  c                 C   s   | | S r   r   r   r   r   r   mult  r{   r  c                 C   s   | || |  S r   r   )r   r  r   r   r   add_func  s   r  c                 C   s   | ||  |ksJ d S r   )rm   )f1r  r   r   r   _checker  s   r  c                   @   r  )
$TestMultiprocessingDefaultParametersc                 C   sf   zt d}W n ty   t }Y nw dD ]}|jt||fd}|  |t | |j	d qd S )Nspawn)ri   r'   r(   )r   rS   r   )
multiprocessingget_contextAttributeErrorProcessr  r   r   _TEST_TIMEOUTrg   exitcode)rZ   fcctxrA   pr   r   r   run_fc_multiproc  s   
z5TestMultiprocessingDefaultParameters.run_fc_multiprocc                 C      |  t dS )z Tests issue #4888N)r  r  r  r   r   r   test_int_def_param     z7TestMultiprocessingDefaultParameters.test_int_def_paramc                 C   r  )z" Tests None as a default parameterNr  r  r  r   r   r   test_none_def_param  r  z8TestMultiprocessingDefaultParameters.test_none_def_paramc                 C   r  )z( Tests a function as a default parameterNr  r  r   r   r   test_function_def_param  r  z<TestMultiprocessingDefaultParameters.test_function_def_paramN)r^   r_   r`   r  r  r  r  r   r   r   r   r    s
    r  c                   @   s   e Zd ZdZdd ZdS )TestVectorizeDifferentTargetszDTest that vectorize can be reapplied if the target is different
    c                 C   s<   t dd }tg d dd}|| tg d dd}|| d S )Nc                 S   r   r   r   r   r   r   r   r      r{   z?TestVectorizeDifferentTargets.test_cpu_vs_parallel.<locals>.addcpu)identityr   parallel)r   r   )rZ   r    custom_vectorizecustom_vectorize_2r   r   r   test_cpu_vs_parallel  s   
z2TestVectorizeDifferentTargets.test_cpu_vs_parallelN)r^   r_   r`   r  r  r   r   r   r   r    s    r  __main__)r'   r(   )r'   )r,   r   r  )Dr  platformr   r   r   	itertoolsr   ior   numpyr6   numbar   r   r   r   r   
numba.corer	   r
   r   numba.core.compilerr   numba.tests.supportr   r   numba.np.numpy_supportr   numba.core.dispatcherr   r   r   numba.testing.mainr   _RUNNER_TIMEOUTr  r  r  ImportErrorr  machiner  r   r    r%   r)   r*   r3   r5   rN   rO   rb   r  r  r  r$  r  r  r  r  r  r  r  r  r  r  r^   mainr   r   r   r   <module>   s    






   SO* }M`
"
