U
    9%eE                     @   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 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)numpy_version)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   ]/var/www/html/Darija-Ai-API/env/lib/python3.8/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                   @   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   intp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   5   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list1.<locals>.<listcomp>r)   )r   lenxr   r   r   list13   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   9   s      zLTestListComprehension.test_bulk_use_cases.<locals>.list2.<locals>.<listcomp>r   r.   r   r   r   list27   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   r2   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   F   s     zWTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>.<listcomp>r7   r2   r.   r   r   r   F   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list5.<locals>.<listcomp>r7   r.   r   r.   r   list5D   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   innerJ   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.innerc                    s   g | ]} |qS r   r   r;   r?   r   r   r   L   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list6.<locals>.<listcomp>r   r.   r   r@   r   list6H   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 r6   c                    s   |   S )Nr   r.   )r3   r   r   r?   R   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.innerc                    s   g | ]} |qS r   r   r;   r@   r   r   r   T   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list7.<locals>.<listcomp>r   r.   r   )r?   r3   r   list7N   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;   r   r   r   r   X   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.<listcomp>c                 S   s   | d d S Nr   r)   r   r.   r   r   r   r?   Z   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list8.<locals>.innerr   )r/   r   r?   qr   r   r   list8V   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 rC   r   r;   r   r   r   r   a   s     zLTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.<listcomp>c                    s   | d  d  S rD   r   r.   r   r   r   r?   c   s    zGTestListComprehension.test_bulk_use_cases.<locals>.list9.<locals>.innerr   r/   r?   r   rG   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 rC   r   r;   r   r   r   r   i   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   r2   rG   r   r   r   l   s     z\TestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.inner.<locals>.<listcomp>r   r.   rG   r   r   r?   k   s    zHTestListComprehension.test_bulk_use_cases.<locals>.list10.<locals>.innerr   rH   r   rG   r   list10g   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   r7   r;   r   r   r   r   q   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list11.<locals>.<listcomp>r   r/   r   r   r   r   list11o   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   )r8   float64r;   r   r   r   r   v   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list12.<locals>.<listcomp>r   rK   r   r   r   list12t   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   )numpyrM   r;   r   r   r   r   {   s     zMTestListComprehension.test_bulk_use_cases.<locals>.list13.<locals>.<listcomp>r   rK   r   r   r   list13y   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   floatr;   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list14.<locals>.<listcomp>r   rK   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   rQ   r;   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list15.<locals>.<listcomp>r7   rK   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   rQ   r;   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list16.<locals>.<listcomp>c                 S   s   g | ]}|qS r   r   r;   r   r   r   r      s     r7   )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 r1   )r8   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 rC   r   r2   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list22.<locals>.<listcomp>c                 S   s   g | ]}|d  qS rC   r   r2   r   r   r   r      s     c                    s"   g | ]} D ]}||kr|qqS r   r   )r   r/   r3   rZ   r   r   r      s
        r   )r/   rY   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   r2   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 )r6   rQ   r2   r   r   r   r      s     zMTestListComprehension.test_bulk_use_cases.<locals>.list24.<locals>.<listcomp>r   rh   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>
   r8   r9   r   )r/   Znot_includedr   rn   r   list25   s    z9TestListComprehension.test_bulk_use_cases.<locals>.list25r)   r(   r6      r   l        @       N)r   r    
