U
    ,dD                     @   s   d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZ d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZ e Zd	d
 ZG dd deZG dd de jZedkre   dS )    N)TestCase)compile_isolated)jittyped)typesutils)TypingErrorLoweringError)_header_lead)tag_32bitcaptured_stdoutc                 C   s,   dd t | D }d}|D ]}||7 }q|S )Nc                 S   s   g | ]}|qS  r   .0ir   r   B/tmp/pip-unpacked-wheel-eu7e0c37/numba/tests/test_comprehension.py
<listcomp>   s     zcomp_list.<locals>.<listcomp>r   range)nlsr   r   r   r   	comp_list   s
    
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestListComprehensionc                 C   sX   t }t|tjg}|j}| |d|d | |d|d | |d|d d S )N   r   )r   r   r   intpZentry_pointassertEqual)selfpyfunccrescfuncr   r   r   test_comp_list    s    z$TestListComprehension.test_comp_listc                     s  t ddfdddd }dd }d	d
 }dd }dd }dd }dd }dd }dd }	dd }
dd }dd }dd }dd  }d!d" }d#d$ }d%d& }d'  fd(d)}d'  fd*d+}d,d- }fd.d/}d0d1 }d2d3 }d4d5 }d6d7 }||||||||	|
|||||||||||||||g}d8d9d:d;d<g}|D ]x}z&t dd|}| |||| W nJ tk
r   ztj|||| W n tk
r    Y nX Y nX q8| t}t dd|}|| W 5 Q R X t	j
d=krd>}nd?}d@S )Az3 Tests the large number of use cases defined below Tnopythonc                    s$   | dk r| S  | d  | d  S )N      r   r   fib3r   r   r*   ,   s    z7TestListComprehension.test_bulk_use_cases.<locals>.fib3c                 S   s   dd t dt| d D S )z Test basic list comprehension c                 S   s   g | ]}|qS r   r   r   r   r   r   r   4   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list1.<locals>.<listcomp>r'   )r   lenxr   r   r   list12   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list1c                 S   s   dd | D S )z% Test conditional list comprehension c                 S   s   g | ]}|d k r|qS r&   r   r   yr   r   r   r   8   s      zLTestListComprehension.test_bulk_use_cases.<locals>.list2.<locals>.<listcomp>r   r,   r   r   r   list26   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list2c                 S   s   dd | D S )z! Test ternary list comprehension c                 S   s   g | ]}|d k r|ndqS )r&   r   r   r0   r   r   r   r   <   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list3.<locals>.<listcomp>r   r,   r   r   r   list3:   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list3c                 S   s   t dddgS )z* Test list comprehension to np.array ctor r'   r&      nparrayr,   r   r   r   list4>   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list4c                    s   t  fdd D S )z1 Test nested list comprehension to np.array ctor c                    s    g | ]}t d d  D qS )c                 S   s   g | ]}|qS r   r   r   zr   r   r   r   E   s     zWTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>.<listcomp>r5   r0   r,   r   r   r   E   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>r5   r,   r   r,   r   list5C   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list5c                    s   dd   fdd| D S )z2 Test use of inner function in list comprehension c                 S   s   | d S Nr'   r   r,   r   r   r   innerI   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.innerc                    s   g | ]} |qS r   r   r9   r=   r   r   r   K   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.<listcomp>r   r,   r   r>   r   list6G   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list6c                    s"   dfdd  fdd| D S )z+ Test use of closure in list comprehension r4   c                    s   |   S )Nr   r,   )r1   r   r   r=   Q   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.innerc                    s   g | ]} |qS r   r   r9   r>   r   r   r   S   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.<listcomp>r   r,   r   )r=   r1   r   list7M   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list7c                 S   s"   dd | D }dd }||}|S )z9 Test use of list comprehension as arg to inner function c                 S   s   g | ]}|d  qS r'   r   r9   r   r   r   r   W   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.<listcomp>c                 S   s   | d d S Nr   r'   r   r,   r   r   r   r=   Y   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.innerr   )r-   r   r=   qr   r   r   list8U   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list8c                    s"   dd | D   fdd}|| S )z2 Test use of list comprehension access in closure c                 S   s   g | ]}|d  qS rA   r   r9   r   r   r   r   `   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.<listcomp>c                    s   | d  d  S rB   r   r,   r   r   r   r=   b   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.innerr   r-   r=   r   rE   r   list9^   s    z8TestListComprehension.test_bulk_use_cases.<locals>.list9c                    s"   dd | D   fdd}| S )z= Test use of list comprehension access in closure and as arg c                 S   s   g | ]}|d  qS rA   r   r9   r   r   r   r   h   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.<listcomp>c                    s    fdd| D S )Nc                    s   g | ]}| d   qS )r   r   r0   rE   r   r   r   k   s     z\TestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.inner.<locals>.<listcomp>r   r,   rE   r   r   r=   j   s    zHTestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.innerr   rF   r   rE   r   list10f   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list10c                 S   s   dd | D }|S )z6 Test scalar array construction in list comprehension c                 S   s   g | ]}t |qS r   r5   r9   r   r   r   r   p   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list11.<locals>.<listcomp>r   r-   r   r   r   r   list11n   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list11c                 S   s   dd | D }|S )z@ Test scalar type conversion construction in list comprehension c                 S   s   g | ]}t |qS r   )r6   float64r9   r   r   r   r   u   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list12.<locals>.<listcomp>r   rI   r   r   r   list12s   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list12c                 S   s   dd | D }|S )zH Test use of explicit numpy scalar ctor reference in list comprehension c                 S   s   g | ]}t |qS r   )numpyrK   r9   r   r   r   r   z   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list13.<locals>.<listcomp>r   rI   r   r   r   list13x   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list13c                 S   s   dd | D }|S )z@ Test use of python scalar ctor reference in list comprehension c                 S   s   g | ]}t |qS r   floatr9   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list14.<locals>.<listcomp>r   rI   r   r   r   list14}   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list14c                 S   s   dd | D }t |S )zo Test use of python scalar ctor reference in list comprehension followed by np array construction from the listc                 S   s   g | ]}t |qS r   rO   r9   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list15.<locals>.<listcomp>r5   rI   r   r   r   list15   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list15c                 S   s8   dd | D }dd | D }t |}t |}|| S )zH Test type unification from np array ctors consuming list comprehension c                 S   s   g | ]}t |qS r   rO   r9   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list16.<locals>.<listcomp>c                 S   s   g | ]}|qS r   r   r9   r   r   r   r      s     r5   )r-   l1l2ZzeZoer   r   r   list16   s
    

