o
    iY                     @   s  d dl mZ d dlZd dlmZmZmZmZ d dl	m
Z
mZmZmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZmZmZmZ d d	lmZ d d
lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 dZ1G dd deeZ2edddG dd deZ3G dd deeZ4G dd deeZ5G dd deeZ6G dd deZ7dd Z8G dd  d eZ9G d!d" d"eZ:e;d#kre<  dS dS )$    )
namedtupleN)TestCaseMemoryLeakMixinskip_parfors_unsupportedcaptured_stdout)njittypedliteral_unrollprange)typeserrorsir)unittest)overload)PassManagerregister_passFunctionPassAnalysisPassCompilerBase)	FixupArgsTranslateByteCodeIRProcessingInlineClosureLikesSimplifyCFGIterLoopCanonicalizationLiteralUnroll
PreserveIR)NopythonTypeInferenceIRLegalizationNoPythonBackendPartialTypeInferenceNativeLowering)compute_cfg_from_blocksflatten_labels)_header_lead
      c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestLiteralTupleInterpretationc                 C   sP   |j |jd  }|jj| }| t|tj |D ]}| t|tjd qd S )Nr   non literal)		overloads
signaturesfndesctypemap
assertTrue
isinstancer   TupleLiteral)selffuncvarcrestysubty r9   c/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/numba/tests/test_mixed_tuple_unroller.pycheck   s   z$TestLiteralTupleInterpretation.checkc                 C   .   t dd }| | |  | |d d S )Nc                  S      d} | d S )N         r?   r9   xr9   r9   r:   foo$      zDTestLiteralTupleInterpretation.test_homogeneous_literal.<locals>.foorC   r   assertEqualpy_funcr;   r3   rD   r9   r9   r:   test_homogeneous_literal#      
z7TestLiteralTupleInterpretation.test_homogeneous_literalc                 C   r<   )Nc                  S   r=   )N)r?   r@   rA   arA   r9   rB   r9   r9   r:   rD   -   rE   zFTestLiteralTupleInterpretation.test_heterogeneous_literal.<locals>.foorC   rF   rI   r9   r9   r:   test_heterogeneous_literal,   rK   z9TestLiteralTupleInterpretation.test_heterogeneous_literalc                 C   sj   t dd }| | |  | t}| |d W d    n1 s%w   Y  | dt|j d S )Nc                  S   r=   )N)r?   r@   rA   rL                 ?   r9   rB   r9   r9   r:   rD   6   rE   z<TestLiteralTupleInterpretation.test_non_literal.<locals>.foorC   r*   )	r   rG   rH   assertRaisesAssertionErrorr;   assertInstr	exception)r3   rD   er9   r9   r:   test_non_literal5   s   
z/TestLiteralTupleInterpretation.test_non_literalN)__name__
__module____qualname__r;   rJ   rM   rV   r9   r9   r9   r:   r)      s
    		r)   Fmutates_CFGanalysis_onlyc                   @   s    e Zd ZdZdd Zdd ZdS )ResetTypeInforeset_the_type_informationc                 C      t |  d S Nr   __init__r3   r9   r9   r:   rb   F      zResetTypeInfo.__init__c                 C   s   d |_ d |_d |_dS )NT)r.   return_type	calltypes)r3   stater9   r9   r:   run_passI   s   zResetTypeInfo.run_passN)rW   rX   rY   _namerb   rh   r9   r9   r9   r:   r]   B   s    r]   c                   @   st   e Zd ZdddZedZedZeddZdd Zdd Ze	
d	d
d Zdd Ze	
d	dd Zdd ZdS )TestLoopCanonicalisationFc                    s   G  fdddt }|S )Nc                       s   e Zd Z fddZdS )z:TestLoopCanonicalisation.get_pipeline.<locals>.NewCompilerc                    s   t d}|td |td |td r|td  r&|td |td r4|td |t	d	 |t
d
 |td |td |td |  |gS )Ncustom_pipelineanalyzing bytecodeprocessing IRz(inline calls to locally defined closureszdo partial typingzCanonicalise loopszSimplify the CFGzresets the type info statenopython frontendzensure IR is legalzsave IR for later inspectionnative loweringnopython mode backend)r   add_passr   r   r   r!   r   r   r]   r   r   r   r"   r    finalize)r3   pmuse_canonicaliseruse_partial_typingr9   r:   define_pipelinesU   s(   zKTestLoopCanonicalisation.get_pipeline.<locals>.NewCompiler.define_pipelinesN)rW   rX   rY   rw   r9   rt   r9   r:   NewCompilerS   s    rx   r   )ru   rv   rx   r9   rt   r:   get_pipelineR   s   $z%TestLoopCanonicalisation.get_pipelineTc                        fdd}| j \}}| j\}} fdd}|||  t|jd t|j dd }||d} t|d	 ||d}	 t|	d	 ||d
}
 t|
d	  |d jj|
d jj |j|	d  jd } t	|t
j dS )- This heavily checks a simple loop transform c                    P   t | ddd }d} |||| |j|jd  }|jd }||jfS )Npipeline_classc                 S   s   d}| D ]}||7 }q|S Nr   r9   )tupaccir9   r9   r:   rD         
zQTestLoopCanonicalisation.test_simple_loop_in_depth.<locals>.get_info.<locals>.foor>   r   preserved_irr   rG   rH   r+   r,   metadatar-   pipelinerD   rC   r6   func_irrc   r9   r:   get_info   s   


zDTestLoopCanonicalisation.test_simple_loop_in_depth.<locals>.get_infoc                    ,   t t| j}t t|j} || d S r`   r#   r$   blocksrG   rL   ba_cfgb_cfgrc   r9   r:   compare_cfg      zGTestLoopCanonicalisation.test_simple_loop_in_depth.<locals>.compare_cfgrA   c                        fdd| j  D S )Nc                    &   g | ]}t |tjr|j kr|qS r9   r0   r   Exprop.0rC   r   r9   r:   
<listcomp>       

zYTestLoopCanonicalisation.test_simple_loop_in_depth.<locals>.find_getX.<locals>.<listcomp>rf   keysfdr   r9   r   r:   	find_getX      zETestLoopCanonicalisation.test_simple_loop_in_depth.<locals>.find_getXgetiterr?   getitemr   NLoopIgnoringCompilerLoopCanonicalisingCompilerrG   lenrf   valuenameargsr/   r0   r   	RangeTyper3   r   ignore_loops_irignore_loops_fndesccanonicalise_loops_ircanonicalise_loops_fndescr   r   il_getiterscl_getiterscl_getitems
range_instr9   rc   r:   test_simple_loop_in_depth~   s(   



z2TestLoopCanonicalisation.test_simple_loop_in_depthc                    rz   )z This checks the transform, when there's no typemap, will happily
        transform a loop on something that's not tuple-like
        c                    sH   t | ddd } | |  |j|jd  }|jd }||jfS )Nr}   c                  S      d} dD ]}| |7 } q| S Nr   r>   r9   r   r   r9   r9   r:   rD      r   zLTestLoopCanonicalisation.test_transform_scope.<locals>.get_info.<locals>.foor   r   r   )r   rD   r6   r   rc   r9   r:   r      s   


z?TestLoopCanonicalisation.test_transform_scope.<locals>.get_infoc                    r   r`   r   r   rc   r9   r:   r      r   zBTestLoopCanonicalisation.test_transform_scope.<locals>.compare_cfgrA   c                    r   )Nc                    r   r9   r   r   r   r9   r:   r      r   zTTestLoopCanonicalisation.test_transform_scope.<locals>.find_getX.<locals>.<listcomp>r   r   r9   r   r:   r      r   z@TestLoopCanonicalisation.test_transform_scope.<locals>.find_getXr   r?   r   r   Nr   r   r9   rc   r:   test_transform_scope   s(   



z-TestLoopCanonicalisation.test_transform_scopez-Waiting for pass to be enabled for all tuplesc                        fdd}| j \}}| j\}} fdd}|||  t|jd t|j dd }||d} t|d ||d}	 t|	d ||d	}
 t|
