a
    –§»a,  ã                   @   s�   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZG dd„ de	ƒZ
dd„ Zd	d
„ ZG dd„ deƒZG dd„ deƒZedkrŒe ¡  dS )é    N)Újit)Útypes)ÚTestCasec                   @   s   e Zd Zdd„ ZdS )ÚDummyc                 C   s   |d S )Né   © )ÚselfÚotherr   r   úX/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/test_func_lifetime.pyÚ__add__   s    zDummy.__add__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r
   r   
   s   r   c                 C   s   | d S ©Né   r   ©Úxr   r   r
   Úglobal_usecase1   s    r   c                   C   s   t d S r   )Ú
global_objr   r   r   r
   Úglobal_usecase2   s    r   c                   @   sp   e Zd 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S )ÚTestFuncLifetimezP
    Test the lifetime of compiled function objects and their dependencies.
    c                 C   s*   |   t|jƒd¡ t|j ¡ ƒd }|jS )zV
        Get the single implementation (a C function object) of a dispatcher.
        r   r   )ÚassertEqualÚlenZ	overloadsÚlistÚvaluesÚentry_point)r   Ú
dispatcherZcresr   r   r
   Úget_impl   s    zTestFuncLifetime.get_implc                 K   s†   dd„ }t d	i |¤Ž|ƒ}|  |dƒd¡ |  |¡}dd„ |||jfD ƒ}d  } } }}t ¡  |  dd„ |D ƒd gt|ƒ ¡ d S )
Nc                 S   s   | d S r   r   r   r   r   r
   Úf%   s    z5TestFuncLifetime.check_local_func_lifetime.<locals>.fúint32(int32)r   é   c                 S   s   g | ]}t  |¡‘qS r   ©ÚweakrefÚref©Ú.0Úobjr   r   r
   Ú
<listcomp>1   ó    z>TestFuncLifetime.check_local_func_lifetime.<locals>.<listcomp>c                 S   s   g | ]
}|ƒ ‘qS r   r   ©r%   Úwrr   r   r
   r'   4   r(   )r   )r   ÚassertPreciseEqualr   Ú__self__ÚgcÚcollectr   r   )r   Újitargsr   Úc_fÚcfuncÚrefsr&   r   r   r
   Úcheck_local_func_lifetime$   s    
z*TestFuncLifetime.check_local_func_lifetimec                 C   s   | j dd� d S ©NT)Zforceobj©r3   ©r   r   r   r
   Útest_local_func_lifetime6   s    z)TestFuncLifetime.test_local_func_lifetimec                 C   s   | j dd� d S ©NT)Znopythonr5   r6   r   r   r
   Útest_local_func_lifetime_npm9   s    z-TestFuncLifetime.test_local_func_lifetime_npmc                 K   s‚   t f i |¤Žtƒ}|  |dƒd¡ |  |¡}t |¡}dd„ ||jfD ƒ}d  } }}t ¡  |  	dd„ |D ƒd gt
|ƒ ¡ d S )Nr   r    c                 S   s   g | ]}t  |¡‘qS r   r!   r$   r   r   r
   r'   C   r(   z?TestFuncLifetime.check_global_func_lifetime.<locals>.<listcomp>c                 S   s   g | ]
}|ƒ ‘qS r   r   r)   r   r   r
   r'   F   r(   )r   r   r+   r   r"   r#   r,   r-   r.   r   r   )r   r/   r0   r1   r*   r2   r&   r   r   r
   Úcheck_global_func_lifetime<   s    