z9TestListComprehension.test_bulk_use_cases.<locals>.list16c                    s    fdd D S )z6 Test complex list comprehension including math calls c              	      sD   g | ]<} D ]2} D ](}t |d  |d   |kr|||fqqqS r/   )r6   sqrt)r   abcr,   r   r   r      s        zMTestListComprehension.test_bulk_use_cases.<locals>.list17.<locals>.<listcomp>r   r,   r   r,   r   list17   s    
z9TestListComprehension.test_bulk_use_cases.<locals>.list17	   c                    s$   g }| D ]}| k r| | q|S )z3 Test loop list with outer scope var as conditionalappend)r-   r:   r   _OUTER_SCOPE_VARr   r   list18   s
    z9TestListComprehension.test_bulk_use_cases.<locals>.list18c                    s    fdd| D S )z8 Test list comprehension with outer scope as conditionalc                    s   g | ]}| k r|qS r   r   r   r^   r   r   r      s      zMTestListComprehension.test_bulk_use_cases.<locals>.list19.<locals>.<listcomp>r   r,   r^   r   r   list19   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list19c                 S   s   dd | D S )z Test return empty list c                 S   s   g | ]}|d kr|qS )ir   r   r   r   r   r      s      zMTestListComprehension.test_bulk_use_cases.<locals>.list20.<locals>.<listcomp>r   r,   r   r   r   list20   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list20c                    s    fdd| D S )z5 Test call a jitted function in a list comprehension c                    s   g | ]} |qS r   r   r   r)   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list21.<locals>.<listcomp>r   r,   r)   r   r   list21   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list21c                    s.   dd | D }dd | D   fdd|D S )zH Test create two lists comprehensions and a third walking the first two c                 S   s   g | ]}|d  qS rA   r   r0   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list22.<locals>.<listcomp>c                 S   s   g | ]}|d  qS rA   r   r0   r   r   r   r      s     c                    s"   g | ]} D ]}||kr|qqS r   r   )r   r-   r1   rX   r   r   r      s
        r   )r-   rW   r   rd   r   list22   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list22c                 S   s   dd | D }| d |S )z0 Test operation on comprehension generated list c                 S   s   g | ]}|qS r   r   r0   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list23.<locals>.<listcomp>r'   r\   r-   r:   r   r   r   list23   s    