d
  |d
 jj|
d jj |	D ]}|j| jd } t	|t
j qhdS )zT This heavily checks a typed transformation only impacts tuple
        induced loopsc                    r|   )Nr}   c                 S   s6   d}t dD ]}| D ]}t dD ]}|d7 }qq
q|S Nr   rO   rA   r?   ranger   r   r   yjr9   r9   r:   rD      s   
zYTestLoopCanonicalisation.test_influence_of_typed_transform.<locals>.get_info.<locals>.foor>   r   r   r   r   rc   r9   r:   r         


zLTestLoopCanonicalisation.test_influence_of_typed_transform.<locals>.get_infoc                    r   r`   r   r   rc   r9   r:   r     r   zOTestLoopCanonicalisation.test_influence_of_typed_transform.<locals>.compare_cfgrA   c                    r   )Nc                    r   r9   r   r   r   r9   r:   r     r   zaTestLoopCanonicalisation.test_influence_of_typed_transform.<locals>.find_getX.<locals>.<listcomp>r   r   r9   r   r:   r     r   zMTestLoopCanonicalisation.test_influence_of_typed_transform.<locals>.find_getXr   r   r?   r   Nr   TypedLoopCanonicalisingCompilerrG   r   rf   r   r   r   r/   r0   r   r   r3   r   r   r   r   r   r   r   r   r   r   rC   r   r9   rc   r:   !test_influence_of_typed_transform   s,   



z:TestLoopCanonicalisation.test_influence_of_typed_transformc                    r   )za This heavily checks a typed transformation only impacts loops with
        literal_unroll markerc                    r|   )Nr}   c                 S   s:   d}t dD ]}t| D ]}t dD ]}|d7 }qqq|S r   )r   r	   r   r9   r9   r:   rD   6  s   
zhTestLoopCanonicalisation.test_influence_of_typed_transform_literal_unroll.<locals>.get_info.<locals>.foor>   r   r   r   r   rc   r9   r:   r   5  r   z[TestLoopCanonicalisation.test_influence_of_typed_transform_literal_unroll.<locals>.get_infoc                    r   r`   r   r   rc   r9   r:   r   K  r   z^TestLoopCanonicalisation.test_influence_of_typed_transform_literal_unroll.<locals>.compare_cfgrA   c                    r   )Nc                    r   r9   r   r   r   r9   r:   r   Z  r   zpTestLoopCanonicalisation.test_influence_of_typed_transform_literal_unroll.<locals>.find_getX.<locals>.<listcomp>r   r   r9   r   r:   r   Y  r   z\TestLoopCanonicalisation.test_influence_of_typed_transform_literal_unroll.<locals>.find_getXr   r   r?   r   Nr   r   r9   rc   r:   0test_influence_of_typed_transform_literal_unroll1  s,   



zITestLoopCanonicalisation.test_influence_of_typed_transform_literal_unrollc                    ^    fdd}| j \}}| j\}} fdd}|||  t|jd t|j dS )r{   c                    r|   )Nr}   c                 S   s^   d}| D ]}||7 }| d D ]}|d| 7 }|dkr nq|d8 }q| D ]}||d 8 }q$|S )Nr   )rO         r?   r   r@   r9   )r   r   r   r   r9   r9   r:   rD   t  s   zJTestLoopCanonicalisation.test_lots_of_loops.<locals>.get_info.<locals>.foor>   r   r   r   r   rc   r9   r:   r   s  s   


z=TestLoopCanonicalisation.test_lots_of_loops.<locals>.get_infoc                    r   r`   r   r   rc   r9   r:   r     r   z@TestLoopCanonicalisation.test_lots_of_loops.<locals>.compare_cfg	   Nr   r   rG   r   rf   r3   r   r   r   r   r   r   r9   rc   r:   test_lots_of_loopso  s   
z+TestLoopCanonicalisation.test_lots_of_loopsc                    r   )z( Checks a loop appearing from a closure c                    r|   )Nr}   c                 S   s.   dd }d}| D ]}||7 }|||7 }q|S )Nc                 S   s   d}t | D ]}|d7 }q|S Nr   r?   r   )nr   r   r9   r9   r:   bar     
zWTestLoopCanonicalisation.test_inlined_loops.<locals>.get_info.<locals>.foo.<locals>.barr   r9   )r   r   r   r   r9   r9   r:   rD     s   zJTestLoopCanonicalisation.test_inlined_loops.<locals>.get_info.<locals>.foor>   r   r   r   r   rc   r9   r:   r     s   


z=TestLoopCanonicalisation.test_inlined_loops.<locals>.get_infoc                    r   r`   r   r   rc   r9   r:   r     r   z@TestLoopCanonicalisation.test_inlined_loops.<locals>.compare_cfgr   Nr   r   r9   rc   r:   test_inlined_loops  s   
z+TestLoopCanonicalisation.test_inlined_loopsN)F)rW   rX   rY   ry   r   r   r   r   r   r   skipr   r   r   r   r9   r9   r9   r:   rj   P   s    
(
::
>>
.rj   c                   @   s:  e Zd Zdd Zdd Zdd Zdd Z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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d6d7 Ze d8d9 Z!e d:d; Z"e d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(dHS )ITestMixedTupleUnrollc                 C   2   t dd }d}|}| |d||d| d S )Nc                 S   sV   dddd|d| f}d}t tt|D ]}||| 7 }|jdk r&|d8 }q |S |S 	N   ffffff)@              @rO   r@   r      r?   r   r   r	   real)idxzrL   r   r   r9   r9   r:   rD     s   

z)TestMixedTupleUnroll.test_01.<locals>.foor   r@   r   rG   rH   r3   rD   fkr9   r9   r:   test_01  s
   
zTestMixedTupleUnroll.test_01c                 C   r   )Nc                 S   sJ   dddd|d| f}d}t |D ]}||7 }|jdk r |d8 }q |S |S r   r	   r   )r   r   rC   r   rL   r9   r9   r:   rD     s   

z)TestMixedTupleUnroll.test_02.<locals>.foor   r@   r   r   r9   r9   r:   test_02  s
   
zTestMixedTupleUnroll.test_02c                 C   r   )Nc                 S   sr   dddd|d| f}d|d| f}d}t |D ]}||7 }|jdk r'|d	8 }qt |D ]}||d
u 7 }q+ |S |S )Nr   r   r   rO   r@   rD   r   r   r?   Fr   )r   r   rC   r   r   rL   tr9   r9   r:   rD     s   

z)TestMixedTupleUnroll.test_03.<locals>.foor   r@   r   r   r9   r9   r:   test_03  s
   
