a
    –§»aj  ã                   @   sZ  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 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�rVe .¡  dS )+é    N)Úcompile_isolated)ÚTypingError)ÚjitÚtypeof)Útypesé*   é@   é   é   )é   é   Úx)ÚyZS3é    ©Údtypeéþÿÿÿs   XXXX_array_contents_XXXXé   c                 C   s   t d S ©N© )Úa0©Úir   r   úZ/home/yuhw/wc/pochoir/venv/lib/python3.9/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   Úgetitem52   s    r%   c                 C   s   t |  S r   )Úa6r   r   r   r   Úgetitem66   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_arrayB   s    r.   c                   @   sp   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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_constK   s    z#TestConstantArray.check_array_constc                 C   s   |   t¡ d S r   )r8   r   ©r4   r   r   r   Útest_array_const_0dQ   s    z%TestConstantArray.test_array_const_0dc                 C   s   |   t¡ d S r   )r8   r   r9   r   r   r   Útest_array_const_1d_contigT   s    z,TestConstantArray.test_array_const_1d_contigc                 C   s   |   t¡ d S r   )r8   r   r9   r   r   r   Útest_array_const_1d_noncontigW   s    z/TestConstantArray.test_array_const_1d_noncontigc                 C   s   |   t¡ d S r   )r8   r!   r9   r   r   r   Útest_array_const_2dZ   s    z%TestConstantArray.test_array_const_2dc                 C   s   |   t¡ d S r   )r8   r#   r9   r   r   r   Útest_record_array_const_contig]   s    z0TestConstantArray.test_record_array_const_contigc                 C   s   |   t¡ d S r   )r8   r%   r9   r   r   r   Ú!test_record_array_const_noncontig`   s    z3TestConstantArray.test_record_array_const_noncontigc                 C   sb   t jf}t|dd�tƒ}| |¡}| ¡ D ](}d|v 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)r4   Úsigr7   ZirÚliner   r   r   Útest_array_const_alignmentc   s    
z,TestConstantArray.test_array_const_alignmentc                 C   s(   t }t|dƒ}|j}|  |ƒ |ƒ ¡ d S r   )r)   r   r1   ÚassertEqual©r4   r5   r6   r7   r   r   r   Útest_arrayscalar_constu   s    
z(TestConstantArray.test_arrayscalar_constc                 C   s<   t }|  t¡� t|dƒ W d   ƒ n1 s.0    Y  d S r   )r+   ÚassertRaisesr   r   )r4   r5   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   r5   ˆ   s    z1TestConstantArray.test_issue_1850.<locals>.pyfuncr   N)r,   Úarrayr   r1   rD   )r4   r5   r6   Úoutr   rJ   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 thats prohibitively long and consume
        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   r5   ™   s    zFTestConstantArray.test_too_big_to_freeze.<locals>.test.<locals>.pyfuncr   )r,   ÚcopyrD   r   r   Z
assertLessÚlenZlibraryZget_llvm_strÚnbytesr1   ZassertIsr2   Zassert_equal)rO   Úexpectr5   r6   rL   r9   rN   r   Útest•   s    

z6TestConstantArray.test_too_big_to_freeze.<locals>.testi€–˜ r
   ÚCÚFN)r,   ÚarangeÚreshapeZasfortranarrayÚrandomrD   r   Zlayout)r4   rT   ZnelemZc_arrayZf_arrayr   r9   r   Útest_too_big_to_freeze�   s    z(TestConstantArray.test_too_big_to_freezeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   r:   r;   r<   r=   r>   r?   rC   rF   rH   rM   rZ   r   r   r   r   r/   F   s   r/   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   r1   r,   r2   r3   rE   r   r   r   Útest_constant_bytes¸   s    
z%TestConstantBytes.test_constant_bytesN)r[   r\   r]   r`   r   r   r   r   r_   ·   s   r_   Ú__main__)/Únumpyr,   ZunittestZnumba.core.compilerr   Znumba.core.errorsr   Znumbar   r   Z
numba.corer   rK   r   r0   r(   rW   r   r   rX   ÚTr    r   Zint8ÚdtÚviewr"   r$   r-   Úfloat32r&   r*   r   r   r   r!   r#   r%   r'   r)   r+   r.   ZTestCaser/   r_   r[   Úmainr   r   r   r   Ú<module>   s:   


q	