z9TestListComprehension.test_bulk_use_cases.<locals>.list23c                 S   s   dd | D }|S )z Test type promotion c                 S   s    g | ]}|d krt |n|qS )r4   rO   r0   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list24.<locals>.<listcomp>r   rf   r   r   r   list24   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list24c                    s,   t ddddg  fddtdD }|S )Nr'   r&         c                    s   g | ]}|t  kr|qS r   )listr   Zincludedr   r   r      s      zMTestListComprehension.test_bulk_use_cases.<locals>.list25.<locals>.<listcomp>
   r6   r7   r   )r-   Znot_includedr   rl   r   list25   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list25r'   r&   r4      r   l        @       N)r   r   
ValueErrorr6   testingZassert_allclose	ExceptionassertRaisesr   sysmaxsize) r   r.   r2   r3   r8   r;   r?   r@   rD   rG   rH   rJ   rL   rN   rQ   rR   rU   rZ   r`   ra   rb   rc   re   rg   rh   ro   fvarrefr"   raisesbitsr   )r_   r*   r   test_bulk_use_cases(   s    	
                z)TestListComprehension.test_bulk_use_casesc                 C   s@   dd }t dd|}dddg}||}||}| || d S )Nc                 S   s   t  }dd | D }|S )Nc                 S   s   g | ]}|qS r   r   r   r-   r   r   r   r      s     zUTestListComprehension.test_objmode_inlining.<locals>.objmode_func.<locals>.<listcomp>)object)r1   r:   Zinlinedr   r   r   objmode_func   s    zATestListComprehension.test_objmode_inlining.<locals>.objmode_funcT)Zforceobjr'   r&   r4   )r   ZassertPreciseEqual)r   r   r"   texpectedgotr   r   r   test_objmode_inlining   s    
z+TestListComprehension.test_objmode_inliningN)__name__
__module____qualname__r#   r~   r   r   r   r   r   r      s    =r   c                   @   s   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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d0d1 Zd2d3 Zd4d5 Zd6S )7TestArrayComprehensionFc           
      O   s   | dd}| dd}| dd}td|d|}|| }|| }	tj||	 |rh| |	d j| |r| d||j	d	  n| 
d||j	d	  |r| d
||j	d	  dS )z^A generic check function that run both pyfunc, and jitted pyfunc,
        and compare results.run_parallelFassert_allocate_listassert_dtypeT)r%   parallelr'   zallocate listr   z@do_schedulingN)getr   r6   rt   Zassert_array_equalr   dtypeassertInZinspect_llvmZ
signaturesZassertNotIn)
r   r    argskwargsr   r   r   r"   Zpyresr!   r   r   r   check   s    zTestArrayComprehension.checkc                 C   s,   dd }|  |d tr(| j |ddd d S )Nc                    s(   | d  t  fddt| D }|S )Nr&   c                    s   g | ]}|  qS r   r   r   mr   r   r     s     z\TestArrayComprehension.test_comp_with_array_1.<locals>.comp_with_array_1.<locals>.<listcomp>rn   r   r   r   r   r   comp_with_array_1	  s    zHTestArrayComprehension.test_comp_with_array_1.<locals>.comp_with_array_1r   Tr   r   PARALLEL_SUPPORTED)r   r   r   r   r   test_comp_with_array_1  s    z-TestArrayComprehension.test_comp_with_array_1c                 C   s   dd }|  |dd d S )Nc                    s&   t |  | }t  fdd|D S )Nc                    s$   g | ]}| k r|| n|d  qS r/   r   r   	thresholdr   r   r     s     z\TestArrayComprehension.test_comp_with_array_2.<locals>.comp_with_array_2.<locals>.<listcomp>)r6   Zaranger7   )r   r   Ar   r   r   comp_with_array_2  s    zHTestArrayComprehension.test_comp_with_array_2.<locals>.comp_with_array_2r   r   r   )r   r   r   r   r   test_comp_with_array_2  s    z-TestArrayComprehension.test_comp_with_array_2c                 C   sB   dd }dd l m  m} zd|_| j|ddd W 5 d|_X d S )Nc                    s(   | d  t  fddt| D }|S )Nr&   c                    s   g | ]}|  qS r   r   r   r   r   r   r     s     zjTestArrayComprehension.test_comp_with_array_noinline.<locals>.comp_with_array_noinline.<locals>.<listcomp>rn   r   r   r   r   comp_with_array_noinline  s    zVTestArrayComprehension.test_comp_with_array_noinline.<locals>.comp_with_array_noinliner   TFr   r   Znumba.core.inline_closurecallcoreZinline_closurecallZenable_inline_arraycallr   )r   r   icr   r   r   test_comp_with_array_noinline  s    z4TestArrayComprehension.test_comp_with_array_noinlinec                 C   s   dd }| j |ddd d S )Nc                 S   s,   dg}t | D ]}|| qt|}|S )Nr   )r   r]   r6   r7   )r   lstr   r   r   r   r   r   '  s
    
zaTestArrayComprehension.test_comp_with_array_noinline_issue_6053.<locals>.comp_with_array_noinliner   Tr   r   )r   r   r   r   r   (test_comp_with_array_noinline_issue_6053&  s    z?TestArrayComprehension.test_comp_with_array_noinline_issue_6053c                 C   s,   dd }|  |d tr(| j |ddd d S )Nc                    s    t  fddt D }|S )Nc                    s"   g | ]  fd dt D qS )c                    s   g | ]} | qS r   r   r   jr   r   r   r   2  s     zmTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r   2  s     zbTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>rn   r   r   r(   r   comp_nest_with_array1  s    zNTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_arrayr   Tr   r   )r   r   r   r   r   test_comp_nest_with_array0  s    z0TestArrayComprehension.test_comp_nest_with_arrayc                 C   s,   dd }|  |d tr(| j |ddd d S )Nc                    s    t  fddt D }|S )Nc                    s$   g | ]  fd dt D qS )c                    s$   g | ]  fd dt D qS )c                    s   g | ]}  | qS r   r   )r   k)r   r   r   r   r   ;  s     z|TestArrayComprehension.test_comp_nest_with_array_3.<locals>.comp_nest_with_array_3.<locals>.<listcomp>.<listcomp>.<listcomp>r   r   )r   r   )r   r   r   ;  s     zqTestArrayComprehension.test_comp_nest_with_array_3.<locals>.comp_nest_with_array_3.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r   ;  s     zfTestArrayComprehension.test_comp_nest_with_array_3.<locals>.comp_nest_with_array_3.<locals>.<listcomp>rn   r   r   r(   r   comp_nest_with_array_3:  s    zRTestArrayComprehension.test_comp_nest_with_array_3.<locals>.comp_nest_with_array_3r   Tr   r   )r   r   r   r   r   test_comp_nest_with_array_39  s    z2TestArrayComprehension.test_comp_nest_with_array_3c                 C   sB   dd }dd l m  m} zd|_| j|ddd W 5 d|_X d S )Nc                    s    t  fddt D }|S )Nc                    s"   g | ]  fd dt D qS )c                    s   g | ]} | qS r   r   r   r   r   r   r   D  s     zTestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinline.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r   D  s     ztTestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinline.<locals>.<listcomp>rn   r   r   r(   r   comp_nest_with_array_noinlineC  s    z`TestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinliner   TFr   r   r   )r   r   r   r   r   r   "test_comp_nest_with_array_noinlineB  s    
z9TestArrayComprehension.test_comp_nest_with_array_noinlinec                 C   s   dd }|  |dd d S )Nc                 S   s   t dd t| |D }|S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r   Q  s     zdTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_range.<locals>.<listcomp>rn   r   r   r   r   r   r   comp_with_array_rangeP  s    zPTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_ranger   rm   r   )r   r   r   r   r   test_comp_with_array_rangeO  s    z1TestArrayComprehension.test_comp_with_array_rangec                 C   s   dd }|  |dd d S )Nc                 S   s    t dd t| |dD }|S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r   X  s     zvTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_step.<locals>.<listcomp>r&   rn   r   r   r   r   comp_with_array_range_and_stepW  s    zbTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_stepr   rm   r   )r   r   r   r   r   #test_comp_with_array_range_and_stepV  s    z:TestArrayComprehension.test_comp_with_array_range_and_stepc                 C   s   dd }| j |ddd d S )Nc                 S   s   t dd t| D }|S )Nc                 S   s   g | ]}|d  dkr|qS )r&   r'   r   r   r   r   r   r   _  s      zpTestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditional.<locals>.<listcomp>rn   r   r   r   r   comp_with_array_conditional^  s    z\TestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditionalrm   Tr   r   )r   r   r   r   r    test_comp_with_array_conditional]  s    z7TestArrayComprehension.test_comp_with_array_conditionalc                 C   s   dd }| j |ddd d S )Nc                    s    t  fddt D }|S )Nc                    s.   g | ]&  d  dkr fddt D qS )r&   r'   c                    s   g | ]} | qS r   r   r   r   r   r   r   f  s     zTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r   f  s      zzTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>rn   r   r   r(   r    comp_nest_with_array_conditionale  s    zfTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditionalr   Tr   r   )r   r   r   r   r   %test_comp_nest_with_array_conditionald  s    z<TestArrayComprehension.test_comp_nest_with_array_conditionalc              	   C   sR   dd }|  t}| |d W 5 Q R X | tt|j | dt|j d S )Nc                 S   s   t dd t| D }|S )Nc                    s&   g | ]  fd dt  d D qS )c                    s   g | ]} | qS r   r   r   r   r   r   r   m  s     zwTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>.<listcomp>r'   r   r   r   r   r   r   m  s     zlTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>rn   r   r   r   r   comp_nest_with_dependencyl  s    zXTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependencyr   zarray(undefined,rv   r   r   r   r
   str	exception)r   r   r|   r   r   r   test_comp_nest_with_dependencyk  s
    z5TestArrayComprehension.test_comp_nest_with_dependencyc              	   C   sP   dd }|  t}| | W 5 Q R X | tt|j | dt|j d S )Nc                  S   s*   t dddgdddg} tdd | D S )	Nr'   r&   r4   rp   r   ri   c                 S   s   g | ]\}}|qS r   r   )r   rW   rX   r   r   r   r   x  s     zdTestArrayComprehension.test_comp_unsupported_iter.<locals>.comp_unsupported_iter.<locals>.<listcomp>)zipr6   r7   )valr   r   r   comp_unsupported_iterv  s    zPTestArrayComprehension.test_comp_unsupported_iter.<locals>.comp_unsupported_iterz1Unsupported iterator found in array comprehensionr   )r   r   r|   r   r   r   test_comp_unsupported_iteru  s    z1TestArrayComprehension.test_comp_unsupported_iterc                 C   s4   dd }| j |ddd dd }| j |ddd d S )	Nc                 S   s   ddddg}t |}|S )Nr'   r&   r4   rp   r5   r   r   rW   r   r   r   no_array_comp1  s    
