o
    iM                     @   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   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/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
   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).0Z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   Z	out_dtyper   r   _fnX   s   z$dtype_generated_usecase.<locals>._fnr   )r0   r	   miscNoneTypeZOmittedr6   Zresult_typeZDTypeZNumberClassr   	TypeErrortype)r@   rA   r7   rC   r   rB   r   dtype_generated_usecaseO   s   


rH   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   checkc   s   z$BaseTest.compile_func.<locals>.checkr   )r   jit_args)rS   rR   rT   r   rP   r   compile_funcb   s   zBaseTest.compile_funcN)__name__
__module____qualname__dictrU   rV   r   r   r   r   rI   ^   s    
rI   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   r]   z)TestDispatcher.test_equality.<locals>.barTFr   assertEqual)rS   r\   r^   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   r\   ~   r]   z+TestDispatcher.test_dyn_pyfunc.<locals>.foo   )r   	overloadsvaluesr`   entry_pointrX   py_func)rS   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 Nrb   r   r   r   r   r   r\      r]   z,TestDispatcher.test_no_argument.<locals>.foor   rS   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 )NTrJ   {   i  g(@gF@y        F@l    F: z(i4, i4)   -   )r   r    rK   assertRaisesrF   )rS   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@   rA   r   r   r   r\         z6TestDispatcher.test_ambiguous_new_version.<locals>.foorb         ?r'   r(      zdidn't compile a new versionN)r   ZassertAlmostEqualr`   lenrc   )rS   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 ri   r   r   r   r   r   r\      rs   z%TestDispatcher.test_lock.<locals>.fooc               
      sH   z dd W d S  ty# }  z |  W Y d } ~ d S d } ~ ww Nrb   r'   )r`   	Exceptionappend)e)r
   r\   rS   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joinZassertFalse)rS   threadstr   )r
   r\   rS   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)rt         @r(   rb   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    rK   r`   rv   rc   r6   int32rp   rF   assertInstr	exceptionfloat32assertRegexpMatchesZassertNotInrS   rQ   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,)rb   z(intc,intc,intc)r(   TZforceobj)rp   rF   r   r    r   r   r   )rS   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    rp   rF   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 disabledrb   )
r   compileZdisable_compilerp   RuntimeErrorr`   r   r   rv   
signaturesrS   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   rp   r   r   r`   r   r   rv   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   r\   %  r]   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.fooc                      s    d  t d d S ri   )r6   r>   r   r\   r   r   r^   )  s   zATestDispatcher.test_disabled_compilation_nested_call.<locals>.barzANo matching definition for argument type(s) array(float64, 1d, C))r   rp   rF   r`   r   r   )rS   r^   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   r\   9  r]   z4TestDispatcher.test_fingerprint_failure.<locals>.fooz(cannot compute fingerprint of empty listNTrJ   c                     s$   t   g } tdD ]} | } q	| S )N
   )objectr   )r   r   r   r   r   r^   K  s
   
z4TestDispatcher.test_fingerprint_failure.<locals>.barrb   )r   rp   
ValueErrorr   Zcompute_fingerprintr   r   r   r`   rf   rc   rd   rv   Zlifted)rS   errmsgr   Z
strict_foor^   rg   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
        TrJ   c                 S   ry   ri   r   r   r   r   r   r\   \  rs   z.TestDispatcher.test_serialization.<locals>.foorb   r'   N)r   r`   r   Z_memoZ_recentclearrv   pickledumpsloadsZassertIsidweakrefref)	rS   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 ri   r6   ZlinalgZmatrix_powerr   r   r   r   r\     s   z:TestDispatcher.test_misaligned_array_dispatch.<locals>.fooTrJ   @   rb   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   r@   rN   gotr\   jitfoonrr   r   rT     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	rS   dtcounttmpr   r   r   r   rT   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   r\     r+   z?TestDispatcher.test_immutability_in_array_dispatch.<locals>.fooTrJ   r   rb   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   flagsZ	writeabler   r   )r8   r@   disable_write_bitrN   r   r   r   r   rT     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   rb   r   r   r   r   r   r\     s   &zITestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.fooTrJ   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   rS   r   r   check_properties  s   zVTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.check_propertiesi  r(   rb   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   rT     s   zKTestDispatcher.test_misaligned_high_dimension_array_dispatch.<locals>.checkr   r   r   r   )	r   r6   r   r   r   r   r   r   r   )
