B
     \(@                 @   s   d dl mZ d dlm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mZmZ d dlmZmZ ddlmZ d d	lmZ dd
lmZmZ epe Zdd ZG dd deZG dd dejZedkre  dS )    )print_functionN   )TestCase)compile_isolated)typesutilsjitr   )TypingErrorLoweringError)tag)captured_stdout)_windows_py27_32bitc             C   s0   dd t | D }d}x|D ]}||7 }qW |S )Nc             S   s   g | ]}|qS  r   ).0ir   r   =lib/python3.7/site-packages/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               @   s4   e Zd Zeddd Zeddd Zdd ZdS )	TestListComprehension	importantc             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 }||||||||	|
|||||||||||||g}tjd6kr0|| d7d8d9d:d;g}x|D ]x}y&t dd|}| |||| W nJ tk
r   ytj|||| W n t	k
r    Y nX Y nX qDW | 
t}t dd|}|| W d<Q R X tjd=krd>}nd?}tjd6k rX| 
t}t dd|}|| W d<Q R X d@||f }| |t|j 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   )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   r   7   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list1.<locals>.<listcomp>r   )r   len)xr   r   r   list15   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   ;   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list2.<locals>.<listcomp>r   )r(   r   r   r   list29   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   )r   r*   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array)r(   r   r   r   list4A   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   H   s    zWTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>.<listcomp>)r.   r/   )r   r*   )r(   r   r   r   H   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>)r.   r/   )r(   r   )r(   r   list5F   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   innerL   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.innerc                s   g | ]} |qS r   r   )r   r1   )r3   r   r   r   N   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.<listcomp>r   )r(   r   )r3   r   list6J   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 r-   c                s   |   S )Nr   )r(   )r*   r   r   r3   T   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.innerc                s   g | ]} |qS r   r   )r   r1   )r3   r   r   r   V   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.<listcomp>r   )r(   r   )r3   r*   r   list7P   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   )r   r1   r   r   r   r   Z   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.<listcomp>c             S   s   | d d S )Nr   r   r   )r(   r   r   r   r3   \   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.innerr   )r(   r   r3   qr   r   r   list8X   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 )r   r   )r   r1   r   r   r   r   c   s    zLTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.<listcomp>c                s   | d  d  S )Nr   r   r   )r(   )r   r   r   r3   e   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.innerr   )r(   r3   r   )r   r   list9a   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 )r   r   )r   r1   r   r   r   r   k   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   )r   r*   )r   r   r   r   n   s    z\TestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.inner.<locals>.<listcomp>r   )r(   )r   r   r   r3   m   s    zHTestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.innerr   )r(   r3   r   )r   r   list10i   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   )r.   r/   )r   r1   r   r   r   r   s   s    zMTestListComprehension.test_bulk_use_cases.<locals>.list11.<locals>.<listcomp>r   )r(   r   r   r   r   list11q   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   )r.   float64)r   r1   r   r   r   r   x   s    zMTestListComprehension.test_bulk_use_cases.<locals>.list12.<locals>.<listcomp>r   )r(   r   r   r   r   list12v   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   )numpyr;   )r   r1   r   r   r   r   }   s    zMTestListComprehension.test_bulk_use_cases.<locals>.list13.<locals>.<listcomp>r   )r(   r   r   r   r   list13{   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   )float)r   r1   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list14.<locals>.<listcomp>r   )r(   r   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   )r?   )r   r1   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list15.<locals>.<listcomp>)r.   r/   )r(   r   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   )r?   )r   r1   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list16.<locals>.<listcomp>c             S   s   g | ]}|qS r   r   )r   r1   r   r   r   r      s    )r.   r/   )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%   )r.   Zsqrt)r   abc)r(   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 }x| D ]}| k r
| | q
W |S )z3 Test loop list with outer scope var as conditional)append)r(   r1   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   )rK   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list19.<locals>.<listcomp>r   )r(   )rK   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   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   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 )r   r   )r   r*   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list22.<locals>.<listcomp>c             S   s   g | ]}|d  qS )r   r   )r   r*   r   r   r   r      s    c                s"   g | ]} D ]}||kr|qqS r   r   )r   r(   r*   )rF   r   r   r      s    r   )r(   rE   r   )rF   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   )r   r*   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list23.<locals>.<listcomp>r   )rJ   )r(   r1   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 )r-   )r?   )r   r*   r   r   r   r      s    zMTestListComprehension.test_bulk_use_cases.<locals>.list24.<locals>.<listcomp>r   )r(   r1   r   r   r   list24   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list24)r-   r   r   r%   r-      r   Nl        @       z,Cannot unify reflected list(int%d) and int%d)r   r   Z	PYVERSIONrJ   r   
ValueErrorr.   testingZassert_allcloseBaseExceptionassertRaisesr	   sysmaxsizeassertInstr	exception) r   r)   r+   r,   r0   r2   r4   r5   r7   r8   r9   r:   r<   r>   r@   rA   rD   rH   rL   rM   rN   rO   rP   rQ   rR   fvarrefr"   raisesbitsmsgr   )rK   r&   r   test_bulk_use_cases*   sp    	



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)r*   r1   Zinlinedr   r   r   objmode_func   s    zATestListComprehension.test_objmode_inlining.<locals>.objmode_funcT)Zforceobjr   r%   r-   )r   ZassertPreciseEqual)r   rg   r"   tZexpectedgotr   r   r   test_objmode_inlining   s    
z+TestListComprehension.test_objmode_inliningN)__name__
__module____qualname__r   r#   re   rj   r   r   r   r   r      s   	 ?r   c               @   s@  e Zd ZdZdd Zeddd Zeddd Zedd	d
 Zeddd Z	eddd Z
