o
    1&i3                     @   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 d dlmZ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 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+dBddZ,dCddZ-dDddZ.dDddZ/dEd d!Z0G d"d# d#eZ1G d$d% d%e1Z2G d&d' d'e1Z3G d(d) d)e3Z4G d*d+ d+eZ5G d,d- d-eZ6G d.d/ d/e"jZ7G d0d1 d1e"jZ8edFd3d4Z9edEd5d6Z:ed7d8 Z;ee;fd9d:Z<d;d< Z=G d=d> d>ee"jZ>G d?d@ d@e"jZ?e@dAkr=e"A  dS dS )G    N)chain)StringIO)njitjittypeof	vectorize)typeserrors)_dispatcher)TestCasecaptured_stdout)as_dtype)
Dispatcher)overload)needs_lapackSerialMixin)_TIMEOUTg      N@armv7lc                 C      | S N xr   r   FC:\wamp64\www\opt\env\Lib\site-packages\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_defaults2   r%   r(   c                 G   s
   | ||fS r   r   r"   r   r   r   star_defaults6      
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
   r2   c                 C   s&   t | tjrdd }|S ddd}|S )Nc                 S   r   r   r   r   r   r   r   r,   F   r   z#bad_generated_usecase.<locals>.impl   c                 S   r-   r   r   r   r   r   r   r,   I   r    )r3   r.   r1   r   r   r   bad_generated_usecaseD   s
   
r4   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).0Zaryr   r   r   	<genexpr>P       z*dtype_generated_usecase.<locals>.<genexpr>zUnhandled Type %sc                    s   t j| j dS Nr6   )r5   onesshape)abr6   Z	out_dtyper   r   _fnW   s   z$dtype_generated_usecase.<locals>._fnr   )r/   r   miscNoneTypeZOmittedr5   Zresult_typeZDTypeZNumberClassr   	TypeErrortype)r?   r@   r6   rB   r   rA   r   dtype_generated_usecaseN   s   


rG   c                   @   s   e Zd ZeddZdd ZdS )BaseTestTZ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   checkb   s   z$BaseTest.compile_func.<locals>.checkr   )r   jit_args)rR   rQ   rS   r   rO   r   compile_funca   s   zBaseTest.compile_funcN)__name__
__module____qualname__dictrT   rU   r   r   r   r   rH   ]   s    
rH   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   foom      z)TestDispatcher.test_equality.<locals>.fooc                 S   r   r   r   r   r   r   r   barq   r\   z)TestDispatcher.test_equality.<locals>.barTFr   assertEqual)rR   r[   r]   r   r   r   test_equalityl   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   r[   }   r\   z+TestDispatcher.test_dyn_pyfunc.<locals>.foo   )r   	overloadsvaluesr_   entry_pointrW   py_func)rR   r[   crr   r   r   test_dyn_pyfunc|   s
   
zTestDispatcher.test_dyn_pyfuncc                 C   s   t dd }|  d S )Nc                   S   s   dS Nra   r   r   r   r   r   r[      r\   z,TestDispatcher.test_no_argument.<locals>.foor   rR   r[   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 )NTrI   {   i  g(@gF@y        F@l    F: z(i4, i4)   -   )r   r   rJ   assertRaisesrE   )rR   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   r   r   r   r?   r@   r   r   r   r[         z6TestDispatcher.test_ambiguous_new_version.<locals>.foora         ?r&   r'      zdidn't compile a new versionN)r   ZassertAlmostEqualr_   lenrb   )rR   r[   INTZ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 rh   r   r   r   r   r   r[      rr   z%TestDispatcher.test_lock.<locals>.fooc               
      sH   z dd W d S  ty# }  z |  W Y d } ~ d S d } ~ ww Nra   r&   )r_   	Exceptionappend)e)r	   r[   rR   r   r   wrapper   s   z)TestDispatcher.test_lock.<locals>.wrapperc                    s   g | ]}t j d qS ))target)	threadingThreadr8   ir}   r   r   
<listcomp>   s    z,TestDispatcher.test_lock.<locals>.<listcomp>   N)r   rangestartjoinZassertFalse)rR   threadstr   )r	   r[   rR   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)rs         @r'   ra   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\) -> float64Zint64)r   r   rJ   r_   ru   rb   r5   int32ro   rE   assertInstr	exceptionZfloat32assertRegexZassertNotInrR   rP   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,)ra   z(intc,intc,intc)r'   TZforceobj)ro   rE   r   r   r   r   r   )rR   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   ro   rE   r_   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   r?   r   r   r   r[     r\   z5TestDispatcher.test_disabled_compilation.<locals>.foo
(float32,)(int32,)compilation disabledra   )
r   compileZdisable_compilero   RuntimeErrorr_   r   r   ru   
signaturesrR   r[   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   r[     r\   zBTestDispatcher.test_disabled_compilation_through_list.<locals>.fooz(complex64,)r   r&   )	r   ro   r   r   r_   r   r   ru   r   r   r   r   r   &test_disabled_compilation_through_list  s   

z5TestDispatcher.test_disabled_compilation_through_listc                    sn   t dgdd  t  fdd}| tj}|  W d    n1 s%w   Y  d}| t|j| d S )Nz(intp,)c                 S   r   r   r   r   r   r   r   r[   $  r\   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.fooc                      s    d  t d d S rh   )r5   r=   r   r[   r   r   r]   (  s   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.barz?.*Invalid use of.*with parameters \(array\(float64, 1d, C\)\).*)r   ro   r	   TypingErrorr   r   r   )rR   r]   r   mr   r   r   %test_disabled_compilation_nested_call#  s   
z4TestDispatcher.test_disabled_compilation_nested_callc                    s  dd }d}|  t}tg  W d   n1 sw   Y  | |t|j tdd| |  g g  tdd|}|  t}|g  W d   n1 sSw   Y  | |t|j tdd 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   r[   9  r   z4TestDispatcher.test_fingerprint_failure.<locals>.fooz(cannot compute fingerprint of empty listNTr   rI   c                     s$   t   g } tdD ]} | } q	| S )N
   )objectr   )r   r   Zobjmode_foor   r   r]   K  s
   