zTestMixedTupleUnroll.test_03c                 C   sR   t dd }d}t|ft||ft|||ff}| |||| d S )Nc                 S   s"   d}t | D ]}|| 7 }q|S r   r	   sumr   r   rL   r9   r9   r:   rD        z)TestMixedTupleUnroll.test_04.<locals>.foor'   r   nponesrG   rH   r3   rD   r   r   r9   r9   r:   test_04  s
   
(zTestMixedTupleUnroll.test_04c                 C   s|   t dd }d}d}t|ft||ft|||ft||||ft|||||ff}| |||||| d S )Nc                 S   s   d}t | D ]F}|dkr||d  7 }q|dkr"||d  7 }q|dkr/||d  7 }q|dkr<||d  7 }q|d	krI||d
  7 }qtd|S )Nr   rL   r   r?   cr@   r   rA   r   rO   Unreachable)r	   r   RuntimeErrortup1tup2r   rL   r9   r9   r:   rD     s   z)TestMixedTupleUnroll.test_05.<locals>.foor'   )rL   r   r   r   r   r   )r3   rD   r   r   r   r9   r9   r:   test_05  s   
$"zTestMixedTupleUnroll.test_05zneeds more clever branch prunec                 C   s*   t dd }d}| |||| d S )Nc                 S   s@   d}t jtj}t| D ]}|dkr|| q||7 }q|S )Nr   rL   )r   List
empty_listr   unicode_typer	   append)r   r   str_bufrL   r9   r9   r:   rD   7  s   
z)TestMixedTupleUnroll.test_06.<locals>.foo)rL   r   r   )r3   rD   r   r9   r9   r:   test_063  s   

zTestMixedTupleUnroll.test_06c                 C   sP   t dd }d}t|ft||fdddh df}| |||| d S )Nc                 S   s"   d}t | D ]}|t|7 }q|S r   r	   r   r   r9   r9   r:   rD   G  r   z)TestMixedTupleUnroll.test_07.<locals>.foor'   
ABCDEFGHJIr>   r?   rD   r@   r      rA   rO   r   r      r   r   r9   r9   r:   test_07E  s   
zTestMixedTupleUnroll.test_07c                 C   sL   t dd }dd }d}|d|d|df}| |||||| d S )	Nc                 S   s\   d}t | D ]%}|dkr||d  7 }q|dkr ||d  7 }q|dkr+||d  7 }q|S )Nr   rL   r   r?   r   r@   r	   r   r9   r9   r:   rD   V  s   z)TestMixedTupleUnroll.test_08.<locals>.fooc                    s    fdd}t |S )Nc                      s    S r`   r9   r9   rB   r9   r:   implc     z7TestMixedTupleUnroll.test_08.<locals>.gen.<locals>.implr   )rC   r  r9   rB   r:   genb  s   z)TestMixedTupleUnroll.test_08.<locals>.gen)rL   r   r   r   r   )r   r?   r@   rA   r   )r3   rD   r
  r   r   r9   r9   r:   test_08S  s   
zTestMixedTupleUnroll.test_08c                 C   s   t dd }t dd }t dd }t dd }d	}d
}| tj}||| W d    n1 s2w   Y  | tt|j d S )Nc                 S   sf   d}d}t | D ]&}|dkr||| 7 }n|dkr ||| 7 }n
|dkr*||| 7 }|d7 }q||fS )Nr   rL   r   r   r?   r  )r   r   r   r   rL   r9   r9   r:   rD   n  s   
z)TestMixedTupleUnroll.test_09.<locals>.fooc                   S      dS Nr?   r9   r9   r9   r9   r:   func1|     z+TestMixedTupleUnroll.test_09.<locals>.func1c                   S   r  Nr@   r9   r9   r9   r9   r:   func2  r  z+TestMixedTupleUnroll.test_09.<locals>.func2c                   S   r  NrA   r9   r9   r9   r9   r:   func3  r  z+TestMixedTupleUnroll.test_09.<locals>.func3rL   r   r   )rN   r?   r@   r   rP   r   TypingErrorrR   r%   rS   rT   )r3   rD   r  r  r  r   r   raisesr9   r9   r:   test_09k  s   



zTestMixedTupleUnroll.test_09c                    B   dd  t  dddd }t fdd}| | |  d S )	Nc                 S   8   | dkrdS | dkrdS | dkrdS | dkrd|  S d S 	Nappler?   oranger@   bananarA      +# \r9   r   r9   r9   r:   dt     z(TestMixedTupleUnroll.test_10.<locals>.dtalwaysinlinec                       t | tjr'| j  dkrdd }|S  dkrdd }|S  dkr%dd }|S t | tjr<| j  dkr> fd	d}|S d S d S )
Nr  c                 S   r  r  r9   lir9   r9   r:   r    r  z9TestMixedTupleUnroll.test_10.<locals>.ol_dt.<locals>.implr  c                 S   r  r  r9   r(  r9   r9   r:   r    r  r  c                 S   r  r  r9   r(  r9   r9   r:   r    r  r  c                       d  S Nr   r9   r(  r!  r9   r:   r       r0   r   StringLiteralliteral_valueIntegerLiteralr)  r  r9   r!  r:   ol_dt  $   z+TestMixedTupleUnroll.test_10.<locals>.ol_dtc                     s"   d} t dD ]}|  |7 } q| S Nr   )r  r  r  r  r  r   r   r"  r9   r:   rD     r   z)TestMixedTupleUnroll.test_10.<locals>.foor   r   rG   rH   r3   r2  rD   r9   r6  r:   test_10     


zTestMixedTupleUnroll.test_10c                 C   "   t dd }| | |  d S )Nc                  S   sd   g } d}t tt|D ]#}|| }|dkr| d q|dkr&| | q|dkr/| d q| S N)r  r  r  r  0r  r  z2.0r   r   r	   r   rC   r   r   r   r9   r9   r:   rD     s   
z)TestMixedTupleUnroll.test_11.<locals>.foor   rI   r9   r9   r:   test_11     
zTestMixedTupleUnroll.test_11c                 C   r;  )Nc                  S   sh   t  } d}ttt|D ]#}|| }|dkr| d q|dkr(| | q|dkr1| d q| S r<  )r   r   r   r   r	   r   r?  r9   r9   r:   rD     s   
z*TestMixedTupleUnroll.test_11a.<locals>.foor   rI   r9   r9   r:   test_11a  rA  zTestMixedTupleUnroll.test_11ac                 C   r   )Nc                 S   sp   dddd|d| f}d}t |D ]}||7 }|jdk r |d8 }qt |D ]}||7 }q$ |d d	k r6|d7 }|S 
Nr   r   r   rO   r@   r   r   r?      r   r   r   rL   r   r   rC   r9   r9   r:   rD     s   


z)TestMixedTupleUnroll.test_12.<locals>.foor   r@   r   r   r9   r9   r:   test_12  
   
zTestMixedTupleUnroll.test_12c                 C   `   t dd }d}|}| tj}|d| W d    n1 s w   Y  | dt|j d S )Nc                 S   s   dddd|d| f}d}t |D ]1}||7 }|jdk r |d8 }nt |D ]}t |D ]}||7 }q*||7 }q$t |D ]}||7 }q:qt |D ]}||7 }qF|d d	k rW|d7 }|S rC  r   )r   r   rL   r   r   rC   r   r9   r9   r:   rD     s$   





