o
    i                     @   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   X/home/ubuntu/veenaModal/venv/lib/python3.10/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_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
   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,   G   r   z#bad_generated_usecase.<locals>.impl   c                 S   r-   r   r   r   r   r   r   r,   J   r    )r3   r.   r1   r   r   r   bad_generated_usecaseE   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).0aryr   r   r   	<genexpr>Q       z*dtype_generated_usecase.<locals>.<genexpr>zUnhandled Type %sc                    s   t j| j dS Nr6   )r5   onesshape)abr6   	out_dtyper   r   _fnX   s   z$dtype_generated_usecase.<locals>._fnr   )r/   r   miscNoneTypeOmittedr5   result_typeDTypeNumberClassr   	TypeErrortype)r@   rA   r6   rD   r   rB   r   dtype_generated_usecaseO   s   


rM   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)rY   rX   rZ   r   rV   r   compile_funcb   s   zBaseTest.compile_funcN)__name__
__module____qualname__dictr[   r\   r   r   r   r   rN   ^   s    
rN   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   rc   z)TestDispatcher.test_equality.<locals>.barTFr   assertEqual)rY   rb   rd   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   rb   ~   rc   z+TestDispatcher.test_dyn_pyfunc.<locals>.foo   )r   	overloadsvaluesrf   entry_pointr^   py_func)rY   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 Nrh   r   r   r   r   r   rb      rc   z,TestDispatcher.test_no_argument.<locals>.foor   rY   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    d S 1 smw   Y  d S )NTrO   {   i  g(@gF@y        F@l    F: z(i4, i4)   -   )r   r   rQ   assertRaisesrK   )rY   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@   rA   r   r   r   rb         z6TestDispatcher.test_ambiguous_new_version.<locals>.foorh         ?r&   r'      zdidn't compile a new versionN)r   assertAlmostEqualrf   lenri   )rY   rb   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 ro   r   r   r   r   r   rb      rz   z%TestDispatcher.test_lock.<locals>.fooc               
      sH   z dd W d S  ty# }  z |  W Y d } ~ d S d } ~ ww Nrh   r&   )rf   	Exceptionappend)e)r	   rb   rY   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joinassertFalse)rY   threadstr   )r	   rb   rY   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'   rh   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   rQ   rf   r~   ri   r5   int32rv   rK   assertInstr	exceptionfloat32assertRegexassertNotInrY   rW   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,)rh   z(intc,intc,intc)r'   Tforceobj)rv   rK   r   r   r   r   r   )rY   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   rv   rK   rf   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   rb     rc   z5TestDispatcher.test_disabled_compilation.<locals>.foo
(float32,)(int32,)compilation disabledrh   )
r   compiledisable_compilerv   RuntimeErrorrf   r   r   r~   
signaturesrY   rb   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   rb     rc   zBTestDispatcher.test_disabled_compilation_through_list.<locals>.fooz(complex64,)r   r&   )	r   rv   r   r   rf   r   r   r~   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   rb   %  rc   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.fooc                      s    d  t d d S ro   )r5   r>   r   rb   r   r   rd   )  s   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.barz?.*Invalid use of.*with parameters \(array\(float64, 1d, C\)\).*)r   rv   r	   TypingErrorr   r   r   )rY   rd   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   rb   :  r   z4TestDispatcher.test_fingerprint_failure.<locals>.fooz(cannot compute fingerprint of empty listNTr   rO   c                     s$   t   g } tdD ]} | } q	| S )N
   )objectr   )r   r   objmode_foor   r   rd   L  s
   
z4TestDispatcher.test_fingerprint_failure.<locals>.barrh   )rv   
ValueErrorr
   compute_fingerprintr   r   r   r   rf   ri   rj   r~   lifted)rY   rb   errmsgr   