rS   r   r   r   r   r   r   r   r   rT   r   )r\   r   r   r   rS   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>.fooTrJ   y      ?       @r   Fr(   rb   )	r   r6   r   r   Zbool_r`   rv   r   r	   )rS   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 )	NTrJ   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   rp   rF   r   r   r   rI   rG   )rS   r\   r   err_msgr   r   r   -test_dispatcher_raises_for_invalid_decoration%  s"   




z<TestDispatcher.test_dispatcher_raises_for_invalid_decorationN)rW   rX   rY   ra   rh   rl   rq   rx   r   r   r   r   r   r   r   r   r   r   unittestskipIf
_is_armv7lr   r   r   r   r   r   r   r   r   r[   k   s2    
&
%-

&
(
1r[   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   ru   r$   r   r#   rb   r4      r   r$   N%too many arguments: expected 3, got 4z'not enough arguments: expected 3, got 0r   zmissing argument 'z')
rV   r%   r`   rv   rc   rp   rF   r   r   r   rS   rQ   rT   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   ru   r   r#   r$   r   r   r4   r   r   Nr   z0not enough arguments: expected at least 1, got 0zmissing argument 'x')rV   r)   rp   rF   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.
        ru   r,   r4   r      r   r   r   Nz!some keyword arguments unexpectedr   )rV   r*   rp   rF   r   r   r   r   r   r   r   test_star_argsr  s*   

z$TestSignatureHandling.test_star_argsN)rW   rX   rY   __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)rW   rX   rY   r   rZ   rU   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 )NTrJ   r   r(   r   ru   r   r   y      @      ?*   y      E@      ?r   y      @      ?)r   r3   r`   )rS   rQ   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 )NTrJ   )r   r=   r   )	r   rH   r6   r>   r   Zfloat64r`   r7   r   )rS   rQ   r@   rA   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.
        TrJ   r   NzGshould be compatible with signature '(x, y=5)', but has signature '(x)'rb   zLshould be compatible with signature '(x, y=5)', but has signature '(x, y=6)')r   r5   rp   rF   r   r   r   )rS   rQ   r   r   r   r   test_signature_errors  s   

z-TestGeneratedDispatcher.test_signature_errorsN)rW   rX   rY   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 )	Nrb   c                       |   S r   r   r   closurer   r   r\     rs   z1TestDispatcherMethods.test_recompile.<locals>.foor'   rt   r   r(   r   )r   rK   r`   rv   r   	recompilerk   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 )Nrb   zint32(int32)c                    r  r   r   r   r  r   r   r\     rs   z<TestDispatcherMethods.test_recompile_signatures.<locals>.foor'   rt   r(   )r   rK   r  rk   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\     rs   z4TestDispatcherMethods.test_inspect_llvm.<locals>.foorb   r   r(   r\   r
  r  )r   Zinspect_llvmr`   rv   rd   r   )rS   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\     rs   z3TestDispatcherMethods.test_inspect_asm.<locals>.foorb   r   r(   r\   )r   Zinspect_asmr`   rv   rd   
