o
    i9                     @   s   d dl 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mZmZ e	 Zde_dd Zdd	 Zd
d Zdd Zdd Zdd Zdd ZG dd deZG dd deeZG dd deeZdS )    N)jittyped)Flags)TestCaseCompilationCacheMemoryLeakMixinTc                 C   
   t | S N)hqheapify)x r   e/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_heapq.pyr         
r   c                 C   r   r	   )r
   heappop)heapr   r   r   r      r   r   c                 C      t | |S r	   )r
   heappushr   itemr   r   r   r         r   c                 C   r   r	   )r
   heappushpopr   r   r   r   r      r   r   c                 C   r   r	   )r
   heapreplacer   r   r   r   r      r   r   c                 C   r   r	   )r
   	nsmallestniterabler   r   r   r   "   r   r   c                 C   r   r	   )r
   nlargestr   r   r   r   r   &   r   r   c                       s   e Zd Z f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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/d0 Zd1d2 Zd3d4 Z  ZS )5
_TestHeapqc                    s(   t t|   t | _tjd| _d S )N*   )	superr   setUpr   ZccachenprandomZRandomStaternd)self	__class__r   r   r!   ,   s   z_TestHeapq.setUpc                 C   s  t }tdd|}g d}| |}|| || | |t| dddtjtj tjg}t	|dD ]}t|}| |}|| || | |t| q4t
t|D ]}|| g}| |}|| || | |t| qVg d}| |}|| || | |t| d S )	NTZnopython
            	               r   A`"	@g      $g      @r1   )r+   !   )r*      )r/      )r   r   listimplassertPreciseEquallistr"   naninf	itertoolscombinations_with_replacementrangelen)r%   pyfunccfuncabZelement_poolr   ir   r   r   test_heapify_basic_sanity1   s2   




z$_TestHeapq.test_heapify_basic_sanityc                 C   s8   t |D ]\}}|r|d d? }| || |k qd S )Nr*   )	enumerate
assertTrue)r%   r   posr   	parentposr   r   r   check_invariantX   s   z_TestHeapq.check_invariantc                 C   s   t }tdd|}t}tdd|}| dg}| dg}| | tdD ]}| jdd}|	| ||| | | q'g }	|rV||}| | |		| |sF|d d  }
|

  | t|
|	 | |	 d S )NTr(            r*   r   )r   r   r   r8   rK   r?   r$   Zrandnr   appendsortr9   r:   )r%   Zpyfunc_heappushcfunc_heappushZpyfunc_heappopcfunc_heappopr   datarE   r   resultsZdata_sortedr   r   r   test_push_pop^   s,   




z_TestHeapq.test_push_popc                 C   sT   t }tdd|}ttdddg D ]}| | j|}|| | | qd S )NTr(   r*      i N  )r   r   r:   r?   r8   r$   Zrandom_samplerK   )r%   rA   rB   sizer   r   r   r   test_heapifyy   s   z_TestHeapq.test_heapifyc                 C   s   t }tdd|}|   |  }|d W d    n1 s w   Y  d}| |t|j |  }|| ddg W d    n1 sHw   Y  d}| |t|j d S )NTr(   r*   r,   r0   heap argument must be a listy      ?      ?y       @      z>'<' not supported between instances of 'complex' and 'complex')r   r   disable_leak_checkassertTypingErrorassertInstr	exceptionr8   r%   rA   rB   emsgr   r   r   test_heapify_exceptions   s   


z"_TestHeapq.test_heapify_exceptionsc           	      C   sz   t }tdd|}dd }| D ]*}t| | |}tt|D ]}||}||}| |t| | || q!qd S )NTr(   c                   s   sD    g dV  g dV  t jdt jd V  t ddd V  d S )Nr)   )r4   )r*   o   )r/   i  r,   )Z
fill_valued   )r"   fullr;   tolistlinspacer   r   r   r   a_variations   s
   

z:_TestHeapq.test_heappop_basic_sanity.<locals>.a_variations)r   r   r   r8   r?   r@   r9   r:   )	r%   rA   rB   rj   rC   rD   rE   Zval_pyZval_cr   r   r   test_heappop_basic_sanity   s   

z$_TestHeapq.test_heappop_basic_sanityc                 C   sd   t }tdd|}|   |  }|d W d    n1 s w   Y  d}| |t|j d S )NTr(   rX   rY   )r   r   rZ   r[   r\   r]   r^   r_   r   r   r   test_heappop_exceptions   s   

z"_TestHeapq.test_heappop_exceptionsc                 c   s^    |  g dV  tddd}|  |V  |  |d d d V  | j| |  |V  d S )Nr)   rd   r/      )r8   r"   ri   r$   shuffle)r%   rC   r   r   r   	iterables   s   z_TestHeapq.iterablesc                    s   t }tdd|}t}tdd| |  D ]-}t|}| |dg|D ]}|| q' fddttD }| 	|| qd S )NTr(   r   c                       g | ]} qS r   r   .0_Z	cfunc_popr   r   r   
<listcomp>       z2_TestHeapq.test_heappush_basic.<locals>.<listcomp>)
r   r   r   rp   sortedr8   popr?   r@   r9   )r%   Zpyfunc_pushZ
cfunc_pushZ
pyfunc_popr   expectedvaluegotr   ru   r   test_heappush_basic   s   z_TestHeapq.test_heappush_basicc                 C      t }tdd|}|   |  }|dd W d    n1 s!w   Y  d}| |t|j |  }|| g dd W d    n1 sJw   Y  d}| |t|j d S )NTr(   rX   r1   rY   g      @'heap type must be the same as item type)r   r   rZ   r[   r\   r]   r^   r8   r_   r   r   r   test_heappush_exceptions      

z#_TestHeapq.test_heappush_exceptionsc                 C   s   t }tdd|}|  D ]}tdt|d D ]}|d|}|d|}| || qq|d| g d}| |g  |d| g d}| |dg |dd	}| |ddg |dtd
}| |g d d S )NTr(   re   r+   r*   Fr+   r/   r*   r/   r1   r,   r0   r+   r/   r*   r1   )r   r*   r/   )	r   r   rp   r?   r@   r9   r8   r"   aranger%   rA   rB   r   r   rz   r|   outr   r   r   test_nsmallest_basic       


z_TestHeapq.test_nsmallest_basicc                 C   s   t }tdd|}|  D ]}tdt|d D ]}|d|}|d|}| || qq|d| g d}| |g  |d| g d}| |dg |dd	}| |d
dg |dtd
}| |g d d S )NTr(   re   r+   r*   Fr   r/   r   r1   r,   )r,   r0   r+   )	r   r   rp   r?   r@   r9   r8   r"   r   r   r   r   r   test_nlargest_basic   r   z_TestHeapq.test_nlargest_basicc                 C   s   |    |  }|d| g d W d    n1 sw   Y  d}| |t|j |  }|dd W d    n1 sAw   Y  d}| |t|j d S )Ng@r   z%First argument 'n' must be an integerr/   rf   z+Second argument 'iterable' must be iterable)rZ   r[   r8   r\   r]   r^   )r%   rB   r`   ra   r   r   r   _assert_typing_error  s   

