o
    8ήct                     @   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re'  dS dS )*    N)compile_isolatedFlags)errorstypes)typeof)TestCaseMemoryLeakMixintagTc                 C   s   | \}}}|||fS N )labcr   r   G/tmp/pip-target-vg8gfxp4/lib/python/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      r   c                  C      t d\} }}| | | S )N   ranger   r   r   r   r   r   unpack_range      r   c                  C   r   )N   r   r   r   r   r   unpack_range_too_small"   r   r!   c                  C   r   )N   r   r   r   r   r   unpack_range_too_large'   r   r#   c                  C      d\} }}| | | S )N   r    r   r   r   r   r   r   unpack_tuple,      
r'   c                  C   r$   )N)r&   r    r   r   r   r   r   unpack_tuple_too_small1   r(   r)   c                  C   r$   )N)r&   r    r   r"   r   r   r   r   r   unpack_tuple_too_large6   r(   r*   c                  C   r$   )N)r&   y              @r   r   r   r   r   $unpack_heterogeneous_tuple_too_small;   r(   r+   c                  C   r$   )N)r&         @              @r"   r   r   r   r   r   $unpack_heterogeneous_tuple_too_large@   r(   r.   c                  C   r$   )N)r&   r,   r-   r   r   r   r   r   unpack_heterogeneous_tupleE   r(   r/   c                  C   s   d\} \}}| | | S )N)r&   )r,   r-   r   r   r   r   r   !unpack_nested_heterogeneous_tupleJ   r   r0   c                 C   s   | \}}||fS r
   r   )seqr   r   r   r   r   unpack_arbitraryO   s   r2   c                  C   s,   t d} t d}|| f}|\}}||fS )Nr&   r    npzeros)r   r   tupalphabetar   r   r   
unpack_nrtT   s
   

r9   c                 C   s(   | |f }\}}|\}}|| | | S r
   r   )r   r   r   r   r   der   r   r   chained_unpack_assign1\   s   r<   c                 C   s   | dkr	|| } }| |fS )Nr   r   )r   r   r   r   r   conditional_swapc   s   
r=   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   s8   t }t|dtd}|j}g d}| |||| d S )Nr   flagsr%   )r   r   force_pyobj_flagsentry_point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)dtypendimlayoutr?   r%   r   )
r   r   r   Arrayint32rB   r4   r5   astypeassertPreciseEqual)rD   r@   rE   rF   rG   r   r   r   r   test_unpack_shapes   s   zTestUnpack.test_unpack_shapec                 C      | j td d S Nr?   )rQ   no_pyobj_flagsrD   r   r   r   test_unpack_shape_npm}      z TestUnpack.test_unpack_shape_npmc                 C      |  t| d S r
   )run_nullary_funcr   rD   r@   r   r   r   test_unpack_range   rW   zTestUnpack.test_unpack_rangec                 C   rR   rS   )r[   rT   rU   r   r   r   test_unpack_range_npm   rW   z TestUnpack.test_unpack_range_npmc                 C   rX   r
   )rY   r'   rZ   r   r   r   test_unpack_tuple   rW   zTestUnpack.test_unpack_tuplec                 C   rR   rS   )r]   rT   rU   r   r   r   test_unpack_tuple_npm   rW   z TestUnpack.test_unpack_tuple_npmc                 C   rX   r
   )rY   r/   rZ   r   r   r   test_unpack_heterogeneous_tuple   rW   z*TestUnpack.test_unpack_heterogeneous_tuplec                 C   rR   rS   )r_   rT   rU   r   r   r   #test_unpack_heterogeneous_tuple_npm   rW   z.TestUnpack.test_unpack_heterogeneous_tuple_npmc                 C   rX   r
   )rY   r0   rZ   r   r   r   &test_unpack_nested_heterogeneous_tuple   rW   z1TestUnpack.test_unpack_nested_heterogeneous_tuplec                 C   rR   rS   )ra   rT   rU   r   r   r   *test_unpack_nested_heterogeneous_tuple_npm   rW   z5TestUnpack.test_unpack_nested_heterogeneous_tuple_npmc                 C   s<   t }t|tjtjg|d}|j}d}| || ||  d S )Nr?   )r"      )r<   r   r   rN   rB   rP   )rD   r@   rE   rF   rG   argsr   r   r   test_chained_unpack_assign   s   z%TestUnpack.test_chained_unpack_assignc                 C   rR   rS   )re   rT   rU   r   r   r   test_chained_unpack_assign_npm   rW   z)TestUnpack.test_chained_unpack_assign_npmc                 C   sJ   |  | t|d|d}|j}|  W d    d S 1 sw   Y  d S Nr   r?   )assertRaisesr   rB   )rD   rE   r@   excrF   rG   r   r   r   check_unpack_error   s
   "zTestUnpack.check_unpack_errorc                 C      |  t |  t d S r
   )rj   r)   r+   rU   r   r   r   test_unpack_tuple_too_small      