assertTrue)rS   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{}{}.rb   r   z^digraph "CFG for \'_ZN{}{}{})	formatrv   rW   splitr   r   r  callabledisplay)rS   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\     rs   z3TestDispatcherMethods.test_inspect_cfg.<locals>.foorb   rb   rb   rb   rb   rb   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_cfgr`   rv   keyssetmaprd   r  listr   )
rS   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\   @  rs   zGTestDispatcherMethods.test_inspect_cfg_with_python_wrapper.<locals>.foorb   r  r  r   python)r!  Zshow_wrappercpythonr   )r   r6   r>   r"  r   r  )rS   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   rr   r   r   r   r\   R  rs   z5TestDispatcherMethods.test_inspect_types.<locals>.foorb   r'   r   )	r   inspect_typesr   r   rc   r   Ztype_annotationr   getvalue)rS   r\   rN   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   ry   ri   r   r   r   r   r   r\   a  rs   zDTestDispatcherMethods.test_inspect_types_with_signature.<locals>.foorb   r   r   r   )r   r   r0  r   r`   r1  )rS   r\   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   rr   r   r   r   r\   v  rs   z<TestDispatcherMethods.test_inspect_types_pretty.<locals>.foorb   r'   T)prettyFZpygments_linesspan)filer8  z$`file` must be None if `pretty=True`)r   r   r0  annitemsr  rp   r   r   r   r   r   )rS   r\   r;  kvZ
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   ry   ri   r   r   r   r   r   r\     rs   z;TestDispatcherMethods.test_get_annotation_info.<locals>.foorb   g?c                 3   s    | ]
}  | V  qd S r   )get_annotation_infor<  r   r   r   r   r:     r;   zATestDispatcherMethods.test_get_annotation_info.<locals>.<genexpr>)r   rZ   r   from_iterabler   rA  r`   )rS   rN   rO   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   rR     r&   zKTestDispatcherMethods.test_issue_with_array_layout_conflict.<locals>.pyfuncr   g        r   g      @r   )orderr   rb   r   N)r   r6   arrayr`   )
rS   rR   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_conflict  s   z;TestDispatcherMethods.test_issue_with_array_layout_conflict)r  )rW   rX   rY   r  r  r  r  r  r,  r/  r3  r7  r   r   jinja2pygmentsr@  rC  rH  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 )NTrJ   c                 S   ry   ri   r   r   r   r   r   add1  rs   zJTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.add1c                 S   s   | |S r   r   )fnr   r   r   r   r^     rs   zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.barc                    s
    | S r   r   r   rM  r^   r   r   r\     s   
zITestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.foorb   g333333&@r   c                 S   s   g | ]}|d  qS rb   r   )r9   r   r   r   r   r     s    zPTestDispatcherFunctionBoundaries.test_pass_dispatcher_as_arg.<locals>.<listcomp>)r   r6   r   ziprK   )rS   r\   ZinputsZexpected_resultsargexpectr   rO  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 )NTrJ   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)rb   r'   r(   ru   c                 S   r.   r   r   r   r   r   r   r    s    zQTestDispatcherFunctionBoundaries.test_dispatcher_as_arg_usecase.<locals>.<lambda>)rV  ru   r,   r   c                 S      | d |d  S Nr   r   r   r   r   r   r        )ru   r   c                 S   rX  ri   r   r   r   r   r   r    rZ  )r   ru   )r   r`   r&  rQ  r   )rS   rW  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 )NTrJ   c                 S   r   r   r   )rN  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_   )rS   r\   rN  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 )NTrJ   c                 S   ry   ri   r   r   r   r   r   one  rs   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   rb   r'   r   )fnsr   r   r   r   choose  s   "zPTestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_arg.<locals>.chooserb   )r'   r(   ru   )r'   r'   r'   r_   )rS   r`  rb  re  r   r_  r   test_dispatcher_in_sequence_arg  s   

z@TestDispatcherFunctionBoundaries.test_dispatcher_in_sequence_argN)rW   rX   rY   rT  r[  r]  rf  r   r   r   r   rL    s
    	rL  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   r\   	  r   z<TestBoxingDefaultError.test_unbox_runtime_error.<locals>.fooZ
dummy_typezcan't unbox dummy_type type)	r   r	   ZDummyrp   rF   re   r`   r   r   )rS   r\   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   r\     r   z:TestBoxingDefaultError.test_box_runtime_error.<locals>.foor   z/cannot convert native Module.* to Python object)r   rp   rF   re   r   r   r   )rS   r\   ri  r   patr   r   r   test_box_runtime_error  s   

z-TestBoxingDefaultError.test_box_runtime_errorN)rW   rX   rY   rj  rl  r   r   r   r   rg    s    rg  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   rb   r   r'   )Z	_compilerr`   rv   Z_failed_cacherp   r
   TypingError)rS   funcZfcomr   r   r   run_test"  s   