strict_foord   rm   r   r   r   test_fingerprint_failure4  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
        TrO   c                 S   r   ro   r   r   r   r   r   rb   ]  rz   z.TestDispatcher.test_serialization.<locals>.foorh   r&   N)r   rf   r   _memo_recentclearr~   pickledumpsloadsassertIsidweakrefref)	rY   rb   memo	memo_sizeserialized_foofoo_rebuiltid_orignew_foor   r   r   r   test_serializationY  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 ro   r5   linalgmatrix_powerr   r   r   r   rb     s   z:TestDispatcher.test_misaligned_array_dispatch.<locals>.fooTrO   @   rh   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@   rT   gotrb   jitfoonrr   r   rZ     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	rY   dtcounttmpr   r   r   r   rZ   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   rb     r*   z?TestDispatcher.test_immutability_in_array_dispatch.<locals>.fooTrO   r   rh   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   flags	writeabler   r   )r7   r@   disable_write_bitrT   r   r   r   r   rZ     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   rh   r   r   r   r   r   rb     s   &zITestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.fooTrO   c                    sH     | jj| |dkr  | jjd |dkr"  | jjd d S d S )NCTF)rf   r   alignedc_contiguousf_contiguous)arrlayoutr  rY   r   r   check_properties  s   zVTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.check_propertiesi  r'   rh   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   rZ     s   zKTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.checkr   r   r   r   )	r   r5   r   r   r   r   r   r   r   )
rY   r  r   r   r   r   r   r   r   rZ   r   )rb   r   r   r   rY   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   rb     r   z@TestDispatcher.test_dispatch_recompiles_for_scalars.<locals>.fooTrO   y      ?       @r   Fr'   rh   )	r   r5   r   r   bool_rf   r~   r   r   )rY   rb   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 )	NTrO   c                 S   r   r   r   r   r   r   r   rb   )  rc   zITestDispatcher.test_dispatcher_raises_for_invalid_decoration.<locals>.fooz8A jit decorator was called on an already jitted functionrb   z.py_funcz&The decorated object is not a function)r   rv   rK   r   r   r   rN   rL   )rY   rb   r   err_msgr   r   r   -test_dispatcher_raises_for_invalid_decoration&  s"   




z<TestDispatcher.test_dispatcher_raises_for_invalid_decorationN)r]   r^   r_   rg   rn   rr   rx   r   r   r   r   r   r   r   r   r   r   r   unittestskipIf
_is_armv7lr   r   r  r  r  r   r   r   r   ra   k   s2    
&
%-