zATestArrayComprehension.test_no_array_comp.<locals>.no_array_comp1rm   Fr   c                 S   s$   ddddg}t |}|d |S )Nr'   r&   r4   rp   r   )r6   r7   r]   r   r   r   r   no_array_comp2  s    

zATestArrayComprehension.test_no_array_comp.<locals>.no_array_comp2Tr   )r   r   r   r   r   r   test_no_array_comp  s    z)TestArrayComprehension.test_no_array_compc                 C   s   dd }|  |d d S )Nc                    s    t  fddt D }|S )Nc                    s$   g | ]}t d d t D qS )c                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     z]TestArrayComprehension.test_nested_array.<locals>.nested_array.<locals>.<listcomp>.<listcomp>rn   r0   r(   r   r   r     s     zRTestArrayComprehension.test_nested_array.<locals>.nested_array.<locals>.<listcomp>rn   r   r   r(   r   nested_array  s    z>TestArrayComprehension.test_nested_array.<locals>.nested_arrayrm   r   r   r   r   r   r   test_nested_array  s    z(TestArrayComprehension.test_nested_arrayc                 C   s   dd }|  |d d S )Nc                 S   s   t dd tdD }|S )Nc                 S   s$   g | ]}t d d tdD qS )c                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zhTestArrayComprehension.test_nested_array_with_const.<locals>.nested_array.<locals>.<listcomp>.<listcomp>r4   rn   r0   r   r   r   r     s     z]TestArrayComprehension.test_nested_array_with_const.<locals>.nested_array.<locals>.<listcomp>rp   rn   r   r   r   r   r     s    zITestArrayComprehension.test_nested_array_with_const.<locals>.nested_arrayr   r   r   r   r   r   test_nested_array_with_const  s    z3TestArrayComprehension.test_nested_array_with_constc                 C   sZ   dd }dddddg}|  || |  |t| |  |t| |  |t| d S )Nc                 S   s   t dd | D }|S )Nc                 S   s   g | ]}|| qS r   r   r   r   r   r   r     s     zXTestArrayComprehension.test_array_comp_with_iter.<locals>.array_comp.<locals>.<listcomp>r5   )rW   r   r   r   r   
array_comp  s    zDTestArrayComprehension.test_array_comp_with_iter.<locals>.array_compr'   r&   r4   rp   r   )r   r6   r7   tupler   List)r   r   r   r   r   r   test_array_comp_with_iter  s    z0TestArrayComprehension.test_array_comp_with_iterc                 C   s   dd }| j |dtjd d S )Nc                 S   s"   t jdd t| D t jd}|S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zYTestArrayComprehension.test_array_comp_with_dtype.<locals>.array_comp.<locals>.<listcomp>)r   )r6   r7   r   	complex64r   r   r   r   r     s    zETestArrayComprehension.test_array_comp_with_dtype.<locals>.array_comprm   r   )r   r6   r   r   r   r   r   r   test_array_comp_with_dtype  s    z1TestArrayComprehension.test_array_comp_with_dtypec                 C   s   dd }|  |d d S )Nc                 S   s   t dd t| D }|S )Nc                 S   s   g | ]}|d  qS )y              ?r   r   r   r   r   r     s     z]TestArrayComprehension.test_array_comp_inferred_dtype.<locals>.array_comp.<locals>.<listcomp>rn   r   r   r   r   r     s    zITestArrayComprehension.test_array_comp_inferred_dtype.<locals>.array_comprm   r   r   r   r   r   test_array_comp_inferred_dtype  s    z5TestArrayComprehension.test_array_comp_inferred_dtypec                 C   s   dd }|  |d d S )Nc                    s    t  fddt D }|S )Nc                    s"   g | ]  fd dt D qS )c                    s   g | ]} | qS r   r   r   r   r   r   r     s     zoTestArrayComprehension.test_array_comp_inferred_dtype_nested.<locals>.array_comp.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r     s     zdTestArrayComprehension.test_array_comp_inferred_dtype_nested.<locals>.array_comp.<locals>.<listcomp>rn   r   r   r(   r   r     s    zPTestArrayComprehension.test_array_comp_inferred_dtype_nested.<locals>.array_comprm   r   r   r   r   r   %test_array_comp_inferred_dtype_nested  s    z<TestArrayComprehension.test_array_comp_inferred_dtype_nestedc                 C   s   dd }|  |d d S )Nc                    s    t  fddt D }|S )Nc                    s"   g | ]  fd dt D qS )c                    s   g | ]} | qS r   r   r   r   r   r   r     s     zsTestArrayComprehension.test_array_comp_inferred_dtype_nested_sum.<locals>.array_comp.<locals>.<listcomp>.<listcomp>r   r   r(   r   r   r     s     zhTestArrayComprehension.test_array_comp_inferred_dtype_nested_sum.<locals>.array_comp.<locals>.<listcomp>rn   r   r   r(   r   r     s    zTTestArrayComprehension.test_array_comp_inferred_dtype_nested_sum.<locals>.array_comprm   r   r   r   r   r   )test_array_comp_inferred_dtype_nested_sum  s    z@TestArrayComprehension.test_array_comp_inferred_dtype_nested_sumc              	   C   s   dd }d}| j |d|tjd | t}tdd|}|dd W 5 Q R X | td	t	j
 t|j | d