z4TestDispatcher.test_fingerprint_failure.<locals>.barra   )ro   
ValueErrorr
   Zcompute_fingerprintr   r   r   r   r_   rb   rc   ru   Zlifted)rR   r[   errmsgr   Z
strict_foor]   rf   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
        TrI   c                 S   rx   rh   r   r   r   r   r   r[   \  rr   z.TestDispatcher.test_serialization.<locals>.foora   r&   N)r   r_   r   Z_memoZ_recentclearru   pickledumpsloadsZassertIsidweakrefref)	rR   r[   memoZ	memo_sizeZserialized_fooZfoo_rebuiltZid_origZ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 rh   r5   ZlinalgZmatrix_powerr   r   r   r   r[     s   z:TestDispatcher.test_misaligned_array_dispatch.<locals>.fooTrI   @   ra   r<   c                    sJ   t jt jd|d d d d f<  |}|}t j|| d S r;   r5   arange
complex128reshapetestingassert_allcloser7   r?   rM   gotr[   jitfoonrr   r   rS     s   (z<TestDispatcher.test_misaligned_array_dispatch.<locals>.checkC_contig_alignedF_contig_alignedC_contig_misalignedF_contig_misalignedr   intr5   sqrtint8r   itemsizer   viewr   T	rR   dtcounttmpr   r   r   r   rS   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   )r5   sumr   r   r   r   r[     r*   z?TestDispatcher.test_immutability_in_array_dispatch.<locals>.fooTrI   r   ra   r<   r   Fc                    sV   t jt jd|d d d d f< |rd|j_ |}|}t j|| d S )Nr<   F)r5   r   r   r   flagsZ	writeabler   r   )r7   r?   disable_write_bitrM   r   r   r   r   rS     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   ra   r   r   r   r   r   r[     s   &zITestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.fooTrI   c                    sH     | jj| |dkr  | jjd |dkr"  | jjd d S d S )NCTF)r_   r   alignedc_contiguousf_contiguous)ZarrZlayoutr   rR   r   r   check_properties  s   zVTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.check_propertiesi  r'   ra   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   rS     s   zKTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.checkr   r   r   r   )	r   r5   r   r   r   r   r   r   r   )
rR   r   r   r   r   r   r   r   r   rS   r   )r[   r   r   r   rR   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   r[     r   z@TestDispatcher.test_dispatch_recompiles_for_scalars.<locals>.fooTrI   y      ?       @r   Fr'   ra   )	r   r5   r   r   Zbool_r_   ru   r   r   )rR   r[   r   Z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 )	NTrI   c                 S   r   r   r   r   r   r   r   r[   (  r\   zITestDispatcher.test_dispatcher_raises_for_invalid_decoration.<locals>.fooz8A jit decorator was called on an already jitted functionr[   z.py_funcz&The decorated object is not a function)r   ro   rE   r   r   r   rH   rF   )rR   r[   r   err_msgr   r   r   -test_dispatcher_raises_for_invalid_decoration%  s"   




z<TestDispatcher.test_dispatcher_raises_for_invalid_decorationN)rV   rW   rX   r`   rg   rk   rp   rw   r   r   r   r   r   r   r   r   r   r   unittestskipIf
_is_armv7lr   r   r   r   r   r   r   r   r   rZ   j   s2    
&
%-

&
(
1rZ   c                   @   s(   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   rt   r#   r   r"   ra   r3      r   r#   N%too many arguments: expected 3, got 4z'not enough arguments: expected 3, got 0r   zmissing argument 'z')
rU   r$   r_   ru   rb   ro   rE   r   r   r   rR   rP   rS   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   rt   r   r"   r#   r   r   r3   r   r   Nr   z0not enough arguments: expected at least 1, got 0zmissing argument 'x')rU   r(   ro   rE   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.
        rt   r+   r3   r      r   r   r   Nz!some keyword arguments unexpectedr   )rU   r)   ro   rE   r   r   r   r   r   r   r   test_star_argsr  s*   

z$TestSignatureHandling.test_star_argsN)rV   rW   rX   __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)rV   rW   rX   r   rY   rT   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 )	Nra   c                       |   S r   r   r   closurer   r   r[     rr   z1TestDispatcherMethods.test_recompile.<locals>.foor&   rs   r   r'   r   )r   rJ   r_   ru   r   	recompilerj   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 )Nra   zint32(int32)c                    r   r   r   r   r   r   r   r[     rr   z<TestDispatcherMethods.test_recompile_signatures.<locals>.foor&   rs   r'   )r   rJ   r   rj   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   r[     rr   z4TestDispatcherMethods.test_inspect_llvm.<locals>.foora   r   r'   r[   r  r  )r   Zinspect_llvmr_   ru   rc   r   )rR   r[   ZllvmsZ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   r[     rr   z3TestDispatcherMethods.test_inspect_asm.<locals>.foora   r   r'   r[   )r   Zinspect_asmr_   ru   rc   
assertTrue)rR   r[   Z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{}{}.ra   r   z^digraph "CFG for \'_ZN{}{}{})	formatru   rV   splitr   r   r  callabledisplay)rR   cfgr}   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 |	 D ]}	| 
|	 qM| tt|	 d |j|jd	 d
}	| 
|	 d S )Nc                 S      |   S r   r   Z	the_arrayr   r   r   r[     rr   z3TestDispatcherMethods.test_inspect_cfg.<locals>.foora   ra   ra   ra   ra   ra   r'   c                 S   s
   t | fS r   )r   r   r   r   r   <lambda>  s   
 z8TestDispatcherMethods.test_inspect_cfg.<locals>.<lambda>r   	signature)r   r5   r=   inspect_cfgr_   ru   keyssetmaprc   r  listr   )
rR   r[   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   r  r   r  r  r   r   r   r[     rr   zGTestDispatcherMethods.test_inspect_cfg_with_python_wrapper.<locals>.foora   r  r  r   python)r  Zshow_wrappercpythonr   )r   r5   r=   r  r   r  )rR   r[   r!  r"  r#  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   rq   r   r   r   r[   (  rr   z5TestDispatcherMethods.test_inspect_types.<locals>.foora   r&   r   )	r   inspect_typesr   r   rb   r   Ztype_annotationr   getvalue)rR   r[   rM   outr   r   r   test_inspect_types'  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   rx   rh   r   r   r   r   r   r[   7  rr   zDTestDispatcherMethods.test_inspect_types_with_signature.<locals>.foora   r   r   r  )r   r   r*  r   r_   r+  )rR   r[   totalfirstsecondr   r   r   !test_inspect_types_with_signature6  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   rq   r   r   r   r[   L  rr   z<TestDispatcherMethods.test_inspect_types_pretty.<locals>.foora   r&   T)prettyFZpygments_linesspan)filer2  z$`file` must be None if `pretty=True`)r   r   r*  annitemsr  ro   r   r   r   r   r   )rR   r[   r5  kvZ
span_foundliner   r   r   r   test_inspect_types_prettyI  s&   

z/TestDispatcherMethods.test_inspect_types_prettyc                    sR   t dd   d  d tt fdd jD }  }| || d S )Nc                 S   rx   rh   r   r   r   r   r   r[   f  rr   z;TestDispatcherMethods.test_get_annotation_info.<locals>.foora   g?c                 3   s    | ]
}  | V  qd S r   )get_annotation_infor6  r   r   r   r   r9   m  r:   zATestDispatcherMethods.test_get_annotation_info.<locals>.<genexpr>)r   rY   r   from_iterabler   r;  r_   )rR   rM   rN   r   r   r   test_get_annotation_infoe  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   rQ   z  r%   zKTestDispatcherMethods.test_issue_with_array_layout_conflict.<locals>.pyfuncr   g        r   g      @r   )orderr   ra   r   N)r   r5   arrayr_   )
rR   rQ   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_conflictr  s   z;TestDispatcherMethods.test_issue_with_array_layout_conflict)r
  )rV   rW   rX   r  r  r  r	  r  r&  r)  r-  r1  r   r   jinja2pygmentsr:  r=  rB  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 )NTrI   c                 S   rx   rh   r   r   r   r   r   add1  rr   zJTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.add1c                 S   s   | |S r   r   )fnr   r   r   r   r]     rr   zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.barc                    s
    | S r   r   r   rG  r]   r   r   r[     s   
zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.foora   g333333&@r   c                 S   s   g | ]}|d  qS ra   r   )r8   r   r   r   r   r     s    zPTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.<listcomp>)r   r5   r   ziprJ   )rR   r[   ZinputsZexpected_resultsargexpectr   rI  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 )NTrI   c                 S   s4   | d }| dd  D ]}|||}|dk r|}q
|S r   r   )seqcmpfnr   ZeachZcmpvalr   r   r   maximum  s   
zPTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.maximum)ra   r&   r'   rt   c                 S   r-   r   r   r   r   r   r   r    s    zQTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.<lambda>)rP  rt   r+   r   c                 S      | d |d  S Nr   r   r   r   r   r   r        )rt   r   c                 S   rR  rh   r   r   r   r   r   r    rT  )r   rt   )r   r_   r   rK  r   )rR   rQ  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 )NTrI   c                 S   r   r   r   )rH  r   r   r   r[     r\   zRTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.fooc                 S   r   r   r   r   r   r   r   r        zWTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.<lambda>r^   )rR   r[   rH  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 )NTrI   c                 S   rx   rh   r   r   r   r   r   one  rr   zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.onec                    s     | S r   r   r   rX  r   r   two     zMTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.twoc                    s      | S r   r   r   rY  r   r   three     zOTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.threec                 S   s"   | d || d || d |fS )Nr   ra   r&   r   )fnsr   r   r   r   choose  s   "zPTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.choosera   )r&   r'   rt   )r&   r&   r&   r^   )rR   rZ  r\  r_  r   rY  r   test_dispatcher_in_sequence_arg  s   

z@TestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_argN)rV   rW   rX   rN  rU  rW  r`  r   r   r   r   rF    s
    	rF  c                   @   s   e Zd Zdd Zdd ZdS )TestBoxingDefaultErrorc                 C   sp   dd }t df}t||j| }| t}|d  W d    n1 s(w   Y  | t|j	d d S )Nc                 S      d S r   r   r   r   r   r   r[     r   z<TestBoxingDefaultError.test_unbox_runtime_error.<locals>.fooZ
dummy_typezcan't unbox dummy_type type)
r   ZDummyr   rb   ro   rE   rd   r_   r   r   )rR   r[   ZargtysZcresr   r   r   r   test_unbox_runtime_error  s   z/TestBoxingDefaultError.test_unbox_runtime_errorc                 C   sV   t d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   r[     r\   z:TestBoxingDefaultError.test_box_runtime_error.<locals>.fooz/cannot convert native Module.* to Python object)r   ro   rE   r   r   r   )rR   r[   r   patr   r   r   test_box_runtime_error  s   
z-TestBoxingDefaultError.test_box_runtime_errorN)rV   rW   rX   rc  re  r   r   r   r   ra    s    ra  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   ra   r   r&   )Z	_compilerr_   ru   Z_failed_cachero   r	   r   )rR   funcZfcomr   r   r   run_test  s   