z)TestMixedTupleUnroll.test_13.<locals>.foor   r@   (Nesting of literal_unroll is unsupportedr   rP   r   UnsupportedErrorrR   rS   rT   r3   rD   r   r   r  r9   r9   r:   test_13  s   
zTestMixedTupleUnroll.test_13c                 C   r;  )Nc                  S   s"   d} d}t | D ]}||7 }q|S Nr?   r@   rA   rO   r   r  rC   r   rL   r9   r9   r:   rD     s
   
z)TestMixedTupleUnroll.test_14.<locals>.foor   rI   r9   r9   r:   test_14  s   
zTestMixedTupleUnroll.test_14c                 C   s   t dd }d}t|ft||fdddh df}| tj}|| W d    n1 s0w   Y  | dt|j d S )	Nc                 S   s"   d}t | D ]}|t|7 }q|S r   r   rP  r9   r9   r:   rD   '  r   z)TestMixedTupleUnroll.test_15.<locals>.foor   r  r>   r  r  Cannot unify)	r   r   r   rP   r   r  rR   rS   rT   )r3   rD   r   r   r  r9   r9   r:   test_15$  s   

zTestMixedTupleUnroll.test_15c                    r  )	Nc                 S   s4   | dkrdS | dkrdS | dkrdS | dkrdS d S )	N  rL     r     r     dr9   r!  r9   r9   r:   r"  :  s   z(TestMixedTupleUnroll.test_16.<locals>.dtr$  r%  c                 S   sf   t | tjr1| j}|dkrdd }|S |dkrdd }|S |dkr'dd }|S |dkr/d	d }|S d S )
NrT  c                 S   r  NrL   r9   r(  r9   r9   r:   r  I  r  z9TestMixedTupleUnroll.test_16.<locals>.ol_dt.<locals>.implrU  c                 S   r  Nr   r9   r(  r9   r9   r:   r  L  r  rV  c                 S   r  Nr   r9   r(  r9   r9   r:   r  O  r  rW  c                 S   r  NrX  r9   r(  r9   r9   r:   r  R  r  )r0   r   r0  r/  r)  r   r  r9   r9   r:   r2  D  s   z+TestMixedTupleUnroll.test_16.<locals>.ol_dtc                     s.   d} d}t | d d D ]}| |7 }q|S )NrT  rU  rV  rW   r@   r  rP  r6  r9   r:   rD   V  
   z)TestMixedTupleUnroll.test_16.<locals>.foor7  r8  r9   r6  r:   test_167  s   


zTestMixedTupleUnroll.test_16c                    r  )	Nc                 S   s@   | dkrdS | dkrdS | dkrdS | dkrdS | d	krd
S d S )NrT  rL   rU  r   rV  r   rW  rX  r   EFFr9   r!  r9   r9   r:   r"  c  s   z(TestMixedTupleUnroll.test_17.<locals>.dtr$  r%  c                 S   s   t | tjr1| j}|dkrdd }|S |dkrdd }|S |dkr'dd }|S |dkr/d	d }|S t | tjrD| j}|d
krFdd }|S d S d S )NrT  c                 S   r  rY  r9   r(  r9   r9   r:   r  t  r  z9TestMixedTupleUnroll.test_17.<locals>.ol_dt.<locals>.implrU  c                 S   r  rZ  r9   r(  r9   r9   r:   r  w  r  rV  c                 S   r  r[  r9   r(  r9   r9   r:   r  z  r  rW  c                 S   r  r\  r9   r(  r9   r9   r:   r  }  r  r   c                 S   r  )Nrb  r9   r(  r9   r9   r:   r    r  )r0   r   r0  r/  r.  r]  r9   r9   r:   r2  o  s*   z+TestMixedTupleUnroll.test_17.<locals>.ol_dtc                     s.   d} d}t | dd  D ]}| |7 }q|S )N)rT  rU  rV  r   r_  r?   r  rP  r6  r9   r:   rD     r`  z)TestMixedTupleUnroll.test_17.<locals>.foor7  r8  r9   r6  r:   test_17`  s   

