U
    b»{jt  ã                   @   s  d dl Zd dlZd dlmZm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_eƒ Zde_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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$G d'd(„ d(eeƒZ%e&d)k�re '¡  dS )*é    N)Úcompile_isolatedÚFlags)ÚerrorsÚtypes)Útypeof)ÚTestCaseÚMemoryLeakMixinÚtagTc                 C   s   | \}}}|||fS ©N© )ÚlÚaÚbÚcr   r   ú_/var/www/html/bwave/python/venv/lib/python3.8/site-packages/numba/tests/test_unpack_sequence.pyÚunpack_list   s    
r   c                 C   s   | j \}}}|| | S r
   ©Úshape)r   ÚxÚyÚzr   r   r   Úunpack_shape   s    r   c                  C   s   t dƒ\} }}| | | S )Né   ©Úrange©r   r   r   r   r   r   Úunpack_range   s    r   c                  C   s   t dƒ\} }}| | | S )Né   r   r   r   r   r   Úunpack_range_too_small"   s    r   c                  C   s   t dƒ\} }}| | | S )Né   r   r   r   r   r   Úunpack_range_too_large'   s    r    c                  C   s   d\} }}| | | S )N©é   r   r   r   r   r   r   r   Úunpack_tuple,   s    
r#   c                  C   s   d\} }}| | | S )N)r"   r   r   r   r   r   r   Úunpack_tuple_too_small1   s    
r$   c                  C   s   d\} }}| | | S )N)r"   r   r   r   r   r   r   r   r   Úunpack_tuple_too_large6   s    
r%   c                  C   s   d\} }}| | | S )N)r"   y              @r   r   r   r   r   Ú$unpack_heterogeneous_tuple_too_small;   s    
r&   c                  C   s   d\} }}| | | S )N)r"   ç      @ù              @r   r   r   r   r   r   Ú$unpack_heterogeneous_tuple_too_large@   s    
r)   c                  C   s   d\} }}| | | S )N)r"   r'   r(   r   r   r   r   r   Úunpack_heterogeneous_tupleE   s    
r*   c                  C   s   d\} \}}| | | S )N)r"   )r'   r(   r   r   r   r   r   Ú!unpack_nested_heterogeneous_tupleJ   s    r+   c                 C   s   | \}}||fS r
   r   )Úseqr   r   r   r   r   Úunpack_arbitraryO   s    r-   c                  C   s,   t  d¡} t  d¡}|| f}|\}}||fS )Nr"   r   ©ÚnpÚzeros)r   r   ÚtupÚalphaÚbetar   r   r   Ú
unpack_nrtT   s
    

r4   c                 C   s(   | |f }\}}|\}}|| | | S r
   r   )r   r   r   r   r   ÚdÚer   r   r   Úchained_unpack_assign1\   s    r7   c                 C   s   | dkr||  } }| |fS )Nr   r   )r   r   r   r   r   Úconditional_swapc   s    
r8   c                   @   s  e Zd Zdd„ Zefdd„Zdd„ Zefdd„Zd	d
„ Zefdd„Z	dd„ Z
efdd„Zdd„ Zefdd„Zdd„ Zefdd„Zdd„ Zee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efd-d.„Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9S ):Ú
TestUnpackc                 C   s:   t }t|dtd�}|j}dddg}|  ||ƒ||ƒ¡ d S )Nr   ©Úflagsr"   r   r   )r   r   Úforce_pyobj_flagsÚentry_pointZassertEqual)ÚselfÚpyfuncÚcrÚcfuncr   r   r   r   Útest_unpack_listl   s
    
zTestUnpack.test_unpack_listc                 C   sT   t }t|tjtjddd�g|d�}|j}tjdd� tj¡}|  	||ƒ||ƒ¡ d S )Nr   ÚC)ZdtypeÚndimZlayoutr:   r!   r   )
r   r   r   ZArrayÚint32r=   r/   r0   ZastypeÚassertPreciseEqual)r>   r;   r?   r@   rA   r   r   r   r   Útest_unpack_shapes   s    þýzTestUnpack.test_unpack_shapec                 C   s   | j td� d S ©Nr:   )rG   Úno_pyobj_flags©r>   r   r   r   Útest_unpack_shape_npm}   s    z TestUnpack.test_unpack_shape_npmc                 C   s   |   t|¡ d S r
   )Úrun_nullary_funcr   ©r>   r;   r   r   r   Útest_unpack_range€   s    zTestUnpack.test_unpack_rangec                 C   s   | j td� d S rH   )rN   rI   rJ   r   r   r   Útest_unpack_range_npmƒ   s    z TestUnpack.test_unpack_range_npmc                 C   s   |   t|¡ d S r
   )rL   r#   rM   r   r   r   Útest_unpack_tuple†   s    zTestUnpack.test_unpack_tuplec                 C   s   | j td� d S rH   )rP   rI   rJ   r   r   r   Útest_unpack_tuple_npm‰   s    z TestUnpack.test_unpack_tuple_npmc                 C   s   |   t|¡ d S r
   )rL   r*   rM   r   r   r   Útest_unpack_heterogeneous_tupleŒ   s    z*TestUnpack.test_unpack_heterogeneous_tuplec                 C   s   | j td� d S rH   )rR   rI   rJ   r   r   r   Ú#test_unpack_heterogeneous_tuple_npm�   s    z.TestUnpack.test_unpack_heterogeneous_tuple_npmc                 C   s   |   t|¡ d S r
   )rL   r+   rM   r   r   r   Ú&test_unpack_nested_heterogeneous_tuple’   s    z1TestUnpack.test_unpack_nested_heterogeneous_tuplec                 C   s   | j td� d S rH   )rT   rI   rJ   r   r   r   Ú*test_unpack_nested_heterogeneous_tuple_npm•   s    z5TestUnpack.test_unpack_nested_heterogeneous_tuple_npmc                 C   s<   t }t|tjtjg|d�}|j}d}|  ||Ž ||Ž ¡ d S )Nr:   )r   é   )r7   r   r   rE   r=   rF   )r>   r;   r?   r@   rA   Úargsr   r   r   Útest_chained_unpack_assign˜   s    ÿz%TestUnpack.test_chained_unpack_assignc                 C   s   | j td� d S rH   )rX   rI   rJ   r   r   r   Útest_chained_unpack_assign_npm    s    z)TestUnpack.test_chained_unpack_assign_npmc              	   C   s4   |   |¡�  t|d|d�}|j}|ƒ  W 5 Q R X d S ©Nr   r:   )ÚassertRaisesr   r=   )r>   r?   r;   Úexcr@   rA   r   r   r   Úcheck_unpack_error£   s    zTestUnpack.check_unpack_errorc                 C   s   |   t¡ |   t¡ d S r
   )r]   r$   r&   rJ   r   r   r   Útest_unpack_tuple_too_small©   s    