&
(
1ra   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   r|   r#   r   r"   rh   r3      r   r#   N%too many arguments: expected 3, got 4z'not enough arguments: expected 3, got 0r   zmissing argument 'z')
r\   r$   rf   r~   ri   rv   rK   r   r   r   rY   rW   rZ   r   r   r   r   test_named_argsA  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   r3   r  r  Nr  z0not enough arguments: expected at least 1, got 0zmissing argument 'x')r\   r(   rv   rK   r   r   r   r  r   r   r   test_default_argsX  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+   r3   r     r   r   r  Nz!some keyword arguments unexpectedr  )r\   r)   rv   rK   r   r   r   r  r   r   r   test_star_argss  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  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 )	Nrh   c                       |   S r   r   r   closurer   r   rb     rz   z1TestDispatcherMethods.test_recompile.<locals>.foor&   r{   r   r'   r   )r   rQ   rf   r~   r   	recompilerq   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 )Nrh   zint32(int32)c                    r   r   r   r   r!  r   r   rb     rz   z<TestDispatcherMethods.test_recompile_signatures.<locals>.foor&   r{   r'   )r   rQ   r#  rq   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   rb     rz   z4TestDispatcherMethods.test_inspect_llvm.<locals>.foorh   r   r'   rb   r'  r(  )r   inspect_llvmrf   r~   rj   r   )rY   rb   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   rb     rz   z3TestDispatcherMethods.test_inspect_asm.<locals>.foorh   r   r'   rb   )r   inspect_asmrf   r~   rj   
assertTrue)rY   rb   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{}{}.rh   r   z^digraph "CFG for \'_ZN{}{}{})	formatr~   r]   splitr   r   r.  callabledisplay)rY   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   rb     rz   z3TestDispatcherMethods.test_inspect_cfg.<locals>.foorh   rh   rh   rh   rh   rh   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_cfgrf   r~   keyssetmaprj   r<  listr   )
rY   rb   a1a2a3cfgss1s2s3r8  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   rb     rz   zGTestDispatcherMethods.test_inspect_cfg_with_python_wrapper.<locals>.foorh   rA  rB  r   python)rE  show_wrappercpythonr   )r   r5   r>   rF  r   r<  )rY   rb   rK  rL  rM  r8  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   ry   r   r   r   rb   )  rz   z5TestDispatcherMethods.test_inspect_types.<locals>.foorh   r&   r   )	r   inspect_typesr   r   ri   r   type_annotationr   getvalue)rY   rb   rT   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   r   ro   r   r   r   r   r   rb   8  rz   zDTestDispatcherMethods.test_inspect_types_with_signature.<locals>.foorh   r   r   rD  )r   r   rW  r   rf   rY  )rY   rb   totalfirstsecondr   r   r   !test_inspect_types_with_signature7  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   ry   r   r   r   rb   M  rz   z<TestDispatcherMethods.test_inspect_types_pretty.<locals>.foorh   r&   T)prettyFpygments_linesspan)filer`  z$`file` must be None if `pretty=True`)r   r   rW  annitemsr.  rv   r   r   r   r   r   )rY   rb   rd  kv
span_foundliner   r   r   r   test_inspect_types_prettyJ  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   ro   r   r   r   r   r   rb   g  rz   z;TestDispatcherMethods.test_get_annotation_info.<locals>.foorh   g?c                 3   s    | ]
}  | V  qd S r   )get_annotation_infore  r   r   r   r   r:   n  r;   zATestDispatcherMethods.test_get_annotation_info.<locals>.<genexpr>)r   r`   r   from_iterabler   rk  rf   )rY   rT   rU   r   r   r   test_get_annotation_infof  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   rX   {  r%   zKTestDispatcherMethods.test_issue_with_array_layout_conflict.<locals>.pyfuncr   g        r   g      @r   )orderr   rh   r   N)r   r5   arrayrf   )
rY   rX   cfuncary_c_and_fary_cary_fexp_cexp_fgot_cgot_fr   r   r   %test_issue_with_array_layout_conflicts  s   z;TestDispatcherMethods.test_issue_with_array_layout_conflict)r2  )r]   r^   r_   r$  r%  r,  r1  r<  rR  rV  r[  r_  r  r  jinja2pygmentsrj  rm  rz  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 )NTrO   c                 S   r   ro   r   r   r   r   r   add1  rz   zJTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.add1c                 S   s   | |S r   r   )fnr   r   r   r   rd     rz   zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.barc                    s
    | S r   r   r   r  rd   r   r   rb     s   
zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.foorh   g333333&@r   c                 S   s   g | ]}|d  qS rh   r   )r8   r   r   r   r   r     s    zPTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.<listcomp>)r   r5   r   ziprQ   )rY   rb   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 )NTrO   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)rh   r&   r'   r|   c                 S   r-   r   r   r   r   r   r   rC    s    zQTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.<lambda>)r  r|   r+   r   c                 S      | d |d  S Nr   r   r   r   r   r   rC        )r|   r   c                 S   r  ro   r   r   r   r   r   rC    r  )r   r|   )r   rf   rJ  r  r   )rY   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 )NTrO   c                 S   r   r   r   )r  r   r   r   rb     rc   zRTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.fooc                 S   r   r   r   r   r   r   r   rC        zWTestDispatcherFunctionBoundaries.test_dispatcher_can_return_to_python.<locals>.<lambda>re   )rY   rb   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 )NTrO   c                 S   r   ro   r   r   r   r   r   one  rz   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   rh   r&   r   )fnsr   r   r   r   choose  s   "zPTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.chooserh   )r&   r'   r|   )r&   r&   r&   re   )rY   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   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   rb     r   z<TestBoxingDefaultError.test_unbox_runtime_error.<locals>.foo
dummy_typezcan't unbox dummy_type type)
r   Dummyr   ri   rv   rK   rk   rf   r   r   )rY   rb   argtys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   rb     rc   z:TestBoxingDefaultError.test_box_runtime_error.<locals>.fooz/cannot convert native Module.* to Python object)r   rv   rK   r   r   r   )rY   rb   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                   @   s6   e Zd ZdZdd Zdd Zdd Zej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   rh   r   r&   )	_compilerrf   r~   _failed_cacherv   r	   r   )rY   funcfcomr   r   r   run_test  s   