eddd Zeddd Zeddd Zeddd Zeddd Zeddd Zeddd Zeddd Zeddd  Zedd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1S )2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$   Zparallelr   zallocate listr   z@do_schedulingN)getr   r.   rW   Zassert_array_equalr   dtyper\   Zinspect_llvmZ
signaturesZassertNotIn)
r   r    argskwargsro   rp   rq   r"   Zpyresr!   r   r   r   check   s    zTestArrayComprehension.checkr   c             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   r   )mr   r   r     s    z\TestArrayComprehension.test_comp_with_array_1.<locals>.comp_with_array_1.<locals>.<listcomp>)r.   r/   r   )r   r   r   )rw   r   comp_with_array_1  s    zHTestArrayComprehension.test_comp_with_array_1.<locals>.comp_with_array_1r   T)ro   )rv   PARALLEL_SUPPORTED)r   rx   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   r(   )	thresholdr   r   r     s    z\TestArrayComprehension.test_comp_with_array_2.<locals>.comp_with_array_2.<locals>.<listcomp>)r.   Zaranger/   )r   r{   Ar   )r{   r   comp_with_array_2  s    zHTestArrayComprehension.test_comp_with_array_2.<locals>.comp_with_array_2r   r   )rv   )r   r}   r   r   r   test_comp_with_array_2  s    z-TestArrayComprehension.test_comp_with_array_2c             C   s<   dd }dd l m} zd|_| j|ddd W d d|_X d S )Nc                s(   | d  t  fddt| D }|S )Nr%   c                s   g | ]}|  qS r   r   )r   r   )rw   r   r   r   #  s    zjTestArrayComprehension.test_comp_with_array_noinline.<locals>.comp_with_array_noinline.<locals>.<listcomp>)r.   r/   r   )r   r   r   )rw   r   comp_with_array_noinline!  s    zVTestArrayComprehension.test_comp_with_array_noinline.<locals>.comp_with_array_noinliner   Fr   T)rp   )numba.inline_closurecallinline_closurecallenable_inline_arraycallrv   )r   r   icr   r   r   test_comp_with_array_noinline  s    z4TestArrayComprehension.test_comp_with_array_noinlinec             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   0  s    zmTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>.<listcomp>)r   )r   )r   )r   r   r   0  s    zbTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>)r.   r/   r   )r   r   r   )r   r   comp_nest_with_array/  s    zNTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_arrayr   T)ro   )rv   ry   )r   r   r   r   r   test_comp_nest_with_array-  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>)r.   r/   r   )r   r   r   )r   r   comp_nest_with_array_39  s    zRTestArrayComprehension.test_comp_nest_with_array_3.<locals>.comp_nest_with_array_3r   T)ro   )rv   ry   )r   r   r   r   r   test_comp_nest_with_array_37  s    z2TestArrayComprehension.test_comp_nest_with_array_3c             C   s<   dd }dd l m} zd|_| j|ddd W d 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   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>)r.   r/   r   )r   r   r   )r   r   comp_nest_with_array_noinlineC  s    z`TestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinliner   Fr   T)rp   )r   r   r   rv   )r   r   r   r   r   r   "test_comp_nest_with_array_noinlineA  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   r   R  s    zdTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_range.<locals>.<listcomp>)r.   r/   r   )rw   r   r   r   r   r   comp_with_array_rangeQ  s    zPTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_ranger   
   )rv   )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   r   Z  s    zvTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_step.<locals>.<listcomp>r%   )r.   r/   r   )rw   r   r   r   r   r   comp_with_array_range_and_stepY  s    zbTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_stepr   r   )rv   )r   r   r   r   r   #test_comp_with_array_range_and_stepW  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   r   b  s    zpTestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditional.<locals>.<listcomp>)r.   r/   r   )r   r   r   r   r   comp_with_array_conditionala  s    z\TestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditionalr   T)rp   )rv   )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   r   j  s    zTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>.<listcomp>)r   )r   )r   )r   r   r   j  s    zzTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>)r.   r/   r   )r   r   r   )r   r    comp_nest_with_array_conditionali  s    zfTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditionalr   T)rp   )rv   )r   r   r   r   r   %test_comp_nest_with_array_conditionalg  s    z<TestArrayComprehension.test_comp_nest_with_array_conditionalc          	   C   sH   dd }|  t}| |d W d Q R X | dtj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   r   r  s    zwTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>.<listcomp>r   )r   )r   r   )r   r   r   r  s    zlTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>)r.   r/   r   )r   r   r   r   r   comp_nest_with_dependencyq  s    zXTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependencyr   zInvalid use of Function({}))	rY   r	   rv   r\   formatoperatorsetitemr]   r^   )r   r   rb   r   r   r   test_comp_nest_with_dependencyo  s    