z&TestUnpack.test_unpack_tuple_too_smallc                 C   s$   |   tttj¡ |   tttj¡ d S r
   )r]   r$   rI   r   ÚTypingErrorr&   rJ   r   r   r   Útest_unpack_tuple_too_small_npm­   s    ÿ ÿz*TestUnpack.test_unpack_tuple_too_small_npmc                 C   s   |   t¡ |   t¡ d S r
   )r]   r%   r)   rJ   r   r   r   Útest_unpack_tuple_too_large³   s    
z&TestUnpack.test_unpack_tuple_too_largec                 C   s$   |   tttj¡ |   tttj¡ d S r
   )r]   r%   rI   r   r_   r)   rJ   r   r   r   Útest_unpack_tuple_too_large_npm·   s    ÿ ÿz*TestUnpack.test_unpack_tuple_too_large_npmc                 C   s   |   t¡ d S r
   )r]   r   rJ   r   r   r   Útest_unpack_range_too_small½   s    z&TestUnpack.test_unpack_range_too_smallc                 C   s   |   tt¡ d S r
   )r]   r   rI   rJ   r   r   r   Útest_unpack_range_too_small_npmÀ   s    z*TestUnpack.test_unpack_range_too_small_npmc                 C   s   |   t¡ d S r
   )r]   r    rJ   r   r   r   Útest_unpack_range_too_largeÃ   s    z&TestUnpack.test_unpack_range_too_largec                 C   s   |   tt¡ d S r
   )r]   r    rI   rJ   r   r   r   Útest_unpack_range_too_large_npmÆ   s    z*TestUnpack.test_unpack_range_too_large_npmc                 C   sD   t ttjtjf|d�}|j}|  |ddƒd¡ |  |ddƒd¡ d S )Nr:   r   rV   )rV   r   r   )r   rV   )r   r8   r   rE   r=   rF   )r>   r;   r@   rA   r   r   r   Úcheck_conditional_swapÉ   s    ÿz!TestUnpack.check_conditional_swapc                 C   s   |   ¡  d S r
   )rg   rJ   r   r   r   Útest_conditional_swapÐ   s    z TestUnpack.test_conditional_swapc                 C   s   |   t¡ d S r
   )rg   rI   rJ   r   r   r   Útest_conditional_swap_npmÓ   s    z$TestUnpack.test_conditional_swap_npmc                 C   sP   t dd„ tdƒD ƒƒ}t|ƒ}t}t||ftd�}|j}|  ||ƒ||ƒ¡ d S )Nc                 s   s   | ]}t  |d  ¡V  qdS )r"   Nr.   )Ú.0Úir   r   r   Ú	<genexpr>×   s     z9TestUnpack.test_unpack_tuple_of_arrays.<locals>.<genexpr>r   r:   )Útupler   r   r-   r   rI   r=   rF   )r>   r1   Ztuptyr?   r@   rA   r   r   r   Útest_unpack_tuple_of_arraysÖ   s    ÿz&TestUnpack.test_unpack_tuple_of_arraysc                 C   s,   t }t|dtd�}|j}|  |ƒ |ƒ ¡ d S rZ   )r4   r   rI   r=   rF   )r>   r?   r@   rA   r   r   r   Útest_unpack_nrtß   s    zTestUnpack.test_unpack_nrtc              	   C   sD   t }|  tj¡�}t|tjftd� W 5 Q R X |  dt	|j
ƒ¡ d S )Nr:   zfailed to unpack int32)r-   r[   r   r_   r   r   rE   rI   ZassertInÚstrÚ	exception)r>   r?   Zraisesr   r   r   Útest_invalid_unpackå   s    zTestUnpack.test_invalid_unpackN)!Ú__name__Ú
__module__Ú__qualname__rB   r<   rG   rK   rN   rO   rP   rQ   rR   rS   rT   rU   rX   rY   Ú
ValueErrorr]   r^   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rn   ro   rr   r   r   r   r   r9   j   s8   
	r9   Ú__main__)(Únumpyr/   ZunittestZnumba.core.compilerr   r   Z
numba.corer   r   Znumbar   Znumba.tests.supportr   r   r	   Zenable_pyobj_flagsZenable_pyobjectr<   Zforce_pyobjectrI   Znrtr   r   r   r   r    r#   r$   r%   r&   r)   r*   r+   r-   r4   r7   r8   r9   rs   Úmainr   r   r   r   Ú<module>   s>    