z#TestNoRetryFailedSignature.run_testc                 C   s    t dddd }| | d S )NTrO   c                 S      | d S r  r   r   r   r   r   rb     rz   z8TestNoRetryFailedSignature.test_direct_call.<locals>.foor   r  rq   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 )	NTrO   c                 S   r  r  r   r   r   r   r   rd     rz   z8TestNoRetryFailedSignature.test_nested_call.<locals>.barc                    s    |  d S r   r   r   )rd   r   r   foobar  r  z;TestNoRetryFailedSignature.test_nested_call.<locals>.foobarc                    s    | |  S r   r   r   rd   r  r   r   rb     r  z8TestNoRetryFailedSignature.test_nested_call.<locals>.foor  rq   r   r  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   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 )Nr  rh   invoke_failedc                 S   r   r   r   r   r   r   r   rC  5  r  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_triggerTrO   c                 S   r  r   r   rZ  r   r   r   r   ident7  rc   zITestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.identc                    s@   | d | d d }t dd fdd}|r||S |S )Nr   TrO   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>.assignrp   )fsr  tab_tailr  )chain_assignr  r   r  ;  s   
zPTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assignr&   rh   r  )
r   r   r5   r>   rv   r	   r   r   r   r   )	fieldr  rf  r  r  r  r   rZ  r   r  )r  r  r  r   rZ   $  s$   


z:TestNoRetryFailedSignature.test_error_count.<locals>.checkr@   Fr  Trh   )rf   )rY   rZ   ct_okct_badr   r  r   test_error_count   s
   
0
z+TestNoRetryFailedSignature.test_error_countN)
r]   r^   r_   r  r  r  r  r  expectedFailurer  r   r   r   r   r    s    r  rh   c                 C   r   r   r   r   r   r   r   add_y1\  rz   r  c                 C   s   | |rd S d S r   r   r   r   r   r   	add_ynonea  s   r  c                 C   s   | | S r   r   r   r   r   r   multf  rz   r  c                 C   s   | || |  S r   r   )r   r  r   r   r   add_funck  s   r  c                 C   s   | ||  |ksJ d S r   )rl   )f1r  r   r   r   _checkerp  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)rh   r&   r'   )r   rR   r   )
multiprocessingget_contextAttributeErrorProcessr  r   r   _TEST_TIMEOUTrf   exitcode)rY   fcctxr@   pr   r   r   run_fc_multiprocu  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  t  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     rz   z?TestVectorizeDifferentTargets.test_cpu_vs_parallel.<locals>.addcpu)identityr   parallel)r   r   )rY   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  )Br  platformr   r   r   	itertoolsr   ior   numpyr5   numbar   r   r   r   
numba.corer   r	   r
   numba.tests.supportr   r   numba.np.numpy_supportr   numba.core.dispatcherr   numba.extendingr   r   r   numba.testing.mainr   _RUNNER_TIMEOUTr  r  r{  ImportErrorr|  machiner  r   r   r$   r(   r)   r2   r4   rM   rN   ra   r  r  r  r~  r  r  r  r  r  r  r  r  r  r]   mainr   r   r   r   <module>   s    






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