z_TestHeapq._assert_typing_errorc                 C       t }tdd|}| | d S NTr(   )r   r   r   r%   rA   rB   r   r   r   test_nsmallest_exceptions&     z$_TestHeapq.test_nsmallest_exceptionsc                 C   r   r   )r   r   r   r   r   r   r   test_nlargest_exceptions+  r   z#_TestHeapq.test_nlargest_exceptionsc                 C   s   t }tdd|}g d}t| | |}dD ]}||| ||| | |t| qtddd}tj|d< tj	|d	< |
 }t| | |}d
dtj	 tj	fD ]}||| ||| | |t| qTd S )NTr(   r)   )r0            r0   rn   g      r3   )r   r   r   r8   r9   r:   r"   ri   r;   r<   rh   )r%   rA   rB   rC   rD   r   r   r   r   test_heapreplace_basic0  s(   







z!_TestHeapq.test_heapreplace_basicc                 C   r~   )NTr(   rX   rn   rY   rL   r   )r   r   rZ   r[   r\   r]   r^   r8   r_   r   r   r   test_heapreplace_exceptionsK  r   z&_TestHeapq.test_heapreplace_exceptionsc                 c   s&    z	 t |V  q ty   Y d S w r	   )r   
IndexError)r%   r   r   r   r   heapiter^  s   
z_TestHeapq.heapiterc                 C   s   t ddt}t ddt}| jtdd }| |d d }|| |dd  D ]}||d kr9||| q,| t	| 
t	|t|dd   d S )NTr(       
   r   rd   )r   r   r   r$   choicer?   rh   r8   r9   r:   r   rx   )r%   cfunc_heapifyZcfunc_heapreplacerR   r   r   r   r   r   
