U
    ,dl                     @   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    dtypes   XXXX_array_contents_XXXX   c                 C   s   t d S N )a0ir   r   D/tmp/pip-unpacked-wheel-eu7e0c37/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|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)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 5 Q R X 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 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   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__)/Z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-   Zfloat32r&   r*   r   r   r   r!   r#   r%   r'   r)   r+   r.   ZTestCaser/   r_   r[   mainr   r   r   r   <module>   s:   


q	
