o
    i                     @   s   d Z ddlZddl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 Zd	d
 Zdd Ze Zde_dd Zdd ZG dd deZG dd deZedkrXe  dS dS )z!
Testing object mode specifics.

    N)compile_isolatedFlags)jit)utils)TestCasec                 C   s   | d }|d S )N   y              @ )ntmpr   r   k/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_object_mode.pycomplex_constant   s   r   c                 C   s   | d S )Nl         4LEh*r-P3OF r   r	   r   r   r   long_constant   s   r   c                 C   s   | d d = d S Nr   xr   r   r   delitem_usecase      r   Tc                 C   sB   d}t | D ]}t |D ]}t | | D ]}||| 7 }qqq|S Nr   )range)r   yr	   ijkr   r   r   loop_nest_3    s   r   c                 C      | S r   r   r   r   r   r   array_of_object*      r   c                   @   sD   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S )TestObjectModec                 C   0   t }t|dtd}|j}| |d|d d S Nr   flags   )r   r   forceobjentry_pointassertPreciseEqualselfpyfunccrescfuncr   r   r   test_complex_constant0      z$TestObjectMode.test_complex_constantc                 C   r   r    )r   r   r$   r%   r&   r'   r   r   r   test_long_constant6   r-   z!TestObjectMode.test_long_constantc                    sh   t tdtd}|j | dd dd fdd} fdd}tt| tt| dS )	zm
        Test bug that decref the iterator early.
        If the bug occurs, a segfault should occur
        r   r!      c                          dd d S Nr/   r   r   )r)   r   r   	bm_pyfuncF   r   z0TestObjectMode.test_loop_nest.<locals>.bm_pyfuncc                      r0   r1   r   r   )r+   r   r   bm_cfuncI   r   z/TestObjectMode.test_loop_nest.<locals>.bm_cfuncN)r   r   r$   r%   assertEqualprintr   Z	benchmark)r(   r*   r2   r3   r   )r+   r)   r   test_loop_nest<   s   zTestObjectMode.test_loop_nestc                 C   s.   t t}tt gd }| ||| d S )N
   )r   r   nparrayobjectZassertIs)r(   r+   Zobjarrr   r   r   test_array_of_objectO   s   z#TestObjectMode.test_array_of_objectc                 C   s   t dddd }| |dddg | |dddg | |dddg | t}|dd W d   n1 s<w   Y  | d	t|j dS )
z6
        Test handling of the `in` comparison
        Tr$   c                 S   s   | |v S r   r   )r   r   r   r   r   fooX      z2TestObjectMode.test_sequence_contains.<locals>.foo   r      Nzis not iterable)r   
assertTrueassertFalseassertRaises	TypeErrorZassertInstr	exception)r(   r=   Zraisesr   r   r   test_sequence_containsT   s   
z%TestObjectMode.test_sequence_containsc                 C   sl   t }t|dtd}|j}g d}|| | |g  | t |d W d    d S 1 s/w   Y  d S )Nr   r!   )   r   r/   *   )r   r   r$   r%   r&   rC   rD   )r(   r)   r*   r+   lr   r   r   test_deliteme   s   
"zTestObjectMode.test_delitemc                    sT   dd  t dd fdd}d}||}||}| |t| | || d S )Nc                  W   r   r   r   r   r   r   r   consumerq   r   z8TestObjectMode.test_starargs_non_tuple.<locals>.consumerTr<   c                    s    |  S r   r   r   rL   r   r   r=   t   r>   z3TestObjectMode.test_starargs_non_tuple.<locals>.fooZijo)r   Zpy_funcr4   tuple)r(   r=   arggotexpectr   rM   r   test_starargs_non_tuplep   s   
z&TestObjectMode.test_starargs_non_tupleN)
__name__
__module____qualname__r,   r.   r6   r;   rG   rK   rR   r   r   r   r   r   .   s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestObjectModeInvalidRewritezM
    Tests to ensure that rewrite passes didn't affect objmode lowering.
    c                 C   s   |  |j | |j |S r   )rA   Z
signaturesrB   Znopython_signatures)r(   Zdispr   r   r   _ensure_objmode   s   z,TestObjectModeInvalidRewrite._ensure_objmodec                    s>   dd   fdd}t |}| |d|d | | dS )zo
        Test code based on user submitted issue at
        https://github.com/numba/numba/issues/2159
        c                 S   r   r   r   r   r   r   r   test0   r   zQTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallback.<locals>.test0c                    s   | dkrt   | S r   )
ValueErrorr   rX   r   r   test1   s   zQTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallback.<locals>.test1r7   N)r   r4   rW   )r(   r[   compiledr   rZ   r   %test_static_raise_in_objmode_fallback   s
   zBTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallbackc                    sV   dd   fdd}t |}tdgtdgf}| || ||  | | dS )zo
        Test code based on user submitted issue at
        https://github.com/numba/numba/issues/2169
        c                 S   r   r   r   r   r   r   r   rX      r   zSTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallback.<locals>.test0c                    s&   t | } d|d<  |  |  S )Nr?   r   )r8   Zasarraysum)Za1Za2rZ   r   r   test   s   
zRTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallback.<locals>.testrH   r   N)r   r8   r9   r4   rW   )r(   r_   r\   argsr   rZ   r   'test_static_setitem_in_objmode_fallback   s   zDTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallbackc                 C   sD   d}|d7 }i }dt i}t||| |d }tdd|}|  dS )zG
        Test issue https://github.com/numba/numba/issues/3355
        zdef func():
z    np.array([1,2,3])
r8   funcTr<   N)r8   execr   )r(   Z	func_textZloc_varsZcustom_globalsrb   Zjittedr   r   r   test_dynamic_func_objmode   s   
z6TestObjectModeInvalidRewrite.test_dynamic_func_objmodeN)rS   rT   rU   __doc__rW   r]   ra   rd   r   r   r   r   rV      s    rV   __main__)re   numpyr8   ZunittestZnumba.core.compilerr   r   Znumbar   Z
numba.corer   Znumba.tests.supportr   r   r   r   r$   Zforce_pyobjectr   r   r   rV   rS   mainr   r   r   r   <module>   s&    
Q@