zTestMixedTupleUnroll.test_17c                 C   r;  )Nc                  S   s:   d} d}t | d d d D ]}|d7 }|dk r |S q|S )N)rT  rU  rV  rW  i  ip  r   r?   rV  r  )rC   countrL   r9   r9   r:   rD     s   z)TestMixedTupleUnroll.test_18.<locals>.foor   rI   r9   r9   r:   test_18     
	zTestMixedTupleUnroll.test_18c                 C   r;  )Nc                  S   s`   d} g d}ddg}||f}t d}t jdt jd}||||f}t|D ]}| t|7 } q%| S )Nr   rO  r'      r   dtyper   aranger   
complex128r	   r   r   l1l2r   a1a2r   r9   r9   r:   rD     s   
z)TestMixedTupleUnroll.test_19.<locals>.foor   rI   r9   r9   r:   test_19  s   
zTestMixedTupleUnroll.test_19c                 C   r;  )Nc                  S   sF   g } t d}t jdt jd}||f}t|D ]	}| |  q| S )Nrh  r   ri  )r   rl  r   rm  r	   r   r   )lrq  rr  r   r   r9   r9   r:   rD     s   
z)TestMixedTupleUnroll.test_20.<locals>.foor   rI   r9   r9   r:   test_20  s   
	zTestMixedTupleUnroll.test_20c                 C   .   t dd }d}|}| |||| d S )Nc                    s0   d  fdd}d}dD ]	}|| | 7 }q|S )NrD  gfffff7@y              @   c                        d} t  D ]}| |7 } q| S r   r  r   r   r   r9   r:   r     r   z6TestMixedTupleUnroll.test_21.<locals>.foo.<locals>.barr   rO  r9   r   r   	outer_accrC   r9   r{  r:   rD     s   z)TestMixedTupleUnroll.test_21.<locals>.foor   r   r   r9   r9   r:   test_21  s
   
zTestMixedTupleUnroll.test_21c                 C   ^   t dd }d}|}| tj}|| W d    n1 sw   Y  | dt|j d S )Nc                    sF   dddd| d|  df}d  fdd	}d
}t |D ]}|| 7 }q|S )Nr   r   r   rO   r@   rL   rw  c                     ry  r   r  rz  r{  r9   r:   r     r   z6TestMixedTupleUnroll.test_22.<locals>.foo.<locals>.barr   r  )r   rL   r   r   rC   r9   r{  r:   rD     s   z)TestMixedTupleUnroll.test_22.<locals>.foor   rI  rJ  rL  r9   r9   r:   test_22  s   

zTestMixedTupleUnroll.test_22c                 C   r  )Nc                    s4   d  fdd}d}t  D ]	}|| | 7 }q|S )Nrw  c                     ry  r   r  rz  r{  r9   r:   r     r   z6TestMixedTupleUnroll.test_23.<locals>.foo.<locals>.barr   r  r|  r9   r{  r:   rD     s   z)TestMixedTupleUnroll.test_23.<locals>.foor   rI  rJ  rL  r9   r9   r:   test_23  s   

zTestMixedTupleUnroll.test_23c                 C   sX   t dd }| tj}|  W d    n1 sw   Y  d}| |t|j d S )Nc                  S   s   t dD ]} t|  qd S )NABCDEr	   printrB   r9   r9   r:   rD      s   
z)TestMixedTupleUnroll.test_24.<locals>.fooz7argument should be a tuple or a list of constant valuesrJ  )r3   rD   r  msgr9   r9   r:   test_24  s   
zTestMixedTupleUnroll.test_24c                 C   r;  )Nc                  S   s<   t ddddgdf} | }|}g }|D ]	}|t| q|S )Nr>   )               @r   r?   r@   xyz)r	   r   r   )valalias1alias2lensrC   r9   r9   r:   rD   -  s   z)TestMixedTupleUnroll.test_25.<locals>.foor   rI   r9   r9   r:   test_25+  rg  zTestMixedTupleUnroll.test_25c                 C   rv  )Nc           	      S   sv   dddd| d|  f}d}d}d}d}t jt|ft jd	}t|D ]}||7 }|||< |d
7 }|| }q!|||||fS )Nr   r   r   rO   r@   r   6      ri  r?   )r   emptyr   rm  r	   )	r   rL   r   re  	untouched	read_onlymutatedrC   escaper9   r9   r:   rD   >  s   
z)TestMixedTupleUnroll.test_26.<locals>.foor   )r   assertPreciseEqualrH   r   r9   r9   r:   test_269  s
   
zTestMixedTupleUnroll.test_26c                 C   4   t dddd }d}|}| |||| d S )NTparallelc                 S   s@   dddd| d|  f}d}t |D ]}tdD ]}|d7 }qq|S )	Nr   r   r   rO   r@   r   r'   r?   r	   r
   r   rL   r   rC   r   r9   r9   r:   rD   U     
z)TestMixedTupleUnroll.test_27.<locals>.foor   r   r   r9   r9   r:   test_27R  s
   
zTestMixedTupleUnroll.test_27c                 C   s6   t dddd }d}|}tj|||| d S )NTr  c                 S   s@   dddd| d|  f}d}t |D ]}tdD ]}||7 }qq|S Nr   r   r   rO   r@   r   r'   r  r  r9   r9   r:   rD   f  r  z)TestMixedTupleUnroll.test_28.<locals>.foor   )r   r   testingassert_allcloserH   r   r9   r9   r:   test_28c  s
   
zTestMixedTupleUnroll.test_28c                 C   r  )NTr  c                 S   s@   dddd| d|  f}d}t dD ]}t|D ]}||7 }qq|S r  )r
   r	   )r   rL   r   r   rC   r9   r9   r:   rD   y  r  z)TestMixedTupleUnroll.test_29.<locals>.foor   r   r   r9   r9   r:   test_29u  s
   
zTestMixedTupleUnroll.test_29c                 C   r;  )Nc                     $   d  fdd} dd t | dD S )N  c                    *   d}d}t |D ]}||  7 }q|| fS Nr   r   r   r   rO   r  r   r   rL   rC   constr9   r:   r     
   z6TestMixedTupleUnroll.test_30.<locals>.foo.<locals>.barc                 S      g | ]}|qS r9   r9   r   r9   r9   r:   r         z=TestMixedTupleUnroll.test_30.<locals>.foo.<locals>.<listcomp>r?   r@   mapr   r9   r  r:   rD        z)TestMixedTupleUnroll.test_30.<locals>.foor   rI   r9   r9   r:   test_30     
zTestMixedTupleUnroll.test_30c                 C   sf   t dd }| tj}|  W d    n1 sw   Y  | tt|j | dt|j d S )Nc                     r  )Nr  c                    r  r  r  r  r  r9   r:   r     r  z6TestMixedTupleUnroll.test_31.<locals>.foo.<locals>.barc                 S   r  r9   r9   r   r9   r9   r:   r     r  z=TestMixedTupleUnroll.test_31.<locals>.foo.<locals>.<listcomp>)r?   r  r  r  r9   r  r:   rD     r  z)TestMixedTupleUnroll.test_31.<locals>.foozipr  r3   rD   r  r9   r9   r:   test_31  s   
zTestMixedTupleUnroll.test_31c                    s2   t dd  t  fdd}| | |  d S )Nc                 s       t | D ]}|V  qd S r`   r  rL   rC   r9   r9   r:   r
    s   z)TestMixedTupleUnroll.test_32.<locals>.genc                      s   dd  dD S )Nc                 S   r  r9   r9   r   r9   r9   r:   r     r  z=TestMixedTupleUnroll.test_32.<locals>.foo.<locals>.<listcomp>r?   gffffff@y              @r9   r9   r
  r9   r:   rD     s   z)TestMixedTupleUnroll.test_32.<locals>.foor   rI   r9   r  r:   test_32  s
   
zTestMixedTupleUnroll.test_32c                 C   s<   t dd }dd }||}||jj}| | |  d S )Nc                 s   s    | |V  d S r`   r9   )r4   argr9   r9   r:   consumer  s   z.TestMixedTupleUnroll.test_33.<locals>.consumerc                    s   t  fdd}|S )Nc                     s   dd } dd  | dD S )Nc                 s   r  r`   r  r  r9   r9   r:   r
    s   zCTestMixedTupleUnroll.test_33.<locals>.get.<locals>.foo.<locals>.genc                 S   s   g | ]}t |qS r9   )nextr   r9   r9   r:   r     s    zJTestMixedTupleUnroll.test_33.<locals>.get.<locals>.foo.<locals>.<listcomp>r  r9   r  consr9   r:   rD     s   z6TestMixedTupleUnroll.test_33.<locals>.get.<locals>.foor	  )r  rD   r9   r  r:   get  s   z)TestMixedTupleUnroll.test_33.<locals>.get)r   rH   rG   )r3   r  r  cfuncpyfuncr9   r9   r:   test_33  s   
	zTestMixedTupleUnroll.test_33c                 C   sf   t dd }| tj}|  W d    n1 sw   Y  | dt|j | dt|j d S )Nc                  S   sn   d} g d}ddg}| d dkr||f}nt d}t jdt jd}||||f}t|D ]}| t|7 } q,| S )	Nr   rO  r'   rh  r@   rA   r   ri  rk  rn  r9   r9   r:   rD     s   

z)TestMixedTupleUnroll.test_34.<locals>.foozInvalid use ofz&found multiple definitions of variablerJ  r  r9   r9   r:   test_34  s   
zTestMixedTupleUnroll.test_34N))rW   rX   rY   r   r   r   r   r   r   r   r   r  r  r  r9  r@  rB  rF  rM  rQ  rS  ra  rc  rf  rs  ru  r~  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r9   r9   r9   r:   r     sP    
%, )1-


r   c                   @   s|   e 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S )TestConstListUnrollc                 C   r;  )Nc                  S   sJ   g d} d}t tt| D ]}|| | 7 }|jdk r |d8 }q |S |S Nr  r   r   r?   r   )rL   r   r   r9   r9   r:   rD     s   

z(TestConstListUnroll.test_01.<locals>.foor   rI   r9   r9   r:   r     r  zTestConstListUnroll.test_01c                 C   r;  )Nc                  S   s>   g d} d}t | D ]}||7 }|jdk r|d8 }q
 |S |S r  r   rP  r9   r9   r:   rD     s   

