o
    1&i                     @   sd  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Z+G d)d* d*eZ,e-d+kre.  dS dS ),    N)njit)TypingError)jittypeof)types)TestCase*   @         )      x)yZS3    dtypes   XXXX_array_contents_XXXX   c                 C   s   t d S N )a0ir   r   KC:\wamp64\www\opt\env\Lib\site-packages\numba/tests/test_array_constants.pygetitem0      r   c                 C      t |  S N)a1r   r   r   r   getitem1#   r   r    c                 C   r   r   )a2r   r   r   r   getitem2'   r   r"   c                 C   r   r   )a3r   r   r   r   getitem3+   r   r$   c                 C   r   r   )a4r   r   r   r   getitem4/   r   r&   c                 C   r   r   )a5r   r   r   r   getitem53   r   r(   c                 C   r   r   )a6r   r   r   r   getitem67   r   r*   c                   C   s   t S r   )s1r   r   r   r   use_arrayscalar_const;      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   r2   c                   @   sv   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jdd ZdS )TestConstantArrayz
    Test array constants.
    c                 C   s4   t tjf|}dD ]}tj|||| q
d S )N)r   r   r   )r   r   int32r0   testingassert_array_equal)selfpyfunccfuncr   r   r   r   check_array_constL   s   z#TestConstantArray.check_array_constc                 C      |  t d S r   )r:   r   r7   r   r   r   test_array_const_0dQ      z%TestConstantArray.test_array_const_0dc                 C   r;   r   )r:   r    r<   r   r   r   test_array_const_1d_contigT   r>   z,TestConstantArray.test_array_const_1d_contigc                 C   r;   r   )r:   r"   r<   r   r   r   test_array_const_1d_noncontigW   r>   z/TestConstantArray.test_array_const_1d_noncontigc                 C   r;   r   )r:   r$   r<   r   r   r   test_array_const_2dZ   r>   z%TestConstantArray.test_array_const_2dc                 C   r;   r   )r:   r&   r<   r   r   r   test_record_array_const_contig]   r>   z0TestConstantArray.test_record_array_const_contigc                 C   r;   r   )r:   r(   r<   r   r   r   !test_record_array_const_noncontig`   r>   z3TestConstantArray.test_record_array_const_noncontigc                 C   sd   t jf}t|ddt}||}| D ]}d|v r*| d| | d|  dS 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*   inspect_llvm
splitlinesZassertInZfail)r7   sigr9   Zirliner   r   r   test_array_const_alignmentc   s   
z,TestConstantArray.test_array_const_alignmentc                 C   s$   t }td|}| | |  d S r   )r,   r   assertEqualr7   r8   r9   r   r   r   test_arrayscalar_constu   s   z(TestConstantArray.test_arrayscalar_constc                 C   s@   t }| t td| W d    d S 1 sw   Y  d S r   )r/   assertRaisesr   r   )r7   r8   r   r   r   test_write_to_global_arrayz   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   r8      r   z1TestConstantArray.test_issue_1850.<locals>.pyfuncr   N)r0   arrayr   rI   )r7   r8   r9   outr   rO   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|d j | }	 | ~d  | }t j
|| t|t| d S )Nc                      s    S r   r   r   biggier   r   r8      r-   zFTestConstantArray.test_too_big_to_freeze.<locals>.test.<locals>.pyfuncr   )r0   copyrI   r   r   Z
assertLesslenrD   nbytesZassertIsr5   Zassert_equal)rT   expectr8   r9   rQ   r<   rS   r   test   s   
z6TestConstantArray.test_too_big_to_freeze.<locals>.testi r   CFN)r0   arangereshapeZasfortranarrayrandomrI   r   Zlayout)r7   rY   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__r:   r=   r?   r@   rA   rB   rC   rH   rK   rM   rR   r   Zrun_test_in_subprocessr_   r   r   r   r   r3   G   s    r3   c                   @   s   e Zd Zdd ZdS )TestConstantBytesc                 C   s&   t }td|}tj| |  d S r   )r2   r   r0   r5   r6   rJ   r   r   r   test_constant_bytes   s   z%TestConstantBytes.test_constant_bytesN)r`   ra   rb   re   r   r   r   r   rd      s    rd   __main__)/numpyr0   ZunittestZnumbar   Znumba.core.errorsr   r   r   Z
numba.corer   Znumba.tests.supportr   rP   r   r4   r+   r\   r   r!   r]   Tr#   r   Zint8dtviewr%   r'   r1   Zfloat32r)   r.   r   r    r"   r$   r&   r(   r*   r,   r/   r2   r3   rd   r`   mainr   r   r   r   <module>   s@    


o