z#TestNoRetryFailedSignature.run_testc                 C   s    t dddd }| | d S )NTrJ   c                 S      | d S rY  r   r   r   r   r   r\   3  rs   z8TestNoRetryFailedSignature.test_direct_call.<locals>.foor   rp  rk   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 )	NTrJ   c                 S   rq  rY  r   r   r   r   r   r^   :  rs   z8TestNoRetryFailedSignature.test_nested_call.<locals>.barc                    s    |  d S r   r   r   )r^   r   r   foobar>  ra  z;TestNoRetryFailedSignature.test_nested_call.<locals>.foobarc                    s    | |  S r   r   r   r^   rt  r   r   r\   B  rc  z8TestNoRetryFailedSignature.test_nested_call.<locals>.foorr  rk   r   ru  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 )Nrw  rb   invoke_failedc                 S   r   r   r   r   r   r   r   r  W  r\  z]TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.trigger.<locals>.<lambda>)r
   rn  r   )counter
would_failr   r   triggerQ  s   
zKTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.triggerTrJ   c                 S   rh  r   r   r2  r   r   r   r   identY  r]   zITestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.identc                    s@   | d | d d }t dd fdd}|r||S |S )Nr   TrJ   c                    s"    | | | d  |7  < d S rY  r   r|  innerZtab_headr   r   assign`  s   
z`TestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assign.<locals>.assignrj   )fsr  Ztab_tailr  )chain_assignr~  r   r  ]  s   
zPTestNoRetryFailedSignature.test_error_count.<locals>.check.<locals>.chain_assignr'   rb   rx  )
r   r   r6   r>   rp   r
   rn  r   r   r   )fieldrz  r=  r{  r}  r   r2  r   r   )r  ry  rz  r   rT   I  s"   


z:TestNoRetryFailedSignature.test_error_count.<locals>.checkr@   Frw  Trb   )r`   )rS   rT   Zct_okZct_badr   r   r   test_error_countH  s
   
-
z+TestNoRetryFailedSignature.test_error_countN)rW   rX   rY   r   rp  rs  rv  r  r   r   r   r   rm    s    rm  rb   c                 C   r   r   r   r   r   r   r   add_y1~  rs   r  c                 C   s   | |rd S d S rz   r   r   r   r   r   	add_ynone  s   r  c                 C   s   | | S r   r   r   r   r   r   mult  rs   r  c                 C   s   | || |  S r   r   )r   ro  r   r   r   add_func  s   r  c                 C   s   | ||  |ksJ d S r   )rf   )f1rR  r   r   r   _checker  s   r  c                   @   rK  )
$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)rb   r'   r(   )r   rL   r   )
multiprocessingZget_contextAttributeErrorProcessr  r   r   _TEST_TIMEOUTr`   exitcode)rS   Zfcctxr@   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)rW   rX   rY   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      rs   z?TestVectorizeDifferentTargets.test_cpu_vs_parallel.<locals>.addcpu)identityr   Zparallel)r   r   )rS   r    Zcustom_vectorizeZcustom_vectorize_2r   r   r   test_cpu_vs_parallel  s   
z2TestVectorizeDifferentTargets.test_cpu_vs_parallelN)rW   rX   rY   r   r  r   r   r   r   r    s    r  __main__)r'   r(   )r'   )r,   r   rP  )Dr  platformr   r   r   	itertoolsr   ior   numpyr6   Znumbar   r   r   r   r   Z
numba.corer	   r
   r   Znumba.core.compilerr   Znumba.tests.supportr   r   Znumba.np.numpy_supportr   Znumba.core.dispatcherr   r   r   Znumba.testing.mainr   Z_RUNNER_TIMEOUTr   r  rI  ImportErrorrJ  machiner   r   r    r%   r)   r*   r3   r5   rH   rI   r[   r   r   r   r  rL  rg  rm  r  r  r  r  r  r  r  rW   mainr   r   r   r   <module>   s    






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