U
    iâËdÉ  ã                   @   sf  d dl Zd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ e d¡Ze d¡Ze d	¡Zeddd
… Ze d¡jZe dejfdg¡Zejdejd� e¡Zeddd… Zejdejd�Z e dg¡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j,ƒZ-G d)d*„ d*ej,ƒZ.e/d+k�rbe 0¡  dS ),é    N)Úcompile_isolated)ÚTypingError)ÚjitÚtypeof)Útypes)Úskip_m1_llvm_rtdyld_failureé*   é@   é   é   )é   é   Úx)ÚyZS3é    ©Údtypeéþÿÿÿs   XXXX_array_contents_XXXXé   c                 C   s   t d S ©N© )Úa0©Úir   r   úY/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_array_constants.pyÚgetitem0   s    r   c                 C   s   t |  S ©N)Úa1r   r   r   r   Úgetitem1#   s    r   c                 C   s   t |  S r   )Úa2r   r   r   r   Úgetitem2'   s    r    c                 C   s   t |  S r   )Úa3r   r   r   r   Úgetitem3+   s    r"   c                 C   s   t |  S r   )Úa4r   r   r   r   Úgetitem4/   s    r$   c                 C   s   t |  S r   )Úa5r   r   r   r   Úgetitem53   s    r&   c                 C   s   t |  S r   )Úa6r   r   r   r   Úgetitem67   s    r(   c                   C   s   t S r   )Ús1r   r   r   r   Úuse_arrayscalar_const;   s    r*   c                   C   s   dt d< d S )Nr   r   )Úmyarrayr   r   r   r   Úwrite_to_global_array?   s    r,   c                   C   s   t jdt jd�S )Ns   foor   )ÚnpÚ
frombufferZuint8r   r   r   r   Úbytes_as_const_arrayC   s    r/   c                   @   st   e Zd 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edd„ ƒZdS )ÚTestConstantArrayz
    Test array constants.
    c                 C   s8   t |tjfƒ}|j}dD ]}tj ||ƒ||ƒ¡ qd S )N)r   r   r   )r   r   Úint32Úentry_pointr-   ÚtestingÚassert_array_equal)ÚselfÚpyfuncÚcresÚcfuncr   r   r   r   Úcheck_array_constL   s    z#TestConstantArray.check_array_constc                 C   s   |   t¡ d S r   )r9   r   ©r5   r   r   r   Útest_array_const_0dR   s    z%TestConstantArray.test_array_const_0dc                 C   s   |   t¡ d S r   )r9   r   r:   r   r   r   Útest_array_const_1d_contigU   s    z,TestConstantArray.test_array_const_1d_contigc                 C   s   |   t¡ d S r   )r9   r    r:   r   r   r   Útest_array_const_1d_noncontigX   s    z/TestConstantArray.test_array_const_1d_noncontigc                 C   s   |   t¡ d S r   )r9   r"   r:   r   r   r   Útest_array_const_2d[   s    z%TestConstantArray.test_array_const_2dc                 C   s   |   t¡ d S r   )r9   r$   r:   r   r   r   Útest_record_array_const_contig^   s    z0TestConstantArray.test_record_array_const_contigc                 C   s   |   t¡ d S r   )r9   r&   r:   r   r   r   Ú!test_record_array_const_noncontiga   s    z3TestConstantArray.test_record_array_const_noncontigc                 C   sb   t jf}t|dd�tƒ}| |¡}| ¡ D ](}d|kr*|  d|¡ |  d|¡  q^q*|  d¡ dS )zt
        Issue #1933: the array declaration in the LLVM IR must have
        the right alignment specified.
        T)ZnopythonZXXXX_array_contents_XXXXzconstant [24 x i8]z	, align 4z+could not find array declaration in LLVM IRN)r   Zintpr   r(   Zinspect_llvmÚ
splitlinesZassertInZfail)r5   Úsigr8   ZirÚliner   r   r   Útest_array_const_alignmentd   s    
z,TestConstantArray.test_array_const_alignmentc                 C   s(   t }t|dƒ}|j}|  |ƒ |ƒ ¡ d S r   )r*   r   r2   ÚassertEqual©r5   r6   r7   r8   r   r   r   Útest_arrayscalar_constv   s    
z(TestConstantArray.test_arrayscalar_constc              	   C   s(   t }|  t¡� t|dƒ W 5 Q R X d S r   )r,   ÚassertRaisesr   r   )r5   r6   r   r   r   Útest_write_to_global_array}   s    z,TestConstantArray.test_write_to_global_arrayc                    s:   t  dg¡‰ ‡ fdd„}t|dƒ}| ¡ }|  |d¡ dS )zy
        This issue is caused by an unresolved bug in numpy since version 1.6.
        See numpy GH issue #3147.
        éV   c                      s   ˆ d S )Nr   r   r   ©Zconstarrr   r   r6   ‰   s    z1TestConstantArray.test_issue_1850.<locals>.pyfuncr   N)r-   Úarrayr   r2   rE   )r5   r6   r7   Úoutr   rK   r   Útest_issue_1850‚   s
    