z(TestConstListUnroll.test_02.<locals>.foor   rI   r9   r9   r:   r     s   
zTestConstListUnroll.test_02c                 C   r;  )Nc                  S   s`   g d} ddg}d}t | D ]}||7 }|jdk r|d8 }qt |D ]}||du 7 }q" |S |S )Nr  rD   rx  r   r   r?   Fr   rC   r   r   rL   r   r9   r9   r:   rD     s   

z(TestConstListUnroll.test_03.<locals>.foor   rI   r9   r9   r:   r        
zTestConstListUnroll.test_03c                 C   r;  )Nc                  S   s\   g d} d}d}t | D ]}||7 }|jdk r|d8 }qt |D ]}||du 7 }q  |S |S )Nr  )rD   rx  r   r   r?   Fr   r  r9   r9   r:   rD   !  s   

z(TestConstListUnroll.test_04.<locals>.foor   rI   r9   r9   r:   r     r  zTestConstListUnroll.test_04c                 C   s   t dd }d}tdtdg}t|ft||ft|||ft||||ft|||||ff}| tj}||| W d    n1 sMw   Y  d}| |t|j	 d S )Nc                 S   s2   d}t | D ]}|d dkr||d  7 }q|S r   r   r   r9   r9   r:   rD   4  s   z(TestConstListUnroll.test_05.<locals>.foor'   z6Invalid use of literal_unroll with a function argument)
r   r   zerosr   rP   r   rK  rR   rS   rT   )r3   rD   r   r   r   r  r  r9   r9   r:   r   2  s   
$"zTestConstListUnroll.test_05c                 C   T   t dd }| tj}|  W d    n1 sw   Y  | dt|j d S )Nc                  S   sL   d} t | ft | | fdddh dg}d}t|D ]}|t|7 }q|S )Nr'   r  r>   r  r  r   )r   r   r	   r   )r   r   r   rL   r9   r9   r:   rD   I  s   z(TestConstListUnroll.test_06.<locals>.fooz&Found non-constant value at position 0rJ  r  r9   r9   r:   r   G  s   
	zTestConstListUnroll.test_06c                    r  )	Nc                 S   r  r  r9   r!  r9   r9   r:   r"  \  r#  z&TestConstListUnroll.test_7.<locals>.dtr$  r%  c                    r'  )
Nr  c                 S   r  r  r9   r(  r9   r9   r:   r  k  r  z7TestConstListUnroll.test_7.<locals>.ol_dt.<locals>.implr  c                 S   r  r  r9   r(  r9   r9   r:   r  n  r  r  c                 S   r  r  r9   r(  r9   r9   r:   r  q  r  r  c                    r*  r+  r9   r(  r!  r9   r:   r  w  r,  r-  r1  r9   r!  r:   r2  f  r3  z)TestConstListUnroll.test_7.<locals>.ol_dtc                     s&   d} t g dD ]}|  |7 } q| S r4  r  r5  r6  r9   r:   rD   |  s   z'TestConstListUnroll.test_7.<locals>.foor7  r8  r9   r6  r:   test_7Y  r:  zTestConstListUnroll.test_7c                 C   r;  )Nc                  S   sh   g } g d}t tt|D ]#}|| }|dkr| d q|dkr(| | q|dkr1| d q| S r<  r>  r?  r9   r9   r:   rD     s   
z'TestConstListUnroll.test_8.<locals>.foor   rI   r9   r9   r:   test_8  rA  zTestConstListUnroll.test_8c                 C   r   )Nc                 S   sd   g d}d}t |D ]}||7 }|jdk r|d8 }q
t |D ]}||7 }q |d dk r0|d7 }|S )Nr  r   r   r?   rD  r@   r   rE  r9   r9   r:   rD     s   


z'TestConstListUnroll.test_9.<locals>.foor   r@   r   r   r9   r9   r:   test_9  rG  zTestConstListUnroll.test_9c                 C   rH  )Nc                 S   s   dddd|d| f}g d}d}t |D ]1}||7 }|jdk r$|d	8 }nt |D ]}t |D ]}||7 }q.||7 }q(t |D ]}||7 }q>qt |D ]}||7 }qJ|d d
k r[|d7 }|S )Nr   r   r   rO   r@   r  r   r   r?   rD  r   )r   r   rL   r   r   r   rC   r   r9   r9   r:   rD     s&   





z(TestConstListUnroll.test_10.<locals>.foor   r@   rI  rJ  rL  r9   r9   r:   r9    s   
zTestConstListUnroll.test_10c                 C   r;  )Nc                  S   s&   g d} d}t | D ]}||7 }q
|S rN  r  rP  r9   r9   r:   rD     
   
z(TestConstListUnroll.test_11.<locals>.foor   rI   r9   r9   r:   r@    s   
zTestConstListUnroll.test_11c                 C   r  )Nc                  S   s*   d} g d}t |D ]}| t|7 } q
|S )Nr   )r?   r@   rL   )r	   bool)r   rC   rL   r9   r9   r:   rD     s
   z(TestConstListUnroll.test_12.<locals>.foorR  r   rP   r   r  rR   rS   rT   r  r9   r9   r:   rF    s   
zTestConstListUnroll.test_12c                 C   r  )Nc                  S   s.   g d} d}t | d d D ]}||7 }q|S )Nr^  r   r@   r  rP  r9   r9   r:   rD     s
   
z(TestConstListUnroll.test_13.<locals>.foozInvalid use of literal_unrollrJ  r  r9   r9   r:   rM    s   
zTestConstListUnroll.test_13c                 C   r  )Nc                  S   s0   g d} d}t | D ]}||7 }q
| d |S )Nr^  r   r'   )r	   r   rP  r9   r9   r:   rD     s   

z(TestConstListUnroll.test_14.<locals>.fooz(Unknown attribute 'append' of type Tupler  r  r9   r9   r:   rQ    s   
zTestConstListUnroll.test_14N)rW   rX   rY   r   r   r   r   r   r   r  r  r  r9  r@  rF  rM  rQ  r9   r9   r9   r:   r    s    ,!r  c                   @   s   e Zd Zdd Z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d Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-S ).TestMorec                 C   r  )Nc                  S   s$   d} d}t | | D ]}||7 }q	|S )N)r'   rh  r   r  rC   rrL   r9   r9   r:   rD     s
   
z2TestMore.test_invalid_use_of_unroller.<locals>.fooz*literal_unroll takes one argument, found 2rJ  r  r9   r9   r:   test_invalid_use_of_unroller  s   
z%TestMore.test_invalid_use_of_unrollerc                 C   sV   t dd }| tj}|d W d    n1 sw   Y  | dt|j d S )Nc                 S   &   d| g}d}t |D ]}||7 }q
|S Nr'   r   r  r   rC   r  rL   r9   r9   r:   rD   "  r  z,TestMore.test_non_constant_list.<locals>.foor'   zKFound non-constant value at position 1 in a list argument to literal_unrollrJ  r  r9   r9   r:   test_non_constant_list   s   

zTestMore.test_non_constant_listz!numba.literally not supported yetc                    s>   ddl m tfdd  d t fdd}|  d S )Nr   	literallyc                    s*   d | g}d}t |D ]}||7 }q|S r  r  r  r  r9   r:   rD   7  
   
z2TestMore.test_literally_constant_list.<locals>.foor   c                          dS Nr   r9   r9   rD   r9   r:   r   C  r,  z2TestMore.test_literally_constant_list.<locals>.bar)numbar  r   r3   r   r9   )rD   r  r:   test_literally_constant_list2  s   	
z%TestMore.test_literally_constant_listz8inlining of foo doesn't have const prop so y isn't constc                    s4   t dddd  t  fdd}| | d d S )Nr$  r%  c                 S   r  r  r  r  r9   r9   r:   rD   M  r  z.TestMore.test_inlined_unroll_list.<locals>.fooc                      r  r  r9   r9   r  r9   r:   r   U  r,  z.TestMore.test_inlined_unroll_list.<locals>.bar   )r   rG   r  r9   r  r:   test_inlined_unroll_listK  s
   
z!TestMore.test_inlined_unroll_listc                 C   s<   t dd }| |d|d | |d|d d S )Nc                 S   s&   d| f}d}t |D ]}||7 }q
|S r  r  r  r9   r9   r:   rD   \  r  z+TestMore.test_unroll_tuple_arg.<locals>.foor   333333?r   rI   r9   r9   r:   test_unroll_tuple_arg[  s   
zTestMore.test_unroll_tuple_argc                 C   s<   t dd }| |d|d | |d|d d S )Nc                 S      d}t | D ]}||7 }q|S r   r  r  r9   r9   r:   rD   h     
z,TestMore.test_unroll_tuple_arg2.<locals>.foo)r   r  r   rI   r9   r9   r:   test_unroll_tuple_arg2g  s   
zTestMore.test_unroll_tuple_arg2c                 C   r;  )Nc                  S   s2   d} d}t | D ]}|}|}||| | 7 }q|S )Nr'   r  r   r  )rC   outr   r   r   r9   r9   r:   rD   s  s   z-TestMore.test_unroll_tuple_alias.<locals>.foor   rI   r9   r9   r:   test_unroll_tuple_aliasr  s   
	z TestMore.test_unroll_tuple_aliasc                 C   sj   t dd }| tj}|  W d    n1 sw   Y  | dt|j d}| t|j| d S )Nc                  S   s,   d} d}t | D ]}|D ]}||7 }qq|S )N)r  )rN   g      @r   r  )rC   r  r   r   r9   r9   r:   rD     s   
z.TestMore.test_unroll_tuple_nested.<locals>.foor   z#.*Tuple\(int[0-9][0-9], float64\).*)r   rP   r   r  rR   rS   rT   assertRegex)r3   rD   r  rer9   r9   r:   test_unroll_tuple_nested  s   
z!TestMore.test_unroll_tuple_nestedc                 C   sX   t dd }t }|  W d    n1 sw   Y  |  }| |g d d S )Nc                  S   sZ   i } d| d< d| d< i }d|d< d|d< t | |fD ]}| D ]	\}}t|| q qd S )	Nr?   rL   r@   r   r   rA   rX  rO   )r	   itemsr  )rC   r   itr   vr9   r9   r:   rD     s   z/TestMore.test_unroll_tuple_of_dict.<locals>.foo)za 1zb 2z3 cz4 d)r   r   getvalue
splitlinesrG   )r3   rD   stdoutlinesr9   r9   r:   test_unroll_tuple_of_dict  s   
z"TestMore.test_unroll_tuple_of_dictc                    4   t dg d t fdd}| | |  d S )NABCr  c                     *    ddd} d}t | D ]}||7 }q|S )Nr?   r  333333@r   r  abcr  r   r  r9   r:   rD     r  z-TestMore.test_unroll_named_tuple.<locals>.foor   r   rG   rH   rI   r9   r  r:   test_unroll_named_tuple     z TestMore.test_unroll_named_tuplec                 C   @   t dg d}tdd }|ddd}| |||| d S )Nr  r  c                 S   r  r   r  rC   r  r   r9   r9   r:   rD     r  z1TestMore.test_unroll_named_tuple_arg.<locals>.foor?   r  r  r   r3   r  rD   r  r9   r9   r:   test_unroll_named_tuple_arg  
   
z$TestMore.test_unroll_named_tuple_argc                    r  )Nr  r  c                     r  )Nr?   r@   rA   r   r  r  r  r9   r:   rD     r  z0TestMore.test_unroll_named_unituple.<locals>.foor   rI   r9   r  r:   test_unroll_named_unituple  r  z#TestMore.test_unroll_named_unituplec                 C   r  )Nr  r  c                 S   r  r   r  r  r9   r9   r:   rD     r  z4TestMore.test_unroll_named_unituple_arg.<locals>.foor?   r@   rA   r   r  r9   r9   r:   test_unroll_named_unituple_arg  r  z'TestMore.test_unroll_named_unituple_argc                 C   r;  )Nc                  S   s   d} t tD ]}| |7 } q| S r   )r	   	_X_GLOBALr  r   r9   r9   r:   rD     r  z.TestMore.test_unroll_global_tuple.<locals>.foor   rI   r9   r9   r:   test_unroll_global_tuple  s   
z!TestMore.test_unroll_global_tuplec                    s*   d t  fdd}| | |  d S )Nr&   c                     ry  r   r  r  rB   r9   r:   rD     r  z/TestMore.test_unroll_freevar_tuple.<locals>.foor   rI   r9   rB   r:   test_unroll_freevar_tuple  s   z"TestMore.test_unroll_freevar_tuplec                    sF   t dd }t dd }||f t  fdd}| | |  d S )Nc                   S   r  r  r9   r9   r9   r9   r:   rL     r  z.TestMore.test_unroll_function_tuple.<locals>.ac                   S   r  r  r9   r9   r9   r9   r:   r     r  z.TestMore.test_unroll_function_tuple.<locals>.bc                     s    d} t  D ]}| | 7 } q| S r   r  )r  r   rB   r9   r:   rD         z0TestMore.test_unroll_function_tuple.<locals>.foor   )r3   rL   r   rD   r9   rB   r:   test_unroll_function_tuple  s   

z#TestMore.test_unroll_function_tuplec                 C   s   t dd }dd tdD }t  | |||| W d    n1 s(w   Y  t }|| W d    n1 s?w   Y  |  }| |g d d S )Nc                 S   sL   d}d}dd | D }d}t |D ]}||| 7 }|d7 }t| q||fS )Nr   c                 S   r  r9   r9   )r   rL   r9   r9   r:   r     r  zCTestMore.test_unroll_indexing_list.<locals>.foo.<locals>.<listcomp>)rL      gq=
ףp?Nr?   r  )contr   r   normal_listheter_tupleitemr9   r9   r:   rD     s   
z/TestMore.test_unroll_indexing_list.<locals>.fooc                 S   r  r9   r9   )r   r   r9   r9   r:   r     r  z6TestMore.test_unroll_indexing_list.<locals>.<listcomp>rO   )rL   25z0.23None)r   r   r   rG   rH   r  r  )r3   rD   datar  r  r9   r9   r:   test_unroll_indexing_list	  s   

z"TestMore.test_unroll_indexing_listc                    sP   t dt dt dfddlm  t fdd}| | |  d S )N)r?   )r?   r?   )r?   r?   r?   r   r  c                     s    d}  D ]}| |j 7 } q| S r   )ndimr  freevar_unrollmixedr9   r:   rD   *  r  z.TestMore.test_unroller_as_freevar.<locals>.foo)r   r   r  r	   r   rG   rH   rI   r9   r  r:   test_unroller_as_freevar&  s
   z!TestMore.test_unroller_as_freevarc                 C   s   t ddd }d S )Nz(Tuple((int64, float64)),)c                 S   s.   t | D ]}qd}|dkrd}|dksd S d S )Nr?   r   r  )r   r   rC   r9   r9   r:   rD   6  s   zCTestMore.test_unroll_with_non_conformant_loops_present.<locals>.foor	  rI   r9   r9   r:   -test_unroll_with_non_conformant_loops_present3  s   z6TestMore.test_unroll_with_non_conformant_loops_presentc                    J   t jddgddgd}t|jj  t fdd}| ||d d S )	Nr  r@   rA   )rq  f8)rr  r!  ri  c                    ,   d}t  D ]}|t| |   }q|S r   r	   r   absr   arrresr   fieldsr9   r:   rD   D     z>TestMore.test_literal_unroll_legalize_var_names01.<locals>.foo       @r   arraytuplerj  r)  r   r   rG   r3   testrD   r9   r(  r:   (test_literal_unroll_legalize_var_names01?  s
   z1TestMore.test_literal_unroll_legalize_var_names01c                    r  )	Nr  r   )za1[0]r!  )za2[1]r!  ri  c                    r"  r   r#  r%  r(  r9   r:   rD   S  r*  z>TestMore.test_literal_unroll_legalize_var_names02.<locals>.foor+  r,  r/  r9   r(  r:   (test_literal_unroll_legalize_var_names02M  s   
z1TestMore.test_literal_unroll_legalize_var_names02N)rW   rX   rY   r  r  r   r   r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r1  r2  r9   r9   r9   r:   r    s0    

r  c                    s$   t dddG  fdddt}|S )zg Returns a compiler pass that captures the mutation state reported
    by the pass used in the argumentFTrZ   c                       s.   e Zd Zd j Z Zdd Z fddZdS )zcapture.<locals>.ResultCapturerz
capture_%sc                 S   r_   r`   ra   rc   r9   r9   r:   rb   e  rd   z(capture.<locals>.ResultCapturer.__init__c                    s&      |}|jdi }|| < |S )Nmutation_results)rh   r   
setdefault)r3   rg   resultr3  	real_passr9   r:   rh   h  s   z(capture.<locals>.ResultCapturer.run_passN)rW   rX   rY   ri   
_real_passrb   rh   r9   r6  r9   r:   ResultCapturer`  s
    
r9  )r   r   )r7  r9  r9   r6  r:   capture]  s   
r:  c                   @   s   e Zd ZdZdd ZdS )CapturingCompilerz? Simple pipeline that wraps passes with the ResultCapturer passc                    sr   t d  fdd}|td |td |td |td |td |td	 |td
 |td  	   gS )NzCapturing Compilerc                    s     t| |S r`   )rq   r:  )rC   r   rs   r9   r:   rq   w  s   z4CapturingCompiler.define_pipelines.<locals>.add_passrl   zfix up argsrm   zhandles literal_unrollrn   z$ensure IR is legal prior to loweringro   rp   )