z#TestNoRetryFailedSignature.run_testc                 C   s    t dddd }| | d S )NTrI   c                 S      | d S rS  r   r   r   r   r   r[   
  rr   z8TestNoRetryFailedSignature.test_direct_call.<locals>.foor   rh  rj   r   r   r   test_direct_call	  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 )	NTrI   c                 S   ri  rS  r   r   r   r   r   r]     rr   z8TestNoRetryFailedSignature.test_nested_call.<locals>.barc                    s    |  d S r   r   r   )r]   r   r   foobar  r[  z;TestNoRetryFailedSignature.test_nested_call.<locals>.foobarc                    s    | |  S r   r   r   r]   rl  r   r   r[     r]  z8TestNoRetryFailedSignature.test_nested_call.<locals>.foorj  rj   r   rm  r   test_nested_call  s   
z+TestNoRetryFailedSignature.test_nested_callc                    s<    fdd}|dd}|dd}  |d   |d d S )	Nc           	         s   d}ddidd }t |fdd}tdd	d
d }|f fdd	  |f| }td}r\tj}||d W d    n1 sJw   Y  dt|j	 d S ||d d S )Nr   cr   c                 S   s   J d)Nr   Zunreachabler   r   r   r   r   trigger(  r    zKTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.triggerc                    s&    d  d7  < rt ddd S )Nro  ra   invoke_failedc                 S   r   r   r   r   r   r   r   r  1  rV  z`TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.ol_trigger.<locals>.<lambda>)r	   r   r   )counter
would_failr   r   
ol_trigger+  s   
zNTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.ol_triggerTrI   c                 S   rb  r   r   r,  r   r   r   r   ident3  r\   zITestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.identc                    s@   | d | d d }t dd fdd}|r||S |S )Nr   TrI   c                    s"    | | | d  |7  < d S rS  r   ru  innerZtab_headr   r   assign:  s   
z`TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assign.<locals>.assignri   )fsrx  Ztab_tailry  )chain_assignrw  r   r{  7  s   
zPTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assignr&   ra   rq  )
r   r   r5   r=   ro   r	   r   r   r   r   )	fieldrs  r7  rp  rt  rv  r   r,  r   r   )r{  rr  rs  r   rS      s$   


z:TestNoRetryFailedSignature.test_error_count.<locals>.checkr?   Fro  Tra   r&   )r_   )rR   rS   Zct_okZct_badr   r   r   test_error_count  s
   
