U
    iâËd¡  ã                   @   sX  d dl Zd dlmZmZmZ d dlmZ d dlm	Z	 d dl
Z
e d¡Zdd„ Zejdejd�Zejdejd�Zeed d	 7 Zd
d„ Ze dejfdejfg¡Zejded�ZeeeƒƒD ]Zeee _ed ee _qºdd„ Zdd„ Ze dejfdej fg¡Z!ejde!d�Z"eee"ƒƒD ]"Zed e"e _#ed e"e _$�qdd„ Z%ejded�d  Z&de&_de&_edd�dd„ ƒZ'edd�dd„ ƒZ(d Z)d!Z*d"Z+d#Z,e -d$¡e .d%¡fZ/e 0d&¡ffZ1d'e 0d&¡fd(d)fZ2d*d+„ Z3d,d-„ Z4d.d/„ Z5d0d1„ Z6d2d3„ Z7d4d5„ Z8d6d7„ Z9e :d¡Z;e :d8¡Z<ed9d:„ ƒZ=d;d<„ Z>G d=d>„ d>e
j?ƒZ@eAd?k�rTe
 B¡  dS )@é    N)ÚjitÚnjitÚerrors)Úregister_jitable)Úusecasesé
   c                 C   s   | t jd  }|S )Nr   )ÚXÚshape©ÚxÚy© r   úQ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_globals.pyÚglobal_ndarray_func
   s    r   ©Údtypey              ð?c                 C   s"   t t| ƒƒD ]}t| | |< qd S ©N)ÚrangeÚlenÚcplx_X©ÚaÚir   r   r   Úglobal_cplx_arr_copy   s    r   r   Úbg      à?c                 C   s"   t t| ƒƒD ]}t| | |< qd S r   )r   r   Úrec_Xr   r   r   r   Úglobal_rec_arr_copy"   s    r   c                 C   s2   t t| ƒƒD ] }t| j| |< t| j||< qd S r   )r   r   r   r   r   )r   r   r   r   r   r   Úglobal_rec_arr_extract_fields'   s    r   ÚcÚdg      %@c                 C   sN   t t| ƒƒD ]<}t| j| |< t| j||< t| j||< t| j||< qd S r   )r   r   r   r   r   Úrec_Yr   r   )r   r   r   r   r   r   r   r   Úglobal_two_rec_arrs5   s
    r!   é   g      ø?T©Znopythonc                 C   s   | j tj kS r   )r   Úrecord_only_X)r   r   r   r   Úglobal_record_funcB   s    r%   c                 C   s   t  | |¡S r   )r   Zandornopythonr
   r   r   r   Úglobal_module_funcG   s    r&   )r"   é   )r   r   )r"   r   )g333333ó?g      @é   é   é   ÚZy               @ÚAc                   C   s   t d t d  S ©Nr   r"   )Útup_intr   r   r   r   Úglobal_int_tupleT   s    r/   c                   C   s   t d t d  S r-   )Útup_strr   r   r   r   Úglobal_str_tupleX   s    r1   c                  C   s   t d } t d }t|  | S r-   )Ú	tup_mixedr   )ÚidxÚfieldr   r   r   Úglobal_mixed_tuple\   s    r5   c                   C   s   t d t d  S r-   )Ú	tup_floatr   r   r   r   Úglobal_float_tupleb   s    r7   c                   C   s   t d t d  S r-   )Útup_npy_intsr   r   r   r   Úglobal_npy_int_tuplef   s    r9   c                   C   s   dt d d d< d S )Nç      $@r   )Útup_tup_arrayr   r   r   r   Úglobal_write_to_arr_in_tuplej   s    r<   c                   C   s   dt d d d< d S )Nr:   r   r"   )Úmixed_tup_tup_arrayr   r   r   r   Ú"global_write_to_arr_in_mixed_tuplen   s    r>   Fc                  G   s   d S r   r   )Úargsr   r   r   Ú_sinkv   s    r@   c                   C   s   t ttƒ ttfS r   )r@   Ú_glbl_np_bool_TÚ_glbl_np_bool_Fr   r   r   r   Úglobal_npy_boolz   s    