z5TestArrayComprehension.test_comp_nest_with_dependencyc             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%   r-   rS   )r.   r/   )r   r   rE   r   r   r   no_array_comp1~  s    
zATestArrayComprehension.test_no_array_comp.<locals>.no_array_comp1r   F)rp   c             S   s$   ddddg}t |}|d |S )Nr   r%   r-   rS   r   )r.   r/   rJ   )r   r   rE   r   r   r   no_array_comp2  s    

zATestArrayComprehension.test_no_array_comp.<locals>.no_array_comp2T)rv   )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   r     s    z]TestArrayComprehension.test_nested_array.<locals>.nested_array.<locals>.<listcomp>.<listcomp>)r.   r/   r   )r   r*   )r   r   r   r     s    zRTestArrayComprehension.test_nested_array.<locals>.nested_array.<locals>.<listcomp>)r.   r/   r   )r   r   r   )r   r   nested_array  s    z>TestArrayComprehension.test_nested_array.<locals>.nested_arrayr   )rv   )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   r     s    zhTestArrayComprehension.test_nested_array_with_const.<locals>.nested_array.<locals>.<listcomp>.<listcomp>r-   )r.   r/   r   )r   r*   r   r   r   r     s    z]TestArrayComprehension.test_nested_array_with_const.<locals>.nested_array.<locals>.<listcomp>rS   )r.   r/   r   )r   r   r   r   r   r     s    zITestArrayComprehension.test_nested_array_with_const.<locals>.nested_arrayr   )rv   )r   r   r   r   r   test_nested_array_with_const  s    z3TestArrayComprehension.test_nested_array_with_constc             C   s8   dd }dddddg}|  || |  |t| 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    zXTestArrayComprehension.test_array_comp_with_iter.<locals>.array_comp.<locals>.<listcomp>)r.   r/   )rE   r   r   r   r   
array_comp  s    zDTestArrayComprehension.test_array_comp_with_iter.<locals>.array_compr   r%   r-   rS   r   )rv   r.   r/   )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   r     s    zYTestArrayComprehension.test_array_comp_with_dtype.<locals>.array_comp.<locals>.<listcomp>)rs   )r.   r/   r   	complex64)r   r   r   r   r   r     s    zETestArrayComprehension.test_array_comp_with_dtype.<locals>.array_compr   )rq   )rv   r.   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   r     s    z]TestArrayComprehension.test_array_comp_inferred_dtype.<locals>.array_comp.<locals>.<listcomp>)r.   r/   r   )r   r   r   r   r   r     s    zITestArrayComprehension.test_array_comp_inferred_dtype.<locals>.array_compr   )rv   )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   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>)r.   r/   r   )r   r   r   )r   r   r     s    zPTestArrayComprehension.test_array_comp_inferred_dtype_nested.<locals>.array_compr   )rv   )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   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>)r.   r/   r   )r   r   r   )r   r   r     s    zTTestArrayComprehension.test_array_comp_inferred_dtype_nested_sum.<locals>.array_compr   )rv   )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 d Q R X | 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   r     s    zmTestArrayComprehension.test_array_comp_inferred_dtype_outside_setitem.<locals>.array_comp.<locals>.<listcomp>r   )r.   r/   r   )r   vZarrr   r   r   r     s    zYTestArrayComprehension.test_array_comp_inferred_dtype_outside_setitem.<locals>.array_compg333333?r   )rq   T)r$   y        ffffff@zInvalid use of Function({})z/(array({}, 1d, C), Literal[int](0), complex128))rv   r.   r   rY   r	   r   r\   r   r   r   r]   r^   r   )r   r   r   rb   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 d Q R X |  }t "}ttdd t D  W d Q R X |  }| || | 	|d d S )	Nd   T)r$   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   r     s    zZTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.foo.<locals>.<listcomp>)r.   r/   r   randomZshuffleprint)Znumbers)nelemr   r   foo  s    zFTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.fooc             S   s   g | ]}|qS r   r   )r   r   r   r   r   r     s    zMTestArrayComprehension.test_array_comp_shuffle_sideeffect.<locals>.<listcomp>z\[(\s*\d+)+\])
r   r   getvaluestripr   r.   r/   r   ZassertNotEqualZassertRegexpMatches)r   r   Zgotbufri   Z	expectbufZ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 )Nr   )r.   r/   r   ZchoicerJ   )r(   rh   ZmyListrE   r   r   r   r_     s
    z=TestArrayComprehension.test_empty_list_not_removed.<locals>.fr   T)rp   )rv   )r   r_   r   r   r   test_empty_list_not_removed  s    z2TestArrayComprehension.test_empty_list_not_removedN)rk   rl   rm   Z_numba_parallel_test_rv   r   rz   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   rn      s0   

rn   __main__) Z
__future__r   Znumba.unittest_supportZunittest_supportZunittestZsupportr   rZ   r   r=   r.   Znumba.compilerr   Znumbar   r   r   Znumba.errorsr	   r
   r   Znumba.tests.supportr   Ztest_parforsr   r   ry   r   r   rn   rk   mainr   r   r   r   <module>   s*   
 W  