0
z+TestNoRetryFailedSignature.test_error_countN)rV   rW   rX   r   rh  rk  rn  r}  r   r   r   r   rf    s    rf  ra   c                 C   r   r   r   r   r   r   r   add_y1Y  rr   r~  c                 C   s   | |rd S d S ry   r   r   r   r   r   	add_ynone^  s   r  c                 C   s   | | S r   r   r   r   r   r   multc  rr   r  c                 C   s   | || |  S r   r   )r   rg  r   r   r   add_funch  s   r  c                 C   s   | ||  |ksJ d S r   )re   )f1rL  r   r   r   _checkerm  s   r  c                   @   rE  )
$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 )NZspawn)ra   r&   r'   )r~   rK   r   )
multiprocessingZget_contextAttributeErrorProcessr  r   r   _TEST_TIMEOUTr_   exitcode)rR   Zfcctxr?   pr   r   r   run_fc_multiprocr  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)rV   rW   rX   r  r  r  r  r   r   r   r   r  q  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     rr   z?TestVectorizeDifferentTargets.test_cpu_vs_parallel.<locals>.addcpu)identityr~   Zparallel)r   r   )rR   r   Zcustom_vectorizeZcustom_vectorize_2r   r   r   test_cpu_vs_parallel  s   
z2TestVectorizeDifferentTargets.test_cpu_vs_parallelN)rV   rW   rX   r   r  r   r   r   r   r    s    r  __main__)r&   r'   )r&   )r+   r   rJ  )Br  platformr   r   r   	itertoolsr   ior   numpyr5   Znumbar   r   r   r   Z
numba.corer   r	   r
   Znumba.tests.supportr   r   Znumba.np.numpy_supportr   Znumba.core.dispatcherr   Znumba.extendingr   r   r   Znumba.testing.mainr   Z_RUNNER_TIMEOUTr   r  rC  ImportErrorrD  machiner   r   r   r$   r(   r)   r2   r4   rG   rH   rZ   r   r   r   rF  ra  rf  r~  r  r  r  r  r  r  rV   mainr   r   r   r   <module>   s    






   TO }Md
"
