
    J/Ph,                         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e	          Z
d Zd Z G d	 d
e          Z G d de          Zedk    r ej                     dS dS )    N)jit)types)TestCasec                       e Zd Zd ZdS )Dummyc                     |dz   S )N    )selfothers     ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_func_lifetime.py__add__zDummy.__add__   s    qy    N)__name__
__module____qualname__r   r
   r   r   r   r   
   s#            r   r   c                     | dz   S N   r
   xs    r   global_usecase1r      s    q5Lr   c                      t           dz   S r   )
global_objr
   r   r   global_usecase2r      s    >r   c                   Z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )TestFuncLifetimezP
    Test the lifetime of compiled function objects and their dependencies.
    c                     |                      t          |j                  d           t          |j                                                  d         }|j        S )zV
        Get the single implementation (a C function object) of a dispatcher.
        r   r   )assertEquallen	overloadslistvaluesentry_point)r   
dispatchercress      r   get_implzTestFuncLifetime.get_impl   sO     	Z122A666J(//112215r   c                 ^   d } t          di ||          }|                      |d          d           |                     |          }d |||j        fD             }d x}x}x}}t	          j                     |                     d |D             d gt          |          z             d S )Nc                     | dz   S r   r
   r   s    r   fz5TestFuncLifetime.check_local_func_lifetime.<locals>.f%   s    q5Lr   int32(int32)r      c                 6    g | ]}t          j        |          S r
   weakrefref.0objs     r   
<listcomp>z>TestFuncLifetime.check_local_func_lifetime.<locals>.<listcomp>1   s"    EEESC  EEEr   c                 "    g | ]} |            S r
   r
   r2   wrs     r   r4   z>TestFuncLifetime.check_local_func_lifetime.<locals>.<listcomp>4       ...2""$$...r   )r+   )r   assertPreciseEqualr'   __self__gccollectr   r    )r   jitargsr*   c_fcfuncrefsr3   s          r   check_local_func_lifetimez*TestFuncLifetime.check_local_func_lifetime$   s    	 	 	 -c,,G,,Q//A***c"" FEQU^,DEEE $$$a$#

.....T0BCCCCCr   c                 2    |                      d           d S NT)forceobjrA   r   s    r   test_local_func_lifetimez)TestFuncLifetime.test_local_func_lifetime6       &&&55555r   c                 2    |                      d           d S NT)nopythonrE   rF   s    r   test_local_func_lifetime_npmz-TestFuncLifetime.test_local_func_lifetime_npm9   rH   r   c                     t          di |t                    }|                      |d          d           |                     |          }t	          j        |          }d ||j        fD             }d x}x}}t          j                     | 	                    d |D             d gt          |          z             d S )Nr   r,   c                 6    g | ]}t          j        |          S r
   r.   r1   s     r   r4   z?TestFuncLifetime.check_global_func_lifetime.<locals>.<listcomp>C   s"    BBBSC  BBBr   c                 "    g | ]} |            S r
   r
   r6   s     r   r4   z?TestFuncLifetime.check_global_func_lifetime.<locals>.<listcomp>F   r8   r   r
   )r   r   r9   r'   r/   r0   r:   r;   r<   r   r    )r   r=   r>   r?   r7   r@   r3   s          r   check_global_func_lifetimez+TestFuncLifetime.check_global_func_lifetime<   s    cnnGnn_--A***c""[BBS%.,ABBB   cE