tjt|j d S )Nc                 S   s$   t dd t| D }||d< |S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zmTestArrayComprehension.test_array_comp_inferred_dtype_outside_setitem.<locals>.array_comp.<locals>.<listcomp>r   rn   )r   vZarrr   r   r   r     s    zYTestArrayComprehension.test_array_comp_inferred_dtype_outside_setitem.<locals>.array_compg333333?rm   r   Tr$   y        ffffff@z Function({})z/(array({}, 1d, C), Literal[int](0), complex128))r   r6   r   rv   r   r   r   r
   formatoperatorsetitemr   r   r   )r   r   r   r|   r"   r   r   r   .test_array_comp_inferred_dtype_outside_setitem  s    
zETestArrayComprehension.test_array_comp_inferred_dtype_outside_setitemc              	      s   d t dd fdd}t }|  W 5 Q R X |  }t "}ttdd t D  W 5 Q R X |  }| || | 	|d d S )	Nd   Tr$   c                     s0   t dd t D } t j|  t|  d S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zZTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.foo.<locals>.<listcomp>)r6   r7   r   randomshuffleprint)ZnumbersZnelemr   r   foo  s    zFTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.fooc                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zMTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.<listcomp>z\[(\s*\d+)+\])
r   r   getvaluestripr   r6   r7   r   ZassertNotEqualZassertRegexpMatches)r   r   Zgotbufr   Z	expectbufexpectr   r   r   "test_array_comp_shuffle_sideeffect  s    &z9TestArrayComprehension.test_array_comp_shuffle_sideeffectc                 C   s   dd }| j |ddd d S )Nc                 S   s0   g }t dg}t j|d}|| |  |S r<   )r6   r7   r   choicer]   )r-   r   ZmyListrW   r   r   r   ry     s
    z=TestArrayComprehension.test_empty_list_not_removed.<locals>.fr   Tr   r   )r   ry   r   r   r   test_empty_list_not_removed  s    z2TestArrayComprehension.test_empty_list_not_removedc                 C   s   dd }| j |ddd dS )z Test issue 3742 c                 S   s@   dd t dD  t| }t | D ]}t| }|||< q$|S )Nc                 S   s   g | ]}|qS r   r   r   r   r   r   r     s     zOTestArrayComprehension.test_reuse_of_array_var.<locals>.foo.<locals>.<listcomp>r'   )r   r6   emptyzeros)r   r:   r   r   r   r   r      s    


z;TestArrayComprehension.test_reuse_of_array_var.<locals>.foorm   Tr   Nr   )r   r   r   r   r   test_reuse_of_array_var  s    z.TestArrayComprehension.test_reuse_of_array_varN)r   r   r   Z_numba_parallel_test_r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s6   

		


r   __main__)ZunittestZnumba.tests.supportr   rw   r   rM   r6   Znumba.core.compilerr   Znumbar   r   Z
numba.corer   r   Znumba.core.errorsr   r	   Znumba.core.types.functionsr
   r   r   r   r   r   r   r   r   mainr   r   r   r   <module>   s(    T  