z!TestConstantArray.test_issue_1850c                    sr   ‡ fdd„}d}t  |¡ |¡}t  t j d|d f¡¡}ˆ  t|ƒjd¡ ˆ  t|ƒjd¡ ||ƒ ||ƒ dS )zº
        Test issue https://github.com/numba/numba/issues/2188 where freezing
        a constant array into the code that's prohibitively long and consumes
        too much RAM.
        c                    s”   t  ˆ ¡}ˆ tˆ ƒt|ƒ¡ ‡ fdd„}t|dƒ}ˆ t|j ¡ ƒˆ j	¡ | 
¡ }ˆ ˆ |¡ ~d ‰ | 
¡ }t j ||¡ ˆ t|ƒt|ƒ¡ d S )Nc                      s   ˆ S r   r   r   ©Úbiggier   r   r6   ›   s    zFTestConstantArray.test_too_big_to_freeze.<locals>.test.<locals>.pyfuncr   )r-   ÚcopyrE   r   r   Z
assertLessÚlenZlibraryZget_llvm_strÚnbytesr2   ZassertIsr3   Zassert_equal)rP   Úexpectr6   r7   rM   r:   rO   r   Útest—   s    

z6TestConstantArray.test_too_big_to_freeze.<locals>.testi€–˜ r   ÚCÚFN)r-   ÚarangeÚreshapeZasfortranarrayÚrandomrE   r   Zlayout)r5   rU   ZnelemZc_arrayZf_arrayr   r:   r   Útest_too_big_to_freeze�   s    z(TestConstantArray.test_too_big_to_freezeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   r;   r<   r=   r>   r?   r@   rD   rG   rI   rN   r   r[   r   r   r   r   r0   G   s   r0   c                   @   s   e Zd Zdd„ ZdS )ÚTestConstantBytesc                 C   s*   t }t|dƒ}|j}tj |ƒ |ƒ ¡ d S r   )r/   r   r2   r-   r3   r4   rF   r   r   r   Útest_constant_bytesº   s    
z%TestConstantBytes.test_constant_bytesN)r\   r]   r^   ra   r   r   r   r   r`   ¹   s   r`   Ú__main__)1Únumpyr-   ZunittestZnumba.core.compilerr   Znumba.core.errorsr   Znumbar   r   Z
numba.corer   Znumba.tests.supportr   rL   r   r1   r)   rX   r   r   rY   ÚTr!   r   Zint8ÚdtÚviewr#   r%   r.   Zfloat32r'   r+   r   r   r    r"   r$   r&   r(   r*   r,   r/   ZTestCaser0   r`   r\   Úmainr   r   r   r   Ú<module>   s<   


r	