.....T0BCCCCCr   c                 2    |                      d           d S rC   rP   rF   s    r   test_global_func_lifetimez*TestFuncLifetime.test_global_func_lifetimeH       '''66666r   c                 2    |                      d           d S rJ   rR   rF   s    r   test_global_func_lifetime_npmz.TestFuncLifetime.test_global_func_lifetime_npmK   rT   r   c                 L   t                      a t          di |t                    }|                      |            d           d |t          fD             }d x}x}at          j                     |                     d |D             d gt          |          z             d S )N   c                 6    g | ]}t          j        |          S r
   r.   r1   s     r   r4   z>TestFuncLifetime.check_global_obj_lifetime.<locals>.<listcomp>X   s"    >>>SC  >>>r   c                 "    g | ]} |            S r
   r
   r6   s     r   r4   z>TestFuncLifetime.check_global_obj_lifetime.<locals>.<listcomp>[   r8   r   r
   )	r   r   r   r   r9   r;   r<   r   r    )r   r=   r>   r@   r3   s        r   check_global_obj_lifetimez*TestFuncLifetime.check_global_obj_lifetimeN   s    
 WW
cnnGnn_--q)))>>S*,=>>>!%%%cJ

.....T0BCCCCCr   c                 2    |                      d           d S rC   )r[   rF   s    r   test_global_obj_lifetimez)TestFuncLifetime.test_global_obj_lifetime]   rH   r   c           	         d } t          d	i ||                                           fd} t          d	i ||          }|                                 |                      |d          d           d ||||                               j        |                     |          j        fD             }dx}x}xx}}t          j                     |                     d |D             dgt          |          z             dS )
z
        When a jitted function calls into another jitted function, check
        that everything is collected as desired.
        c                     | dz  S )N
   r
   )as    r   mult_10z?TestFuncLifetime.check_inner_function_lifetime.<locals>.mult_10e   s    r6Mr   
intp(intp)c                       | dz             S )N   r
   )r   	c_mult_10s    r   do_mathz?TestFuncLifetime.check_inner_function_lifetime.<locals>.do_mathk   s    9QU###r   r   2   c                 6    g | ]}t          j        |          S r
   r.   r1   s     r   r4   zBTestFuncLifetime.check_inner_function_lifetime.<locals>.<listcomp>s   s.       Cw{3   r   Nc                 "    g | ]} |            S r
   r
   )r2   ws     r   r4   zBTestFuncLifetime.check_inner_function_lifetime.<locals>.<listcomp>z   s    +++!!!##+++r   )rc   )r   disable_compiler   r'   r:   r;   r<   r    )r   r=   rb   rg   	c_do_mathwrsr3   rf   s          @r   check_inner_function_lifetimez.TestFuncLifetime.check_inner_function_lifetime`   sV   
	 	 	 1C000099	!!###	$ 	$ 	$ 	$ 	$ 1C000099	!!###1r*** GYi((1i((1  
 ;?>>g>	>Gi

++s+++dVc#hh->?????r   c                 2    |                      d           d S rC   ro   rF   s    r   test_inner_function_lifetimez-TestFuncLifetime.test_inner_function_lifetime|       **D*99999r   c                 2    |                      d           d S rJ   rq   rF   s    r    test_inner_function_lifetime_npmz1TestFuncLifetime.test_inner_function_lifetime_npm   rs   r   N)r   r   r   __doc__r'   rA   rG   rL   rP   rS   rV   r[   r]   ro   rr   ru   r
   r   r   r   r      s              D D D$6 6 66 6 6
D 
D 
D7 7 77 7 7D D D6 6 6@ @ @8: : :: : : : :r   r   c                       e Zd Zd ZdS )TestLifeTimeIssuec                 2  	 ddl m} dd l	|d             }|	fd            }	                    ddggg          }	                    ddgg          } |            } ||d         |            |            } ||d         |            |            }d S )Nr   )njitc                 <    |j         d         }|dk    r|d         }dS )Nr   )shape)pointpolygonsnum_polygonsintentionally_unused_variables       r   is_point_in_polygonsz@TestLifeTimeIssue.test_double_free.<locals>.is_point_in_polygons   s(    #>!,Lq  08-1r   c                  <                          d j                  S )Nr`   )dtype)emptyint64)nps   r   dummyz1TestLifeTimeIssue.test_double_free.<locals>.dummy   s    88Bbh8///r   r   g      g      ?)numbarz   numpyarray)
r   rz   r   r   r~   pointsra   bcr   s
            @r   test_double_freez"TestLifeTimeIssue.test_double_free   s     
	 	 
	 
	0 	0 	0 	0 
	0 88q!fXJ''D#;-((EGGVAY111EGGVAY111EGGr   N)r   r   r   r   r
   r   r   rx   rx      s#            r   rx   __main__)r;   r/   r   r   
numba.corer   numba.tests.supportr   unittestobjectr   r   r   r   rx   r   mainr
   r   r   <module>r      s"   				              ( ( ( ( ( (     F       i: i: i: i: i:x i: i: i:X       @ zHMOOOOO r   