z&TestUnpack.test_unpack_tuple_too_smallc                 C   $   |  tttj |  tttj d S r
   )rj   r)   rT   r   TypingErrorr+   rU   r   r   r   test_unpack_tuple_too_small_npm      z*TestUnpack.test_unpack_tuple_too_small_npmc                 C   rk   r
   )rj   r*   r.   rU   r   r   r   test_unpack_tuple_too_large   rm   z&TestUnpack.test_unpack_tuple_too_largec                 C   rn   r
   )rj   r*   rT   r   ro   r.   rU   r   r   r   test_unpack_tuple_too_large_npm   rq   z*TestUnpack.test_unpack_tuple_too_large_npmc                 C      |  t d S r
   )rj   r!   rU   r   r   r   test_unpack_range_too_small      z&TestUnpack.test_unpack_range_too_smallc                 C      |  tt d S r
   )rj   r!   rT   rU   r   r   r   test_unpack_range_too_small_npm   rW   z*TestUnpack.test_unpack_range_too_small_npmc                 C   rt   r
   )rj   r#   rU   r   r   r   test_unpack_range_too_large   rv   z&TestUnpack.test_unpack_range_too_largec                 C   rw   r
   )rj   r#   rT   rU   r   r   r   test_unpack_range_too_large_npm   rW   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"   rc   )rc   r"   r   )r   rc   )r   r=   r   rN   rB   rP   )rD   r@   rF   rG   r   r   r   check_conditional_swap   s   z!TestUnpack.check_conditional_swapc                 C   s   |    d S r
   )r{   rU   r   r   r   test_conditional_swap   s   z TestUnpack.test_conditional_swapc                 C   rt   r
   )r{   rT   rU   r   r   r   test_conditional_swap_npm   rv   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&   Nr3   ).0ir   r   r   	<genexpr>   s    z9TestUnpack.test_unpack_tuple_of_arrays.<locals>.<genexpr>r    r?   )tupler   r   r2   r   rT   rB   rP   )rD   r6   tuptyrE   rF   rG   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 rg   )r9   r   rT   rB   rP   )rD   rE   rF   rG   r   r   r   test_unpack_nrt   s   zTestUnpack.test_unpack_nrtc                 C   sX   t }| tj}t|tjftd W d    n1 sw   Y  | dt	|j
 d S )Nr?   zfailed to unpack int32)r2   rh   r   ro   r   r   rN   rT   assertInstr	exception)rD   rE   raisesr   r   r   test_invalid_unpack   s
   zTestUnpack.test_invalid_unpackN)!__name__
__module____qualname__rH   rA   rQ   rV   r[   r\   r]   r^   r_   r`   ra   rb   re   rf   
ValueErrorrj   rl   rp   rr   rs   ru   rx   ry   rz   r{   r|   r}   r   r   r   r   r   r   r   r>   j   s:    
	r>   __main__)(numpyr4   unittestnumba.core.compilerr   r   
numba.corer   r   numbar   numba.tests.supportr   r   r	   enable_pyobj_flagsenable_pyobjectrA   force_pyobjectrT   nrtr   r   r   r!   r#   r'   r)   r*   r+   r.   r/   r0   r2   r9   r<   r=   r>   r   mainr   r   r   r   <module>   sB     