r   r   r   r   r   r   r   r"   r    rr   )r3   rq   r9   r<  r:   rw   t  s   






z"CapturingCompiler.define_pipelinesN)rW   rX   rY   __doc__rw   r9   r9   r9   r:   r;  q  s    r;  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestLiteralUnrollPassTriggeringc                 C   @   t tddd }|  |j|jd  }| |jd t  d S )Nr}   c                  S   r   r   r9   r   r9   r9   r:   rD     r   zLTestLiteralUnrollPassTriggering.test_literal_unroll_not_invoked.<locals>.foor   r3  r   r;  r+   r,   assertFalser   r   r3   rD   r6   r9   r9   r:   test_literal_unroll_not_invoked  
   
z?TestLiteralUnrollPassTriggering.test_literal_unroll_not_invokedc                 C   r?  )Nr}   c                  S   s   d} t dD ]}| |7 } q| S r   r  r   r9   r9   r:   rD     r  zKTestLiteralUnrollPassTriggering.test_literal_unroll_is_invoked.<locals>.foor   r3  )r   r;  r+   r,   r/   r   r   rB  r9   r9   r:   test_literal_unroll_is_invoked  rD  z>TestLiteralUnrollPassTriggering.test_literal_unroll_is_invokedc                    sH   t  ttd fdd}|  |j|jd  }| |jd t  d S )Nr}   c                     s   d}  dD ]}| |7 } q| S r   r9   r   aliasr9   r:   rD     r  zUTestLiteralUnrollPassTriggering.test_literal_unroll_is_invoked_via_alias.<locals>.foor   r3  )r	   r   r;  r+   r,   r/   r   r   rB  r9   rF  r:   (test_literal_unroll_is_invoked_via_alias  s   zHTestLiteralUnrollPassTriggering.test_literal_unroll_is_invoked_via_aliasc                 C   r?  )Nr}   c                   S   s   d S r`   r9   r9   r9   r9   r:   rD     r  zVTestLiteralUnrollPassTriggering.test_literal_unroll_assess_empty_function.<locals>.foor   r3  r@  rB  r9   r9   r:   )test_literal_unroll_assess_empty_function  s
   
zITestLiteralUnrollPassTriggering.test_literal_unroll_assess_empty_functionc                 C   sT   d}i }t |i | ttd|d }|  |j|jd  }| |jd t  d S )Nzdef foo():
	passr}   rD   r   r3  )execr   r;  r+   r,   rA  r   r   )r3   r   rt  rD   r6   r9   r9   r:   "test_literal_unroll_not_in_globals  s   zBTestLiteralUnrollPassTriggering.test_literal_unroll_not_in_globalsc                 C   s~  d}i }t |i | ttd|d }| tj}|  W d    n1 s'w   Y  | dt|j i }t |dt	i| ttd|d }|  |j
|jd  }| |jd t  ddlm} d	}i }t ||i | ttd|d
 }|  |j
|jd  }| |jd t  ddlm} d}i }t ||i | ttd|d
 }|  |j
|jd  }| |jd t  d S )Nz1def foo():
	for x in literal_unroll((1,)):
		passr}   rD   z$Untyped global name 'literal_unroll'r	   r   r3  )dedentz
            def gen():
                from numba import literal_unroll
                def foo():
                    for x in literal_unroll((1,)):
                        pass
                return foo
            bar = gen()
            r   a  
            def gen():
                from numba import literal_unroll as something_else
                def foo():
                    for x in something_else((1,)):
                        pass
                return foo
            bar = gen()
            )rJ  r   r;  rP   r   r  rR   rS   rT   r	   r+   r,   r/   r   r   textwraprL  )r3   r   rt  rD   r  r6   rL  r9   r9   r:   &test_literal_unroll_globals_and_locals  s@   		zFTestLiteralUnrollPassTriggering.test_literal_unroll_globals_and_localsN)	rW   rX   rY   rC  rE  rH  rI  rK  rN  r9   r9   r9   r:   r>    s    		r>  __main__)=collectionsr   numpyr   numba.tests.supportr   r   r   r   r  r   r   r	   r
   
numba.corer   r   r   numba.testingr   numba.core.extendingr   numba.core.compiler_machineryr   r   r   r   numba.core.compilerr   numba.core.untyped_passesr   r   r   r   r   r   r   r   numba.core.typed_passesr   r   r    r!   r"   numba.core.ir_utilsr#   r$   numba.core.types.functionsr%   r
  r)   r]   rj   r   r  r  r:  r;  r>  rW   mainr9   r9   r9   r:   <module>   sN    (
(        "  (  Pq