z+TestFuncLifetime.check_global_func_lifetimec                 C   s   | j dd� d S r4   ©r:   r6   r   r   r
   Útest_global_func_lifetimeH   s    z*TestFuncLifetime.test_global_func_lifetimec                 C   s   | j dd� d S r8   r;   r6   r   r   r
   Útest_global_func_lifetime_npmK   s    z.TestFuncLifetime.test_global_func_lifetime_npmc                 K   sp   t ƒ atf i |¤Žtƒ}|  |ƒ d¡ dd„ |tfD ƒ}d  } }at ¡  |  dd„ |D ƒd gt|ƒ ¡ d S )Né   c                 S   s   g | ]}t  |¡‘qS r   r!   r$   r   r   r
   r'   X   r(   z>TestFuncLifetime.check_global_obj_lifetime.<locals>.<listcomp>c                 S   s   g | ]
}|ƒ ‘qS r   r   r)   r   r   r
   r'   [   r(   )	r   r   r   r   r+   r-   r.   r   r   )r   r/   r0   r2   r&   r   r   r
   Úcheck_global_obj_lifetimeN   s    z*TestFuncLifetime.check_global_obj_lifetimec                 C   s   | j dd� d S r4   )r?   r6   r   r   r
   Útest_global_obj_lifetime]   s    z)TestFuncLifetime.test_global_obj_lifetimec              	      sÂ   dd„ }t di |¤Ž|ƒ‰ ˆ  ¡  ‡ fdd„}t di |¤Ž|ƒ}| ¡  |  |dƒd¡ dd	„ |ˆ |||  ˆ ¡j|  |¡jfD ƒ}d
 } } ‰  }}t ¡  |  dd	„ |D ƒd
gt|ƒ ¡ d
S )zƒ
        When a jitted function calls into another jitted function, check
        that everything is collected as desired.
        c                 S   s   | d S )Né
   r   )Úar   r   r
   Úmult_10e   s    z?TestFuncLifetime.check_inner_function_lifetime.<locals>.mult_10ú
intp(intp)c                    s   ˆ | d ƒS )Né   r   r   ©Z	c_mult_10r   r
   Údo_mathk   s    z?TestFuncLifetime.check_inner_function_lifetime.<locals>.do_mathr   é2   c                 S   s   g | ]}t  |¡‘qS r   r!   r$   r   r   r
   r'   s   r(   zBTestFuncLifetime.check_inner_function_lifetime.<locals>.<listcomp>Nc                 S   s   g | ]
}|ƒ ‘qS r   r   )r%   Úwr   r   r
   r'   z   r(   )rD   )rD   )r   Zdisable_compiler   r   r,   r-   r.   r   )r   r/   rC   rG   Z	c_do_mathZwrsr&   r   rF   r
   Úcheck_inner_function_lifetime`   s     

þÿz.TestFuncLifetime.check_inner_function_lifetimec                 C   s   | j dd� d S r4   ©rJ   r6   r   r   r
   Útest_inner_function_lifetime|   s    z-TestFuncLifetime.test_inner_function_lifetimec                 C   s   | j dd� d S r8   rK   r6   r   r   r
   Ú test_inner_function_lifetime_npm   s    z1TestFuncLifetime.test_inner_function_lifetime_npmN)r   r   r   Ú__doc__r   r3   r7   r9   r:   r<   r=   r?   r@   rJ   rL   rM   r   r   r   r
   r      s   r   c                   @   s   e Zd Zdd„ ZdS )ÚTestLifeTimeIssuec           	         s„   ddl m} dd l‰ |dd„ ƒ}|‡ fdd„ƒ}ˆ  ddggg¡}ˆ  dd	gg¡}|ƒ }||d |ƒ |ƒ }||d |ƒ |ƒ }d S )
Nr   )Únjitc                 S   s   |j d }|dkr|d }dS )Nr   )Úshape)ZpointÚpolygonsZnum_polygonsZintentionally_unused_variabler   r   r
   Úis_point_in_polygonsŠ   s    
z@TestLifeTimeIssue.test_double_free.<locals>.is_point_in_polygonsc                      s   ˆ j dˆ jd�S )NrA   )Zdtype)ÚemptyÚint64r   ©Únpr   r
   Údummy•   s    z1TestLifeTimeIssue.test_double_free.<locals>.dummyr   g      ø¿g      à?)ÚnumbarP   ÚnumpyÚarray)	r   rP   rS   rX   rR   ZpointsrB   ÚbÚcr   rV   r
   Útest_double_free„   s    

z"TestLifeTimeIssue.test_double_freeN)r   r   r   r^   r   r   r   r
   rO   ƒ   s   rO   Ú__main__)r-   r"   rY   r   Z
numba.corer   Znumba.tests.supportr   ZunittestÚobjectr   r   r   r   rO   r   Úmainr   r   r   r
   Ú<module>   s   l 