test_nbeste  s   
z_TestHeapq.test_nbestc                    s   t ddt}t ddt}t ddt tdD ]M}tjdtjd}| | j	
|d}|d@ r<|d d  | n| |d g|dd  D ]}|| qJ fd	d
tdD }| |t| qd S )NTr(   rf   r,   Zdtyper   r*   r   c                    rq   r   r   rr   rQ   r   r   r   rv     rw   z,_TestHeapq.test_heapsort.<locals>.<listcomp>)r   r   r   r   r?   r"   r   float64r8   r$   r   r9   rx   )r%   r   rP   ZtrialvaluesrR   r   Zheap_sortedr   r   r   test_heapsortv  s   
z_TestHeapq.test_heapsortc                 C   sZ   t }tdd|}| | jtdd}dD ]}| t|||t|d |  qd S )NTr(   r   r   	r   r*   r/   r   rf   i  i  r   iL  )	r   r   r8   r$   r   r?   r9   r:   rx   r%   rA   rB   rR   r   r   r   r   test_nsmallest  s   $z_TestHeapq.test_nsmallestc                 C   s^   t }tdd|}| | jtdd}dD ]}| t|||t|ddd |  qd S )NTr(   r   r   r   )reverse)	r   r   r8   r$   r   r?   r9   r:   rx   r   r   r   r   test_nlargest  s   z_TestHeapq.test_nlargestc           	      C   s   t }tdd|}t}tdd|}tjdtjd}| | j|d}|d d }|| |dd  D ]}||| q4| 	t
| t
|t|dd   d S )NTr(   r   r   r   r   rd   )r   r   r   r"   r   r   r8   r$   r   r9   r:   r   rx   )	r%   Zpyfunc_heappushpopZcfunc_heappushpopZpyfunc_heapifyr   r   rR   r   r   r   r   r   test_nbest_with_pushpop  s   z"_TestHeapq.test_nbest_with_pushpopc                 C   s   t }tdd|}| dg}||d}| t||fdgdf | t|d t | t|t | dg}||d}| t||fdgdf | dg}||d}| t||fdgdf d S )	NTr(   g      ?g      $@r   r   r.   r6   )r   r   r8   r9   r:   typefloat)r%   rA   rB   hr   r   r   r   test_heappushpop  s   


z_TestHeapq.test_heappushpopc                 C   r~   )NTr(   rX   rn   rY   Fr   )r   r   rZ   r[   r\   r]   r^   r8   r_   r   r   r   test_heappushpop_exceptions  r   z&_TestHeapq.test_heappushpop_exceptions)__name__
__module____qualname__r!   rF   rK   rT   rW   rb   rk   rl   rp   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r&   r   r   *   s6    'r   c                   @   s   e Zd ZdZeZdS )TestHeapqReflectedListzTest heapq with reflected listsN)r   r   r   __doc__r:   r8   r   r   r   r   r     s    r   c                   @   s   e Zd ZdZejZdS )TestHeapqTypedListzTest heapq with typed listsN)r   r   r   r   r   Listr8   r   r   r   r   r     s    
r   )heapqr
   r=   numpyr"   Znumbar   r   Znumba.core.compilerr   Znumba.tests.supportr   r   r   Zno_pyobj_flagsZnrtr   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s*       9