rC   c                   @   sÌ   e 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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d1S )2ÚTestGlobalsc                 K   s"   t f |Žtƒ}|  |dƒd¡ d S )Nr"   é   )r   r   ÚassertEqual)ÚselfÚjitargsÚ	ctestfuncr   r   r   Úcheck_global_ndarray�   s    z TestGlobals.check_global_ndarrayc                 C   s   | j dd� d S ©NT)Zforceobj©rJ   ©rG   r   r   r   Útest_global_ndarray†   s    zTestGlobals.test_global_ndarrayc                 C   s   | j dd� d S ©NTr#   rL   rM   r   r   r   Útest_global_ndarray_npm‹   s    z#TestGlobals.test_global_ndarray_npmc                 K   s<   t f |Žtƒ}tjttƒtjd�}||ƒ tj |t¡ d S ©Nr   )	r   r   ÚnpÚzerosr   r   Ú
complex128ÚtestingÚassert_equal©rG   rH   rI   Zarrr   r   r   Úcheck_global_complex_arr�   s    z$TestGlobals.check_global_complex_arrc                 C   s   | j dd� d S rK   ©rX   rM   r   r   r   Útest_global_complex_arr–   s    z#TestGlobals.test_global_complex_arrc                 C   s   | j dd� d S rO   rY   rM   r   r   r   Útest_global_complex_arr_npm™   s    z'TestGlobals.test_global_complex_arr_npmc                 K   s8   t f |Žtƒ}tjtjtd�}||ƒ tj |t¡ d S rQ   )	r   r   rR   rS   r   r	   Úx_dtrU   rV   rW   r   r   r   Úcheck_global_rec_arr�   s    z TestGlobals.check_global_rec_arrc                 C   s   | j dd� d S rK   ©r]   rM   r   r   r   Útest_global_rec_arr¤   s    zTestGlobals.test_global_rec_arrc                 C   s   | j dd� d S rO   r^   rM   r   r   r   Útest_global_rec_arr_npm§   s    z#TestGlobals.test_global_rec_arr_npmc                 K   s`   t f |Žtƒ}tjtjtjd�}tjtjtjd�}|||ƒ tj 	|tj
¡ tj 	|tj¡ d S rQ   )r   r   rR   rS   r   r	   Úint32Úfloat32rU   rV   r   r   )rG   rH   rI   Úarr1Úarr2r   r   r   Úcheck_global_rec_arr_extract«   s    
z(TestGlobals.check_global_rec_arr_extractc                 C   s   | j dd� d S rK   ©re   rM   r   r   r   Útest_global_rec_arr_extract´   s    z'TestGlobals.test_global_rec_arr_extractc                 C   s   | j dd� d S rO   rf   rM   r   r   r   Útest_global_rec_arr_extract_npm·   s    z+TestGlobals.test_global_rec_arr_extract_npmc                 K   s¨   t f |Žtƒ}tjtjtjd�}tjtjtjd�}tjtjtj	d�}tjtjtj
d�}|||||ƒ tj |tj¡ tj |tj¡ tj |tj¡ tj |tj¡ d S rQ   )r   r!   rR   rS   r   r	   ra   rb   r    Úint16Úfloat64rU   rV   r   r   r   r   )rG   rH   rI   rc   rd   Zarr3Zarr4r   r   r   Úcheck_two_global_rec_arrs»   s    z%TestGlobals.check_two_global_rec_arrsc                 C   s   | j dd� d S rK   ©rk   rM   r   r   r   Útest_two_global_rec_arrsÈ   s    z$TestGlobals.test_two_global_rec_arrsc                 C   s   | j dd� d S rO   rl   rM   r   r   r   Útest_two_global_rec_arrs_npmË   s    z(TestGlobals.test_two_global_rec_arrs_npmc                 C   s   t ddƒ}|  d|¡ d S )Nr*   é   T)r&   rF   )rG   Úresr   r   r   Útest_global_moduleÎ   s    
zTestGlobals.test_global_modulec                 C   sJ   t jdtd�d }d|_t|ƒ}|  d|¡ d|_t|ƒ}|  d|¡ d S )Nr"   r   r   Tr'   F)rR   Úrecarrayr\   r   r%   rF   )rG   r   rp   r   r   r   Útest_global_recordÓ   s    zTestGlobals.test_global_recordc                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )r/   r   rF   ©rG   ZpyfuncÚjitfuncr   r   r   Útest_global_int_tupleÝ   s    z!TestGlobals.test_global_int_tuplec                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )r1   r   rF   rt   r   r   r   Útest_global_str_tupleâ   s    z!TestGlobals.test_global_str_tuplec                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )r5   r   rF   rt   r   r   r   Útest_global_mixed_tupleç   s    z#TestGlobals.test_global_mixed_tuplec                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )r7   r   rF   rt   r   r   r   Útest_global_float_tupleì   s    z#TestGlobals.test_global_float_tuplec                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )r9   r   rF   rt   r   r   r   Útest_global_npy_int_tupleñ   s    z%TestGlobals.test_global_npy_int_tuplec              
   C   sN   t tfD ]@}t|ƒ}|  tj¡�}|ƒ  W 5 Q R X d}|  |t|jƒ¡ qd S )Nz%Cannot modify readonly array of type:)	r<   r>   r   ÚassertRaisesr   ZTypingErrorZassertInÚstrÚ	exception)rG   Úfuncru   ÚeÚmsgr   r   r   Ú!test_global_write_to_arr_in_tupleö   s    ÿz-TestGlobals.test_global_write_to_arr_in_tuplec                 C   s    t }t|ƒ}|  |ƒ |ƒ ¡ d S r   )rC   r   rF   rt   r   r   r   Útest_global_npy_bool  s    z TestGlobals.test_global_npy_boolN)Ú__name__Ú
__module__Ú__qualname__rJ   rN   rP   rX   rZ   r[   r]   r_   r`   re   rg   rh   rk   rm   rn   rq   rs   rv   rw   rx   ry   rz   r�   r‚   r   r   r   r   rD      s0   	
rD   Ú__main__)CÚnumpyrR   Znumbar   r   r   Znumba.extendingr   Znumba.testsr   ZunittestZaranger   r   rT   r   Útmpr   r   ra   rb   r\   rr   r   r   r   r   r   r   r   r   ri   rj   Zy_dtr    r   r   r!   r$   r%   r&   r.   r0   r2   r6   Zuint64Zint8r8   Zonesr;   r=   r/   r1   r5   r7   r9   r<   r>   Zbool_rA   rB   r@   rC   ZTestCaserD   rƒ   Úmainr   r   r   r   Ú<module>   sj   

	




 