ValueErrorr8   testingZassert_allclose	ExceptionassertRaisesr   sysmaxsize) r!   r0   r4   r5   r:   r=   rA   rB   rF   rI   rJ   rL   rN   rP   rS   rT   rW   r\   rb   rc   rd   re   rg   ri   rj   rq   fvarrefr$   raisesbitsr   )ra   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)r3   r<   Zinlinedr   r   r   objmode_func   s    zATestListComprehension.test_objmode_inlining.<locals>.objmode_funcT)Zforceobjr)   r(   r6   )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eedk d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d6d7 Z d8S )9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   r8   rv   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>rp   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 r1   r   r   	thresholdr   r   r     s     z\TestArrayComprehension.test_comp_with_array_2.<locals>.comp_with_array_2.<locals>.<listcomp>)r8   Zaranger9   )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>rp   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_   r8   r9   )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   3  s     zmTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>.<listcomp>r   r   r*   r   r   r   3  s     zbTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_array.<locals>.<listcomp>rp   r   r   r*   r   comp_nest_with_array2  s    zNTestArrayComprehension.test_comp_nest_with_array.<locals>.comp_nest_with_arrayr   Tr   r   )r!   r   r   r   r   test_comp_nest_with_array1  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>rp   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_3:  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   E  s     zTestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinline.<locals>.<listcomp>.<listcomp>r   r   r*   r   r   r   E  s     ztTestArrayComprehension.test_comp_nest_with_array_noinline.<locals>.comp_nest_with_array_noinline.<locals>.<listcomp>rp   r   r   r*   r   comp_nest_with_array_noinlineD  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_noinlineC  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  s     zdTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_range.<locals>.<listcomp>rp   r   r   r   r   r   r   comp_with_array_rangeQ  s    zPTestArrayComprehension.test_comp_with_array_range.<locals>.comp_with_array_ranger   ro   r   )r!   r   r   r   r   test_comp_with_array_rangeP  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   Y  s     zvTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_step.<locals>.<listcomp>r(   rp   r   r   r   r   comp_with_array_range_and_stepX  s    zbTestArrayComprehension.test_comp_with_array_range_and_step.<locals>.comp_with_array_range_and_stepr   ro   r   )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   `  s      zpTestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditional.<locals>.<listcomp>rp   r   r   r   r   comp_with_array_conditional_  s    z\TestArrayComprehension.test_comp_with_array_conditional.<locals>.comp_with_array_conditionalro   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   g  s     zTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>.<listcomp>r   r   r*   r   r   r   g  s      zzTestArrayComprehension.test_comp_nest_with_array_conditional.<locals>.comp_nest_with_array_conditional.<locals>.<listcomp>rp   r   r   r*   r    comp_nest_with_array_conditionalf  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_conditionale  s    z<TestArrayComprehension.test_comp_nest_with_array_conditional)r)      zASetting an array element with a sequence is removed in NumPy 1.24c              	   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   q  s     zwTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>.<listcomp>r)   r   r   r   r   r   r   q  s     zlTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependency.<locals>.<listcomp>rp   r   r   r   r   comp_nest_with_dependencyp  s    zXTestArrayComprehension.test_comp_nest_with_dependency.<locals>.comp_nest_with_dependencyr   zarray(undefined,rx   r   r   r   r
   str	exception)r!   r   r~   r   r   r   test_comp_nest_with_dependencyl  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(   r6   rr   r   rk   c                 S   s   g | ]\}}|qS r   r   )r   rY   rZ   r   r   r   r   |  s     zdTestArrayComprehension.test_comp_unsupported_iter.<locals>.comp_unsupported_iter.<locals>.<listcomp>)zipr8   r9   )valr   r   r   comp_unsupported_iterz  s    zPTestArrayComprehension.test_comp_unsupported_iter.<locals>.comp_unsupported_iterz1Unsupported iterator found in array comprehensionr   )r!   r   r~   r   r   r   test_comp_unsupported_itery  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(   r6   rr   r7   r   r   rY   r   r   r   no_array_comp1  s    
zATestArrayComprehension.test_no_array_comp.<locals>.no_array_comp1ro   Fr   c                 S   s$   ddddg}t |}|d |S )Nr)   r(   r6   rr   r   )r8   r9   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>rp   r2   r*   r   r   r     s     zRTestArrayComprehension.test_nested_array.<locals>.nested_array.<locals>.<listcomp>rp   r   r   r*   r   nested_array  s    z>TestArrayComprehension.test_nested_array.<locals>.nested_arrayro   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>r6   rp   r2   r   r   r   r     s     z]TestArrayComprehension.test_nested_array_with_const.<locals>.nested_array.<locals>.<listcomp>rr   rp   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>r7   )rY   r   r   r   r   
array_comp  s    zDTestArrayComprehension.test_array_comp_with_iter.<locals>.array_compr)   r(   r6   rr   r   )r   r8   r9   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   )r8   r9   r   	complex64r   r   r   r   r     s    zETestArrayComprehension.test_array_comp_with_dtype.<locals>.array_compro   r   )r   r8   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>rp   r   r   r   r   r     s    zITestArrayComprehension.test_array_comp_inferred_dtype.<locals>.array_compro   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>rp   r   r   r*   r   r     s    zPTestArrayComprehension.test_array_comp_inferred_dtype_nested.<locals>.array_compro   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>rp   r   r   r*   r   r     s    zTTestArrayComprehension.test_array_comp_inferred_dtype_nested_sum.<locals>.array_compro   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   rp   )r   vZarrr   r   r   r     s    zYTestArrayComprehension.test_array_comp_inferred_dtype_outside_setitem.<locals>.array_compg333333?ro   r   Tr&   y        ffffff@z Function({})z/(array({}, 1d, C), Literal[int](0), complex128))r   r8   r   rx   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>)r8   r9   r   randomshuffleprint)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   r8   r9   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>   )r8   r9   r   choicer_   )r/   r   ZmyListrY   r   r   r   r{     s
    z=TestArrayComprehension.test_empty_list_not_removed.<locals>.fr   Tr   r   )r!   r{   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   r8   emptyZzeros)r   r<   r   r   r   r   r     s    


z;TestArrayComprehension.test_reuse_of_array_var.<locals>.fooro   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   unittestZ
skipUnlessr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s<   

		




r   __main__)r   Znumba.tests.supportr   ry   r   rO   r8   Znumba.core.compilerr   Znumbar   r   Z
numba.corer   r   Znumba.core.errorsr   r	   Znumba.core.types.functionsr
   Znumba.np.numpy_supportr   r   r   r   r   r   r   r   r   mainr   r   r   r   <module>   s*    T  "