U
    9%e6l                    @   sl  d dl Z d dlZd dlZd dlZd dlZd dl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Zd dlmZ d dlZd dlmZmZ d dlZd dlmZmZ d dlZd dl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(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d d	l5m6Z6 d d
l7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZC d dlDmEZE d dlFmGZGmHZHmIZImJZJ d dlKmLZLmMZM d dlNmOZO d dlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] d dl^m_Z_ d dlDm`Z` d dl$maZa d dlbZbd dlcZceWG dd deQZdeceef dkdZgdZhdZieddZjdd Zke]G dd  d eQZld!d" Zmd#d$ Znd%d& Zod'd( Zpd)d* Zqd+d, Zrd-d. Zsd/d0 Ztd1d2 Zud3d4 Zvd5d6 Zwdbd7d8Zxd9d: ZyG d;d< d<ezZ{eWG d=d> d>elZ|eWG d?d@ d@elZ}eWG dAdB dBelZ~G dCdD dDeQZeWG dEdF dFelZeWG dGdH dHeSelZeWG dIdJ dJelZeWG dKdL dLelZeWG dMdN dNelZeWG dOdP dPelZeWG dQdR dRelZG dSdT dTelZeWG dUdV dVeZeWG dWdX dXeZeWG dYdZ dZeQZeWegG d[d\ d\eZeWG d]d^ d^eQZeWG d_d` d`eQZedakrhec  dS )c    Nreducerandn)defaultdict
namedtuple)cyclechain)njitprangeparallel_chunksizeget_parallel_chunksizeset_parallel_chunksizeset_num_threadsget_num_threadstypeof)
typestypingerrorsirrewritestyped_passesinline_closurecallconfigcompilercpu)overload_methodregister_modeltypeof_implunboxNativeValuemodels)
cpu_target)type_annotations)find_callnameguardbuild_definitionsget_definition
is_getitem
is_setitemindex_var_of_get_setitem)empty_inferred)ByteCodeIter)compile_isolatedFlagsCompilerBaseDefaultPassBuilder)register_passAnalysisPass)IRLegalization)TestCasecaptured_stdoutMemoryLeakMixinoverride_env_config
linux_onlytagskip_parfors_unsupported_32bit
needs_blasneeds_lapackdisabled_testskip_unless_scipyneeds_subprocess)register_jitable)_fix_LOAD_GLOBAL_arg)utilsc                   @   s   e Zd ZdZe dkrdn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 )"TestParforsRunnerFaarch64i  i  c                 C   s8   | j }|  dd dd }| j||| jd d S )N._)Ztest_moduleZ
test_classtimeout)
__module__idsplitZsubprocess_test_runner_TIMEOUT)selfZthemodZtest_clazz_name rO   W/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_parfors.pyrunnerP   s    zTestParforsRunner.runnerc                 C   s   |    d S NrQ   rN   rO   rO   rP   test_TestParforBasicX   s    z&TestParforsRunner.test_TestParforBasicc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforNumericalMisc[   s    z.TestParforsRunner.test_TestParforNumericalMiscc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforNumPy^   s    z&TestParforsRunner.test_TestParforNumPyc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsa   s    z"TestParforsRunner.test_TestParforsc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsBitMaskd   s    z)TestParforsRunner.test_TestParforsBitMaskc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsDiagnosticsg   s    z-TestParforsRunner.test_TestParforsDiagnosticsc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsLeaksj   s    z'TestParforsRunner.test_TestParforsLeaksc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsMiscm   s    z&TestParforsRunner.test_TestParforsMiscc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsOptionsp   s    z)TestParforsRunner.test_TestParforsOptionsc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsSlices   s    z'TestParforsRunner.test_TestParforsSlicec                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestParforsVectorizerv   s    z,TestParforsRunner.test_TestParforsVectorizerc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestPrangeBasicy   s    z&TestParforsRunner.test_TestPrangeBasicc                 C   s   |    d S rR   rS   rT   rO   rO   rP   test_TestPrangeSpecific|   s    z)TestParforsRunner.test_TestPrangeSpecificN)__name__rJ   __qualname___numba_parallel_test_platformmachinerM   rQ   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rO   rO   rO   rP   rD   B   s    rD   )i386x86_64zx86 only test      TestNamedTuplepart0part1c                 C   s   dS )z
    Used with check_arq_equality to indicate that we do not care
    whether the value of the parameter at the end of the function
    has a particular value.
    NrO   abrO   rO   rP   null_comparer   s    rr   c                       s   e Zd ZdZdZ f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dZd+d d!Zd"d# Zd$d% Zd&d' Zd(d) Z  ZS ),TestParforsBasez
    Base class for testing parfors.
    Provides functions for compilation and three way comparison between
    python functions, njit'd functions and parfor njit'd functions.
    Fc                    sn   t  | _d| j_t  | _td| j_d| j_t  | _td| j_d| j_td| j_	t
t| j|  d S )NT)r.   cflagsZnrtpflagsr   ParallelOptionsZauto_parallelfast_pflagsZFastMathOptionsfastmathsuperrs   __init__rN   args	__class__rO   rP   rz      s    zTestParforsBase.__init__c                 C   s   t |||dS N)flags)r-   )rN   funcsigr   rO   rO   rP   _compile_this   s    zTestParforsBase._compile_thisc                 C   s   | j ||| jdS r   )r   ru   rN   r   r   rO   rO   rP   compile_parallel   s    z TestParforsBase.compile_parallelc                 C   s   | j ||| jdS r   )r   rw   r   rO   rO   rP   compile_parallel_fastmath   s    z)TestParforsBase.compile_parallel_fastmathc                 C   s   | j ||| jdS r   )r   rt   r   rO   rO   rP   compile_njit   s    zTestParforsBase.compile_njitc                 O   s2   t dd |D }| ||}| ||}||fS )Nc                 S   s   g | ]}t |qS rO   numbar   .0xrO   rO   rP   
<listcomp>   s     z/TestParforsBase.compile_all.<locals>.<listcomp>)tupler   r   )rN   pyfuncr|   kwargsr   cpfunccfuncrO   rO   rP   compile_all   s    zTestParforsBase.compile_allc                 O   sF  | dd}| dd}| dd}| dd}	| dd}
dd	 }|| }|| }|| }|j| }|| }|j| }|
dkrtjj||f| tjj||f| | t|t| nLt|t|
kstt	||||
D ](\}}}}|||f| |||f| q|	r| 
|| |dk	rB|j||  }tjj||f| dS )
a-  
        Checks python, njit and parfor impls produce the same result.

        Arguments:
            pyfunc - the python function to test
            cfunc - CompilerResult from njit of pyfunc
            cpfunc - CompilerResult from njit(parallel=True) of pyfunc
            args - arguments for the function being tested
        Keyword Arguments:
            scheduler_type - 'signed', 'unsigned' or None, default is None.
                           Supply in cases where the presence of a specific
                           scheduler is to be asserted.
            fastmath_pcres - a fastmath parallel compile result, if supplied
                             will be run to make sure the result is correct
            check_arg_equality - some functions need to check that a
                                 parameter is modified rather than a certain
                                 value returned.  If this keyword argument
                                 is supplied, it should be a list of
                                 comparison functions such that the i'th
                                 function in the list is used to compare the
                                 i'th parameter of the njit and parallel=True
                                 functions against the i'th parameter of the
                                 standard Python function, asserting if they
                                 differ.  The length of this list must be equal
                                 to the number of parameters to the function.
                                 The null comparator is available for use
                                 when you do not desire to test if some
                                 particular parameter is changed.
            Remaining kwargs are passed to np.testing.assert_almost_equal
        scheduler_typeNcheck_fastmathfastmath_pcrescheck_schedulingTcheck_arg_equalityc                  W   s   | s
t  S g }| D ]}t|tjr4||d qt|tjrP||  qt|tjrh|| q|d kr||| qt|t r|t	| qt|t
r||d d   qtdqt |S )Nkz%Unsupported argument type encountered)r   
isinstancenpZndarrayappendcopynumbernumbersNumberdeepcopylist
ValueError)r|   new_argsr   rO   rO   rP   	copy_args   s$    


z:TestParforsBase.check_parfors_vs_others.<locals>.copy_args)popentry_pointr   testingassert_almost_equalassertEqualtypelenAssertionErrorzipr   )rN   r   r   r   r|   r   r   r   r   r   Zcheck_args_for_equalityr   Zpy_argsZpy_expectedZ	njit_argsZnjit_outputZparfor_argsparfor_outputZpyargZnjitargZ	parforargZargcompZparfor_fastmath_outputrO   rO   rP   check_parfors_vs_others   s@    

   
z'TestParforsBase.check_parfors_vs_othersc                 O   s.   | j |f| \}}| j|||f|| dS )zChecks that pyfunc compiles for *args under parallel=True and njit
        and asserts that all version execute and produce the same resultNr   r   rN   r   r|   r   r   r   rO   rO   rP   check  s    zTestParforsBase.checkc              
   K   sB   | D ]6}|  ttt| | j|f|| W 5 Q R X qdS )zHRun self.check(impl, ...) on array data generated from arg_gen.
        N)subTestr   mapr   r   )rN   implarg_genr   r|   rO   rO   rP   check_variants#  s    
zTestParforsBase.check_variantsc              
   K   sP   | D ]D}|  ttt|& ttt|}| t||d W 5 Q R X qdS )zXRun self.countParfors(impl, ...) on array types generated from
        arg_gen.
           N)r   r   r   r   r   assertGreaterEqualcountParfors)rN   r   r   r   r|   ZargtysrO   rO   rP   count_parfors_variants*  s    
z&TestParforsBase.count_parfors_variantsc                 C   sH   d}|d k	r2|dkr"|d| 7 }nd}t || | ||j  d S )Nz@do_scheduling)signedunsignedrH   z$Unknown scheduler_type specified: %s)r   assertInlibraryget_llvm_str)rN   cresr   Zscheduler_strmsgrO   rO   rP   r   4  s    z TestParforsBase.check_schedulingc                    s,    fdd}t | fddt|D S )zFMake *ct* sample 1D arrays of length *n* using np.linspace().
        c                   3   s4   t dd V  t dd V  t dd V  d S Nr   r      r   linspacerO   nrO   rP   genC  s    z)TestParforsBase.gen_linspace.<locals>.genc                    s   g | ]}t  qS rO   )nextr   i)srcrO   rP   r   I  s     z0TestParforsBase.gen_linspace.<locals>.<listcomp>)r   range)rN   r   ctr   rO   )r   r   rP   gen_linspace@  s    
zTestParforsBase.gen_linspacec                 c   sp   | j d|dV  dd | j d|dD }|V  dd |D V  dd | j d	|dD }|V  d
d |D V  dS )z?Make 1D, 2D, 3D variants of the data in C and F orders
        
   )r   c                 S   s   g | ]}| d qS )r      reshaper   rO   rO   rP   r   R  s   z9TestParforsBase.gen_linspace_variants.<locals>.<listcomp>   )r   r   c                 S   s   g | ]}t |qS rO   r   Zasfortranarrayr   rO   rO   rP   r   V  s     c                 S   s   g | ]}| d qS ))r   r      r   r   rO   rO   rP   r   Y  s      c                 S   s   g | ]}t |qS rO   r   r   rO   rO   rP   r   ]  s     N)r   )rN   r   Zarr2dsZarr3dsrO   rO   rP   gen_linspace_variantsK  s    z%TestParforsBase.gen_linspace_variantsNc                    s8    fdd|D }|dk	r4|D ]}|t |kstq|S )z. helper function to filter out modules by namec                    s   g | ]} |j kr|qS rO   namer   magicstrrO   rP   r   a  s     
 z/TestParforsBase._filter_mod.<locals>.<listcomp>N)strr   )rN   modr   checkstrZfiltr   rO   r   rP   _filter_mod_  s
    zTestParforsBase._filter_modc                 C   s(   dd |j jjjjD }| j|||dS )z gets the gufunc LLVM Modulesc                 S   s   g | ]}|qS rO   rO   r   rO   rO   rP   r   i  s     z7TestParforsBase._get_gufunc_modules.<locals>.<listcomp>)r   )r   _codegenZ_engineZ_ee_modulesr   )rN   r   r   r   r   rO   rO   rP   _get_gufunc_modulesg  s    z#TestParforsBase._get_gufunc_modulesc                 C   s2   d}|  ||}t }|D ]}||||j< q|S )z$ helper for gufunc IR/asm generation__numba_parfor_gufunc)r   dictr   )rN   r   fnr   Zgufunc_modsr   r   rO   rO   rP   _get_gufunc_infol  s    z TestParforsBase._get_gufunc_infoc                 C   s   |  |tS )z
        Returns the IR of the gufuncs used as parfor kernels
        as a dict mapping the gufunc name to its IR.

        Arguments:
         cres - a CompileResult from `njit(parallel=True, ...)`
        )r   r   )rN   r   rO   rO   rP   _get_gufunc_irv  s    zTestParforsBase._get_gufunc_irc                    s"   |j jj  fdd}| ||S )z
        Returns the assembly of the gufuncs used as parfor kernels
        as a dict mapping the gufunc name to its assembly.

        Arguments:
         cres - a CompileResult from `njit(parallel=True, ...)`
        c                    s   t  | S rR   )r   Zemit_assembly)r   tmrO   rP   emit_asm  s    z1TestParforsBase._get_gufunc_asm.<locals>.emit_asm)r   r   Z_tmr   )rN   r   r   rO   r   rP   _get_gufunc_asm  s    
zTestParforsBase._get_gufunc_asmc           
         sP     ||} |}dd } fdd}| D ]\}}||}	||	 q2dS )a  
        Asserts that the fastmath flag has some effect in that suitable
        instructions are now labelled as `fast`. Whether LLVM can actually do
        anything to optimise better now the derestrictions are supplied is
        another matter!

        Arguments:
         pyfunc - a function that contains operations with parallel semantics
         sig - the type signature of pyfunc
        c                 S   s8   |   }g }|D ]"}td|}|d k	r|| q|S )Nz\bfast\b)
splitlinesresearchr   )r   splittedZ	fast_instr   mrO   rO   rP   _get_fast_instructions  s    z?TestParforsBase.assert_fastmath.<locals>._get_fast_instructionsc                    sF   d}| D ]8}d}|D ]}|d }||kr|d7 }q  |dk qd S )N)ZfaddZfsubZfmulZfdivZfremZfcmpcallr   z fastr   )
assertTrue)ZinstrsopsinstcountopmatchrT   rO   rP   _assert_fast  s    
z5TestParforsBase.assert_fastmath.<locals>._assert_fastN)r   r   items)
rN   r   r   r   _irr   r   r   Zguirr   rO   rT   rP   assert_fastmath  s    
	
zTestParforsBase.assert_fastmath)N)N)rb   rJ   rc   __doc__rd   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rO   rO   r}   rP   rs      s*   Z




rs   c                 C   s   t | | }d| | }|t | }|| | | | }|| }	dd|  }
dd|	  }|t | |  }|| }| |
 | }|| |  }|S )N      ?      ?)r   logsqrtexp)ZsptpricestrikeZrateZ
volatilityZtimevZlogtermZpowtermZdenZd1Zd2ZNofXd1ZNofXd2ZfutureValuec1r   putrO   rO   rP   blackscholes_impl  s    r  c                 C   sF   t |D ]8}|tddt|  t||   d |  |8 }q|S Nr  )r   r   dotr  )YXwZ
iterationsr   rO   rO   rP   lr_impl  s    6r  c                    s|   | j \}t|D ]`}t fddt|D tfddt|D t fddtD qS )Nc                    s&   g | ]  fd dt D qS )c                    s<   g | ]4}t t d d f |d d f  d qS Nr   )mathr  r   sumr   j)A	centroidsr   rO   rP   r     s   2example_kmeans_test.<locals>.<listcomp>.<listcomp>r   r   )r  r  	numCenterr   rP   r     s   z'example_kmeans_test.<locals>.<listcomp>c                    s    g | ]} |d d f   qS rR   argminr   )distrO   rP   r     s     c                    s&   g | ]  fd dt D qS )c                    s0   g | ](}t  k|f t k qS rO   r   r  r  )r  r   labelsrO   rP   r     s   r  r  r  )r  Dr"  r  rP   r     s   )shaper   r   array)r  r  ZnumIterinit_centroidsNlrO   )r  r#  r  r   r"  r  rP   example_kmeans_test  s    

r)  c                 K   sF  t  }t|d}t| }|r.t|}n
td}t||||}t	|| |
  |
  tj|jj|dd}|  tjd|j t|jj|jj|jj|jjd \|j_|j_|j_}	tj|jj|jj|jjdd |jj|jjtjd tj j!" }
tj j!j#|jj|jj|jj|jj|jj||
j$d}|  tjd|j t% }tj j!j&|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  tj j!j(|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  tj j!j)|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  t*|j+|_,W 5 Q R X ||fS )
Nr   T)typedzbefore-inferencerO   )func_irtypemap	calltypesZliftedZlifted_fromr|   return_typeZhtml_output)Zswappedzafter-inference)diagnostics)-r   Contextr   Z
CPUContextr   Zrun_frontendrv   TestPipeliner"   Znested_contextrefreshr   ZInlineClosureCallPassstater+  runr   Zrewrite_registryapplyr   Ztype_inference_stage	typingctx	targetctxr|   r,  r.  r-  r#   ZTypeAnnotationr   HTMLr   parforsparforZParforDiagnosticsZPreParforPassreplaced_fnsr.   Z
ParforPassmetadataZParforFusionPassZParforPreLoweringPassr&   blocksZ_definitions)	test_funcr|   kwsr6  r7  test_iroptionstpZinline_passrH   r/  Zpreparfor_passr   Zparfor_passrO   rO   rP   get_optimized_numba_ir  s    



   
                         rC  c           
      K   sZ   t | |f|\}}d}|j D ]4\}}t|jD ] \}}	t|	tjjj	r2|d7 }q2q |S Nr   r   )
rC  r=  r   	enumeratebodyr   r   r9  r:  Parfor)
r>  r|   r?  r@  rB  	ret_countlabelblockr   r   rO   rO   rP   r     s    r   c                 K   s"   t | |f|\}}t|j|jjS rR   )rC  _count_arrays_innerr=  r3  r,  r>  r|   r?  r@  rB  rO   rO   rP   countArrays&  s    rM  c                 K   sf   t | |f|\}}|j}d}| D ]<\}}t|jD ](\}	}
t|
tjjj	r6|t
|
jj7 }q6q$|S Nr   )rC  r=  r   rE  rF  r   r   r9  r:  rG  r   
init_block)r>  r|   r?  r@  rB  r=  rH  rI  rJ  r   r   rO   rO   rP   get_init_block_size*  s    rP  c           	      C   s   d}t  }|  D ]|\}}t|jD ]h\}}t|tjjjr^|j	
 }|j|d< |t||7 }t|tjr$t||jj tjr$||jj q$q|t|7 }|S rN  )setr   rE  rF  r   r   r9  r:  rG  	loop_bodyr   rO  rK  r   Assigntargetr   r   ArrayCompatibleaddr   )	r=  r,  rH  Zarr_setrI  rJ  r   r   parfor_blocksrO   rO   rP   rK  7  s     

rK  c                 K   s8   t | |f|\}}d}|j D ]}|t||7 }q |S rN  )rC  r=  values_count_array_allocs_inner)r>  r|   r?  r@  rB  rH  rJ  rO   rO   rP   countArrayAllocsI  s
    rZ  c                 C   s   d}|j D ]}t|tjjjrL|t| |j7 }|j	 D ]}|t| |7 }q8t|t
jr
t|jt
jr
|jjdkr
tt| |jdkstt| |jdkr
|d7 }q
|S )Nr   r   )emptynumpy)r+   znumba.np.unsafe.ndarrayr   )rF  r   r   r9  r:  rG  rY  rO  rR  rX  r   rS  valueExprr   r%   r$   )r+  rJ  rH  r   rq   rO   rO   rP   rY  R  s"    


rY  c                 K   s$   t | |f|\}}t||j|jjS rR   )rC  &_count_non_parfor_array_accesses_innerr=  r3  r,  rL  rO   rO   rP   countNonParforArrayAccessesc  s    r`  c           	      C   s  d}|d krt  }| D  ]\}}|jD ]}t|tjjjrt||j	j
 |j }|j|d< |t| |||7 }q*t|rt||jjj
 tjrt| t||s|d7 }q*t|rt||jj
 tjrt| t||s|d7 }q*t|tjr*t|jtjr*|jj
|kr*||jj
 q*q|S rD  )rQ  r   rF  r   r   r9  r:  rG  rV  	index_varr   rR  r   rO  r_  r(   r]  r   rU  _uses_indicesr*   r)   rT  r   rS  ZVar)	f_irr=  r,  Zparfor_indicesrH  rI  rJ  stmtrW  rO   rO   rP   r_  h  sT    


     
  

r_  c                 C   sX   |j |krdS tt| |}t|tjrT|jdkrTtdd |jD }t	||@ dkS dS )NTbuild_tuplec                 s   s   | ]}|j V  qd S rR   r   )r   vrO   rO   rP   	<genexpr>  s     z _uses_indices.<locals>.<genexpr>r   F)
r   r%   r'   r   r   r^  r   rQ  r   r   )rc  indexZ	index_setZind_defvarnamesrO   rO   rP   rb    s    
rb  c                   @   s   e Zd Zdd ZdS )r1  c                 C   sN   t  | _|| j_|| j_|| j_|| j_d | j_d | j_d | j_	i | j_
d S rR   )r   Z	StateDictr3  r6  r7  r|   r+  r,  r.  r-  r<  )rN   r6  r7  r|   r@  rO   rO   rP   rz     s    
zTestPipeline.__init__N)rb   rJ   rc   rz   rO   rO   rO   rP   r1    s   r1  c                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zed"d# Zed$d% Zed&d' Zed(d) Zd*d+ Zd,d- Zd.d/ Zed0d1 Zed2d3 Zed4d5 Z d6d7 Z!d8S )9TestParforBasiczZSmoke tests for the parfors transforms. These tests check the most basic
    functionalityc                 G   sB   t j| f|  ttdd}tdtd||jg| _d S )N      (@r   r         @      @)rs   rz   r   r   arangeTsimple_args)rN   r|   r   rO   rO   rP   rz     s    zTestParforBasic.__init__c              	   C   s>   dd }|  t}| | W 5 Q R X | dt|j d S )Nc                   S   s
   t dS )NrO   r   onesrO   rO   rO   rP   	test_impl  s    z0TestParforBasic.test_simple01.<locals>.test_impl'@do_scheduling' not foundassertRaisesr   r   r   r   	exceptionrN   rt  raisesrO   rO   rP   test_simple01  s    zTestParforBasic.test_simple01c                 C   s   dd }|  | d S )Nc                   S   s
   t dS )Nr   rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple02.<locals>.test_implr   rN   rt  rO   rO   rP   test_simple02  s    zTestParforBasic.test_simple02c                 C   s   dd }|  | d S )Nc                   S   s
   t dS Nr   r   rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple03.<locals>.test_implr}  r~  rO   rO   rP   test_simple03  s    zTestParforBasic.test_simple03c                 C   s   dd }|  | d S )Nc                   S   s
   t dS Nr   rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple04.<locals>.test_implr}  r~  rO   rO   rP   test_simple04  s    zTestParforBasic.test_simple04c                 C   s   dd }|  | d S )Nc                   S   s   t jdt jdS )Nr  dtyper   rs  
complex128rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple07.<locals>.test_implr}  r~  rO   rO   rP   test_simple07  s    zTestParforBasic.test_simple07c                 C   s   dd }|  | d S )Nc                   S   s   t dt d S r  rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple08.<locals>.test_implr}  r~  rO   rO   rP   test_simple08  s    zTestParforBasic.test_simple08c                 C   s   dd }|  | d S )Nc                   S   s
   t dS )Nr   r   rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple09.<locals>.test_implr}  r~  rO   rO   rP   test_simple09  s    zTestParforBasic.test_simple09c                 C   s   dd }|  | d S )Nc                   S   s
   t dS )Nr   r   rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple10.<locals>.test_implr}  r~  rO   rO   rP   test_simple10  s    zTestParforBasic.test_simple10c                 C   s   dd }|  | d S )Nc                   S   s   t dd S Nr   r   r  rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple11.<locals>.test_implr}  r~  rO   rO   rP   test_simple11  s    zTestParforBasic.test_simple11c                 C   s   dd }|  | d S )Nc                   S   s   t dt d S r  r  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple12.<locals>.test_implr}  r~  rO   rO   rP   test_simple12  s    zTestParforBasic.test_simple12c              	   C   s>   dd }|  t}| | W 5 Q R X | dt|j d S )Nc                   S   s
   t dS r  )r   r  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple13.<locals>.test_implru  rv  ry  rO   rO   rP   test_simple13  s    zTestParforBasic.test_simple13c                 C   s   dd }|  | d S )Nc                   S   s   t ddd d S )Nr  r      rr  rO   rO   rO   rP   rt    s    z0TestParforBasic.test_simple14.<locals>.test_implr}  r~  rO   rO   rP   test_simple14  s    zTestParforBasic.test_simple14c                 C   s   dd }| j |f| j  d S )Nc                 S   s   | |  S rR   rO   v1v2m1m2rO   rO   rP   rt    s    z0TestParforBasic.test_simple15.<locals>.test_implr   rq  r~  rO   rO   rP   test_simple15  s    zTestParforBasic.test_simple15c                 C   s   dd }| j |f| j  d S )Nc                 S   s   || S rR   rO   r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple16.<locals>.test_implr  r~  rO   rO   rP   test_simple16  s    zTestParforBasic.test_simple16c                 C   s   dd }| j |f| j  d S )Nc                 S   s   ||  S rR   rO   r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple17.<locals>.test_implr  r~  rO   rO   rP   test_simple17  s    zTestParforBasic.test_simple17c                 C   s   dd }| j |f| j  d S )Nc                 S   s   |j tj|d  S r  )rp  r   linalgZsvdr  rO   rO   rP   rt    s    z0TestParforBasic.test_simple18.<locals>.test_implr  r~  rO   rO   rP   test_simple18  s    zTestParforBasic.test_simple18c                 C   s   dd }| j |f| j  d S )Nc                 S   s   t ||S rR   r   r  r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple19.<locals>.test_implr  r~  rO   rO   rP   test_simple19  s    zTestParforBasic.test_simple19c              	   C   sF   dd }|  t}| j|f| j  W 5 Q R X | dt|j d S )Nc                 S   s   t ||S rR   r  r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple20.<locals>.test_implru  )rw  r   r   rq  r   r   rx  ry  rO   rO   rP   test_simple20	  s    zTestParforBasic.test_simple20c                 C   s   dd }| j |f| j  d S )Nc                 S   s   t | | S rR   r  r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple21.<locals>.test_implr  r~  rO   rO   rP   test_simple21  s    zTestParforBasic.test_simple21c                 C   s   dd }| j |f| j  d S )Nc                 S   s   t | |  S rR   r!  r  rO   rO   rP   rt    s    z0TestParforBasic.test_simple22.<locals>.test_implr  r~  rO   rO   rP   test_simple22  s    zTestParforBasic.test_simple22c                 C   s   dd }| j |f| j  d S )Nc                 S   s2   d|  }d|  }dt |d |d  dk  d S )Nr   r   r   r   r!  )r  r  r  r  r   yrO   rO   rP   rt    s    z0TestParforBasic.test_simple23.<locals>.test_implr  r~  rO   rO   rP   test_simple23  s    zTestParforBasic.test_simple23c                 C   s   dd }|  | d S )Nc                  S   s2   d} t | | f}t | }t |d d |f S )Nr  )r   rs  ro  r  )r   r  rq   rO   rO   rP   rt  %  s    
z0TestParforBasic.test_simple24.<locals>.test_implr}  r~  rO   rO   rP   test_simple24$  s    zTestParforBasic.test_simple24c                 C   s   dd }| j |f| j  dS )zAsame as corresponding test_simple_<n> case but using operator.addc                 S   s   t | | S rR   operatorrV  r  rO   rO   rP   rt  /  s    z:TestParforBasic.test_simple_operator_15.<locals>.test_implNr  r~  rO   rO   rP   test_simple_operator_15,  s    z'TestParforBasic.test_simple_operator_15c                 C   s   dd }| j |f| j  d S )Nc                 S   s   t ||S rR   r  r  rO   rO   rP   rt  6  s    z:TestParforBasic.test_simple_operator_16.<locals>.test_implr  r~  rO   rO   rP   test_simple_operator_164  s    z'TestParforBasic.test_simple_operator_16c                 C   s   dd }| j |f| j  d S )Nc                 S   s   t || S rR   r  r  rO   rO   rP   rt  =  s    z:TestParforBasic.test_simple_operator_17.<locals>.test_implr  r~  rO   rO   rP   test_simple_operator_17;  s    z'TestParforBasic.test_simple_operator_17c                 C   s0   dd }dd }t d}| j|||gd d S )Nc                 S   s   | d7 } d| d d < d S )Nr   r   rO   rp   rO   rO   rP   rt  D  s    z5TestParforBasic.test_inplace_alias.<locals>.test_implc                 S   s   t j| | d S rR   r   r   Zassert_equalro   rO   rO   rP   comparerH  s    z4TestParforBasic.test_inplace_alias.<locals>.comparerr   r   r   rs  r   )rN   rt  r  r   rO   rO   rP   test_inplace_aliasB  s    
z"TestParforBasic.test_inplace_aliasN)"rb   rJ   rc   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>   r  r  r  r  rO   rO   rO   rP   rj    sF   






rj  c                   @   s4   e Zd ZdZdd Zdd Zedd Zdd	 Zd
S )TestParforNumericalMiscz+ Miscellaneous 'classical' numerical tests c                 C   sH   dd }| j |ddd | t|tjfd | t|tjfd d S )Nc                 S   sJ   dt j|  d }dt j|  d }dt |d |d  dk  |  S )Nr   r   r   )r   randomranfr  )r   r   r  rO   rO   rP   rt  T  s    z2TestParforNumericalMisc.test_pi.<locals>.test_impli r   decimalr   )r   r   r   r   int64rM  intpr~  rO   rO   rP   test_piS  s    zTestParforNumericalMisc.test_pic                 C   s*   t jd d  fd }| tt|d d S Nrj   r   )r   float64r   r   r  r{   rO   rO   rP   test_blackscholes]  s    z)TestParforNumericalMisc.test_blackscholesc                 C   s\   t jd d  t jd d d d f t jd d  t jf}| tt|d | tt|d d S Nr   r   )r   r  r  r   r   r  rZ  r{   rO   rO   rP   test_logistic_regressionb  s
    ,z0TestParforNumericalMisc.test_logistic_regressionc                 C   s   t jd d}d}d}t j||f}t j||f}| jt||d|dd ttjddtj	tj	ttjddf}| 
tt|d d S )	Nr      r   r   r   r  r   C)r   r  seedr  r   r)  r   Arrayr  r  r   r`  )rN   r'  r#  Zcentersr  r&  Zarg_typsrO   rO   rP   test_kmeansi  s      z#TestParforNumericalMisc.test_kmeansN)	rb   rJ   rc   r  r  r  r<   r  r  rO   rO   rO   rP   r  O  s   

r  c                   @   s   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestParforNumPyz'Tests NumPy functionality under parforsc                 C   s>   dd }t ddddd}t ddd}| ||| d S )Nc                 S   s   t | |S rR   r  rp   rf  rO   rO   rP   rt    s    z-TestParforNumPy.test_mvdot.<locals>.test_implr   r   r  r   r   )r   r   r   r   )rN   rt  r  rf  rO   rO   rP   
test_mvdot~  s    zTestParforNumPy.test_mvdotc                    sb   t jt jt jt jfD ]H  fdd}| |d | t|tj	fd | t
|tjfd qd S )Nc                    s"   t | } |}| }|| S rR   r   rs  r  )r   r  r  Br   rO   rP   rt    s    
zBTestParforNumPy.test_fuse_argmin_argmax_max_min.<locals>.test_impl   r   r   )r   r  argmaxminmaxr   r   r   r   r  rM  r  r~  rO   r  rP   test_fuse_argmin_argmax_max_min  s
    z/TestParforNumPy.test_fuse_argmin_argmax_max_minc                 C   s"   dd }|  t|tjfd d S )Nc                 S   s   t | }|d S rN  r   r   r  rO   rO   rP   rt    s    zDTestParforNumPy.test_np_random_func_direct_import.<locals>.test_implr   r   r   r   r  r~  rO   rO   rP   !test_np_random_func_direct_import  s    z1TestParforNumPy.test_np_random_func_direct_importc                 C   sf   dd }dd }dd }ddd	t d
dt dd
fD ].}| || | |d| | |d|d q2d S )Nc                 S   s
   t | S rR   r   ro  r   rO   rO   rP   
test_impl1  s    z/TestParforNumPy.test_arange.<locals>.test_impl1c                 S   s   t | |S rR   r  sr   rO   rO   rP   
test_impl2  s    z/TestParforNumPy.test_arange.<locals>.test_impl2c                 S   s   t | ||S rR   r  r  r   trO   rO   rP   
test_impl3  s    z/TestParforNumPy.test_arange.<locals>.test_impl3            >@r   rj   r   complexr   rN   r  r  r  argrO   rO   rP   test_arange  s    zTestParforNumPy.test_arangec                 C   sP   dd }dd }dd }dD ].}|  || |  |d| |  |d|d qd S )	Nc                 S   s   t j| t jdS Nr  r   ro  float32r   rO   rO   rP   r    s    z5TestParforNumPy.test_arange_dtype.<locals>.test_impl1c                 S   s   t j| |t jdS r  r  r  rO   rO   rP   r    s    z5TestParforNumPy.test_arange_dtype.<locals>.test_impl2c                 S   s   t j| ||t jdS r  r  r  rO   rO   rP   r    s    z5TestParforNumPy.test_arange_dtype.<locals>.test_impl3)r  r  r  r   r}  r  rO   rO   rP   test_arange_dtype  s    z!TestParforNumPy.test_arange_dtypec                 C   sR   dd }dd }dddt dd	t d	dfD ]"}| |d
| | |d
|d q*d S )Nc                 S   s   t | |S rR   r   )startstoprO   rO   rP   r    s    z1TestParforNumPy.test_linspace.<locals>.test_impl1c                 S   s   t | ||S rR   r   )r  r  numrO   rO   rP   r    s    z1TestParforNumPy.test_linspace.<locals>.test_impl2r  r  r  r   rj   r      r  )rN   r  r  r  rO   rO   rP   test_linspace  s
    zTestParforNumPy.test_linspacec              	      s   dd }d}t j|}t jjd|dfd} ||  ||  t|ttj	ddfd  t|ttj	d	dfd  fd
d} 
||  || d S )Nc                 S   s   |   S rR   Zmeanr  rO   rO   rP   rt    s    z,TestParforNumPy.test_mean.<locals>.test_impld   r   r   sizer   r  r   c                      s
     dS r  r   rO   rT   rO   rP   <lambda>      z+TestParforNumPy.test_mean.<locals>.<lambda>r   r  r  randintr   r   r   r   r  r  r   r   )rN   rt  r'  r  r  data_genrO   rT   rP   	test_mean  s      zTestParforNumPy.test_meanc              	      s   dd }d}t j|}t jjd|dfd}|d|  } ||  ||  ||  t|ttj	dd	fd
  t|ttj	d
d	fd
  fdd} 
||  || d S )Nc                 S   s   |   S rR   )varr  rO   rO   rP   rt    s    z+TestParforNumPy.test_var.<locals>.test_implr  r   r   r                ?r   r  r   c                      s
     dS r  r  rO   rT   rO   rP   r    r  z*TestParforNumPy.test_var.<locals>.<lambda>r  )rN   rt  r'  r  r  r  r  rO   rT   rP   test_var  s      zTestParforNumPy.test_varc                    s   dd }d}t j|}t jjd|dfd}|d|  } ||  ||  || ttjdd	f} t	||d
  t	||d
  fdd} 
||  || d S )Nc                 S   s   |   S rR   )Zstdr  rO   rO   rP   rt    s    z+TestParforNumPy.test_std.<locals>.test_implr  r   r   r  r  r   r  r   c                      s
     dS r  r  rO   rT   rO   rP   r    r  z*TestParforNumPy.test_std.<locals>.<lambda>)r   r  r  r  r   r   r  r  r   r   r   r   )rN   rt  r'  r  r  r  argtyr  rO   rT   rP   test_std  s    zTestParforNumPy.test_stdc                 C   s"   dd }|  t|tjfd dS )z
        Test function with only a random call to make sure a random function
        like ranf is actually translated to a parfor.
        c                 S   s   t j| | f}|S rR   )r   r  r  r  rO   rO   rP   rt    s    z5TestParforNumPy.test_random_parfor.<locals>.test_implr   Nr  r~  rO   rO   rP   test_random_parfor  s    z"TestParforNumPy.test_random_parforc                 C   s^   dd }d}|  |t|f}||}||}tjj||dd | t|t	j
fd d S )Nc                 S   s   t jj| | fd}t j| | }t jdd| | f}t jd| | f}t jjdd| | fd}t jddd| | f}t || | | | | S Nr          r  r   r   )highr  r   )	r   r  standard_normalr   normal	chisquarer  
triangularr  r   r  r  r  r#  EFrO   rO   rP   rt    s    z/TestParforNumPy.test_randoms.<locals>.test_implr  g?)Zrtolr   )r   r   r   r   r   r   assert_allcloser   r   r   r  rN   rt  r   r   r   Z	py_outputrO   rO   rP   test_randoms  s    	
zTestParforNumPy.test_randomsc                 C   sX   dd }d}|  |t|f}||}||}| || | t|tjfd d S )Nc                 S   sv   t jj| | fd}t j| | }t jdd| | f}t jd| | f}t jjdd| | fd}t jddd| | f}dS r  )r   r  r  r   r  r  r  r  r  rO   rO   rP   rt    s    z4TestParforNumPy.test_dead_randoms.<locals>.test_implr  r   )r   r   r   r   r   r   r   r  r
  rO   rO   rP   test_dead_randoms  s    	
z!TestParforNumPy.test_dead_randomsc              
      sb  dd }dd }d}t j|}t jjd|dt j}t j||f}t t jt jg} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]Z}	 	|	t
jd d  f}
 t}|
t jg t jd	 W 5 Q R X  |t|j qƇ fd
d} ||  ||  ||  || d S )Nc                 S   s   |   S rR   r  r  rO   rO   rP   r  (  s    z,TestParforNumPy.test_min.<locals>.test_impl1c                 S   s
   t | S rR   )r   r  r  rO   rO   rP   r  +  s    z,TestParforNumPy.test_min.<locals>.test_impl2   r   r  zDzero-size array to reduction operation minimum which has no identityr  c                      s
     dS r  r  rO   rT   rO   rP   r  F  r  z*TestParforNumPy.test_min.<locals>.<lambda>r   r  r  r  astypeint32r%  infr   r   r   r  rw  r   r   r   r   rx  r   r   rN   r  r  r   r  r  r  r#  r   r   pcfuncer  rO   rT   rP   test_min'  s4     zTestParforNumPy.test_minc              
      sf  dd }dd }d}t j|}t jjd|dt j}t j||f}t t j t j g} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]Z}	 	|	t
jd d  f}
 t}|
t jg t jd	 W 5 Q R X  |t|j qʇ fd
d} ||  ||  ||  || d S )Nc                 S   s   |   S rR   )r  r  rO   rO   rP   r  M  s    z,TestParforNumPy.test_max.<locals>.test_impl1c                 S   s
   t | S rR   )r   r  r  rO   rO   rP   r  P  s    z,TestParforNumPy.test_max.<locals>.test_impl2r  r   r  zDzero-size array to reduction operation maximum which has no identityr  c                      s
     dS r  r  rO   rT   rO   rP   r  k  r  z*TestParforNumPy.test_max.<locals>.<lambda>r  r  rO   rT   rP   test_maxL  s4     zTestParforNumPy.test_maxc              
      sn  dd }dd }d}t dddd	dg}t jjd
|dt j}t j||f}t ddt jd	dg} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]Z}	 	|	t
jd d  f}
 t}|
t jg t jd W 5 Q R X  |t|j q҇ fdd} ||  ||  ||  || d S )Nc                 S   s   |   S rR   )r  r  rO   rO   rP   r  r  s    z/TestParforNumPy.test_argmax.<locals>.test_impl1c                 S   s
   t | S rR   )r   r  r  rO   rO   rP   r  u  s    z/TestParforNumPy.test_argmax.<locals>.test_impl2r  r  r   rm         @r   r  z*attempt to get argmax of an empty sequencer  c                      s
     dS r  r  rO   rT   rO   rP   r    r  z-TestParforNumPy.test_argmax.<locals>.<lambda>r   r%  r  r  r  r  r  nanr   r   r   r  rw  r   r   r   r   rx  r   r   r  rO   rT   rP   test_argmaxq  s4     zTestParforNumPy.test_argmaxc              
      sn  dd }dd }d}t ddddd	g}t jjd
|dt j}t j||f}t ddt jdd	g} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]Z}	 	|	t
jd d  f}
 t}|
t jg t jd W 5 Q R X  |t|j q҇ fdd} ||  ||  ||  || d S )Nc                 S   s   |   S rR   r  r  rO   rO   rP   r    s    z/TestParforNumPy.test_argmin.<locals>.test_impl1c                 S   s
   t | S rR   )r   r  r  rO   rO   rP   r    s    z/TestParforNumPy.test_argmin.<locals>.test_impl2r  r  r   r  rm  r   r  z*attempt to get argmin of an empty sequencer  c                      s
     dS r  r  rO   rT   rO   rP   r    r  z-TestParforNumPy.test_argmin.<locals>.<lambda>r  r  rO   rT   rP   test_argmin  s4     zTestParforNumPy.test_argminc                 C   sF   dd }t d}| || ttjddf}| t||d d S )Nc                 S   s   |  d | S N      @fillr   rO   rO   rP   rt    s    
z4TestParforNumPy.test_ndarray_fill.<locals>.test_implr   r   r  r   zerosr   r   r  r  r   r   rN   rt  r   r  rO   rO   rP   test_ndarray_fill  s
    
z!TestParforNumPy.test_ndarray_fillc                 C   sF   dd }t d}| || ttjddf}| t||d d S )Nc                 S   s   |  d | S r  r  r!  rO   rO   rP   rt    s    
z6TestParforNumPy.test_ndarray_fill2d.<locals>.test_implr   r   r   r  r   r"  r$  rO   rO   rP   test_ndarray_fill2d  s
    
z#TestParforNumPy.test_ndarray_fill2dc                 C   s@   dd }t ddddddd	d
ddddg}d}| ||| d S )Nc                 S   s^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S Nr   r  r   rG   r   r#  r  r  r   rp   rq   Zresult_matrixsub_azresult_datarO   rO   rP   rt    s    z<TestParforNumPy.test_reshape_with_neg_one.<locals>.test_implr  r  rm  rn        @      @r         @      "@      $@      &@rk  r   r   r%  r   rN   rt  rp   rq   rO   rO   rP   test_reshape_with_neg_one  s    
     z)TestParforNumPy.test_reshape_with_neg_onec                 C   s@   dd }t ddddddd	d
ddddg}d}| ||| d S )Nc                 S   s^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S )Nr   r  r   ir)  r*  rO   rO   rP   rt    s    z>TestParforNumPy.test_reshape_with_large_neg.<locals>.test_implr  r  rm  rn  r.  r/  r  r0  r1  r2  r3  rk  r   r4  r5  rO   rO   rP   test_reshape_with_large_neg  s    
     z+TestParforNumPy.test_reshape_with_large_negc                 C   st   |  tjH}tdddd }tddddd	d
ddddddg}d}||| W 5 Q R X d}| |t|j d S )NTparallelc                 S   s^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S r(  r)  )rp   rq   Zrmr+  r,  r-  rO   rO   rP   rt    s    zETestParforNumPy.test_reshape_with_too_many_neg_one.<locals>.test_implr  r  rm  rn  r.  r/  r  r0  r1  r2  r3  rk  r   z7The reshape API may only include one negative argument.)	rw  r   UnsupportedRewriteErrorr
   r   r%  r   r   rx  )rN   raisedrt  rp   rq   r   rO   rO   rP   "test_reshape_with_too_many_neg_one  s    

     z2TestParforNumPy.test_reshape_with_too_many_neg_onec                 C   s"   dd }| j |tddd d S )Nc                 S   s2   t | t |  t |  t |  t |  S rR   )r   r  prodr  r  r  r   rO   rO   rP   rt    s    z0TestParforNumPy.test_0d_array.<locals>.test_impl   Fr   )r   r   r%  r~  rO   rO   rP   test_0d_array  s    zTestParforNumPy.test_0d_arrayc                 C   sF   dd }t dd }| || | t|tjd d d fd d S )Nc                 S   s   t | jd | jd  S r  )r   r  realimag)r,  rO   rO   rP   rt    s    z6TestParforNumPy.test_real_imag_attr.<locals>.test_implrj   y      ?      ?r   )r   ro  r   r   r   r   r  )rN   rt  r,  rO   rO   rP   test_real_imag_attr
  s    z#TestParforNumPy.test_real_imag_attrN)rb   rJ   rc   r  r<   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r'  r6  r7  r<  r@  rC  rO   rO   rO   rP   r  z  s2   
	
%%$$		r  c                   @   s*   e Zd ZdZee dedd ZdS )TestParforsUnsupportedz$Tests for unsupported use of parforszOnly impacts 32 bit hardwarec              	   C   sr   |  tjF}tdddd }tddddd	}tddd	}||| W 5 Q R X d
}| |t|j	 dS )zu
        This test is in place until issues with the 'parallel'
        target on 32 bit hardware are fixed.
        Tr8  c                 S   s   t | |S rR   r  r  rO   rO   rP   ddot  s    zHTestParforsUnsupported.test_unsupported_combination_raises.<locals>.ddotr   r   r  r   r   zCThe 'parallel' target is not currently supported on 32 bit hardwareN)
rw  r   UnsupportedParforsErrorr
   r   r   r   r   r   rx  )rN   r;  rE  r  rf  r   rO   rO   rP   #test_unsupported_combination_raises  s    
z:TestParforsUnsupported.test_unsupported_combination_raisesN)	rb   rJ   rc   r  unittestskipIfr;   r<   rG  rO   rO   rO   rP   rD    s   rD  c                   @   sT  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zd d! Zd"d# Zed$d% Zed&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8dhdi Z9djdk Z:dldm Z;dndo Z<dpdq Z=drds Z>dtdu Z?dvdw Z@dxdy ZAdzd{ ZBd|d} ZCd~d ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdS )TestParforsz6 Tests cpython, reduction and various parfors featuresc                    s    dd }  | fdd d S )Nc                 S   s   | | | S rR   rO   )rp   r   r  rO   rO   rP   rt  /  s    z,TestParfors.test_arraymap.<locals>.test_implc                      s
     dS Nr   r  rO   rT   rO   rP   r  2  r  z+TestParfors.test_arraymap.<locals>.<lambda>)r   r~  rO   rT   rP   test_arraymap.  s    zTestParfors.test_arraymapc                 C   s(   dd }|  | | t|dd d S )Nc                  S   s"   t d} t d}t | | S )Nr   r      )r   r%  rs  r  r  r  rO   rO   rP   rt  5  s    

z0TestParfors.test_0d_broadcast.<locals>.test_implrO   r   r   r   r   r~  rO   rO   rP   test_0d_broadcast4  s    
zTestParfors.test_0d_broadcastc                 C   s(   dd }|  | | t|dd d S )Nc                  S   s"   t d} t d}t | | S NrM  )r   rs  r#  r  rO  rO   rO   rP   rt  =  s    

z-TestParfors.test_2d_parfor.<locals>.test_implrO   r   rP  r~  rO   rO   rP   test_2d_parfor<  s    
zTestParfors.test_2d_parforc                    s:   dd   fdd}dd } || || d S )Nc                  s   s"   t d} t d}| |fV  d S rR  r   rs  r#  rO  rO   rO   rP   case1E  s    

z)TestParfors.test_nd_parfor.<locals>.case1c                      s   t   dS r  )r	   r   rO   rU  rN   rO   rP   r  J  r  z,TestParfors.test_nd_parfor.<locals>.<lambda>c                 S   s   t | | S rR   r!  rO  rO   rO   rP   rt  L  s    z-TestParfors.test_nd_parfor.<locals>.test_impl)r   r   )rN   r  rt  rO   rV  rP   test_nd_parforD  s
    zTestParfors.test_nd_parforc                    s,   ddl m   fdd}d}| || d S )Nr   rs  c                    s    | }|d S rN  rO   r  rX  rO   rP   rt  T  s    z9TestParfors.test_np_func_direct_import.<locals>.test_implo   )r\  rs  r   rN   rt  r   rO   rX  rP   test_np_func_direct_importR  s    z&TestParfors.test_np_func_direct_importc              	   C   s^   dd }|  |dd | t}tdd|}|dd W 5 Q R X d}| |t|j d S )Nc                 S   s"   t | }t |}t || S rR   r  )r   r   r  r  rO   rO   rP   rt  [  s    

z2TestParfors.test_size_assertion.<locals>.test_implr   Tr8  	   zSizes of A, B do not match)r   rw  r   r
   r   r   rx  )rN   rt  rz  r   r   rO   rO   rP   test_size_assertionZ  s    zTestParfors.test_size_assertionc                 C   s6   dd }d}t j|}t |}| |||| d S )Nc                 S   sT   t dD ]D}t|| d |d | d D ] }d||< | | dkr,d||< q,q
|S )Nr   r   r   r   r   r   )r   is_positiver'  r   r  rO   rO   rP   rt  i  s    "z'TestParfors.test_cfg.<locals>.test_implr  )r   r  randr#  r   )rN   rt  r'  r   r_  rO   rO   rP   test_cfgg  s
    	
zTestParfors.test_cfgc              	   C   s.  dd }d}t j|}| || t jjd|dt j}| || dd }|   | | W 5 Q R X d}t jjd|dt j}dd }| || d	d }| ||d
 dd }| ||d
 | 	t
|tjd d d d f fd dd }| || | 	t
|tjd d  fd d S )Nc                 S   s   d}t dd | |S )Nr   c                 S   s
   t | |S rR   r  ro   rO   rO   rP   r  z  r  <TestParfors.test_reduce.<locals>.test_impl.<locals>.<lambda>r   )r  Zinit_valrO   rO   rP   rt  x  s    z*TestParfors.test_reduce.<locals>.test_implr  r   r  c               	   S   s$   dd } t | tdddddgdS )Nc                 S   s   | d S r  rO   r!  rO   rO   rP   r    r  rb  r   r   r   r   rj   )r   r   r%  )grO   rO   rP   rt    s       c                 S   s   t | | dk S rK  r!  r  rO   rO   rP   rt    s    c                 S   s&   | d d df }t | |dkdf S )Nr   r   r   r!  r  r  rO   rO   rP   rt    s    )   r   c                 S   s*   | d d df }t | |dkddf S )Nr   r   r   r   r!  re  rO   rO   rP   rt    s    r   c                 S   s   t | }| | S rR   )r   Zamin)r  Zmin_valrO   rO   rP   rt    s    
)r   r  r  r   r  r  r  ZassertTypingErrorr   r   r   r   r  rN   rt  r   r  rO   rO   rP   test_reducew  s*    
&zTestParfors.test_reducec              	   C   sD   dd }d}|  t}| |d}W 5 Q R X | |t|j d S )Nc                  S   s    d} t dD ]}t| } q| S rD  )r   cmathr  accr   rO   rO   rP   rt    s    z9TestParfors.test_use_of_reduction_var1.<locals>.test_implCUse of reduction variable acc in an unsupported reduction function.rO   rw  r   r   r   r   rx  rN   rt  r   r  r  rO   rO   rP   test_use_of_reduction_var1  s
    z&TestParfors.test_use_of_reduction_var1c              	   C   sF   dd }d}|  tj}| |d}W 5 Q R X | |t|j d S )Nc                  S   s   d} t dD ]}| d } q| S Nr  r   r   rj  rO   rO   rP   rt    s    
z9TestParfors.test_unsupported_floordiv1.<locals>.test_implzParallel floordiv reductions are not supported. If all divisors are integers then a floordiv reduction can in some cases be parallelized as a multiply reduction followed by a floordiv of the resulting product.rO   )rw  r   ZNumbaValueErrorr   r   r   rx  rn  rO   rO   rP   test_unsupported_floordiv1  s
    z&TestParfors.test_unsupported_floordiv1c              	   C   sD   dd }d}|  t}| |d}W 5 Q R X | |t|j d S )Nc                  S   s"   d} t dD ]}| |d N } q| S rp  rq  rj  rO   rO   rP   rt    s    z4TestParfors.test_unsupported_xor1.<locals>.test_implrl  rO   rm  rn  rO   rO   rP   test_unsupported_xor1  s
    z!TestParfors.test_unsupported_xor1c                 C   s2   dd }d}|  || | t|tjfd d S )Nc                 S   s   t | }| S rR   r  r  rO   rO   rP   rt    s    
z8TestParfors.test_parfor_array_access1.<locals>.test_implr  r   )r   r   rM  r   r  rZ  rO   rO   rP   test_parfor_array_access1  s    z%TestParfors.test_parfor_array_access1c                 C   s2   dd }d}|  || | t|tjfd d S )Nc                 S   sb   t | }d}d} tt|D ]}||| 7 }q tt|D ]}|| kr@| || 7 } q@||  S rN  )r   rs  r   r   r   r   r  r   r   rO   rO   rP   rt    s    
z8TestParfors.test_parfor_array_access2.<locals>.test_implr  r   r   r   r`  r   r  rZ  rO   rO   rP   test_parfor_array_access2  s    z%TestParfors.test_parfor_array_access2c              	   C   sF   dd }d}|  tj}| || W 5 Q R X | dt|j d S )Nc                 S   sB   t | t j}d}tt|D ]}||| 7 }|dkr |}q d S Nr   r   )r   rs  r  r   r   r   ru  rO   rO   rP   rt    s    z8TestParfors.test_parfor_array_access3.<locals>.test_implr  z Overwrite of parallel loop index)rw  r   r:  r   r   r   rx  )rN   rt  r   rz  rO   rO   rP   test_parfor_array_access3  s
    z%TestParfors.test_parfor_array_access3c                 C   s.  dd }d}d}t j||f}t j|}| ||| t|ttjddttjddf\}}| t	|j
dko~d|j
k |j
d }d	}	d }
|jD ]}t|tjjjrd
}	|}
q| |	 d	}|
j D ]N}|jD ]B}t|tjrt|jtjr|jjdkrd
}| |
j|jjk qq| | d S )Nc                 S   s   t | |S rR   r  )r  rq   rO   rO   rP   rt    s    z8TestParfors.test_parfor_array_access4.<locals>.test_implr  r   r   r  r   r   FTre  )r   r  r  r   rC  r   r  r  r   r   r=  rF  r   r   r9  r:  rG  rR  rX  r   rS  r]  r^  r   ra  r   )rN   rt  r   dr  rq   r@  rB  rJ  Zparfor_foundr:  rd  Zbuild_tuple_foundblrO   rO   rP   test_parfor_array_access4  s@     




z%TestParfors.test_parfor_array_access4c                 C   s"   dd }t d}| || d S )Nc                 S   s,   t t| D ]}| jd| |< q| d S Nr   r   )r   r   r   r  r   )rp   r   rO   rO   rP   rt  '  s    z5TestParfors.test_parfor_dtype_type.<locals>.test_implr   r  )rN   rt  rp   rO   rO   rP   test_parfor_dtype_type%  s    
z"TestParfors.test_parfor_dtype_typec                 C   s2   dd }d}|  || | t|tjfd d S )Nc                 S   s>   t | df}d}t| D ]}|||d d f  7 }q|S )Nr   r   )r   rs  r   r   r  r   r  r  r   rO   rO   rP   rt  1  s
    z8TestParfors.test_parfor_array_access5.<locals>.test_implr  r   rv  rZ  rO   rO   rP   test_parfor_array_access5/  s    z%TestParfors.test_parfor_array_access5c                 C   s"   dd }t d}| || d S )Nc                 S   s&   t dD ]}d| d  | d< q| d S )Nr   r   r   rq  )outr   rO   rO   rP   rt  ?  s    z8TestParfors.test_parfor_hoist_setitem.<locals>.test_implr   r  )rN   rt  r  rO   rO   rP   test_parfor_hoist_setitem<  s    
z%TestParfors.test_parfor_hoist_setitemc                 C   sV   dd }d}d}|  ||| | t|tjtjfd | t|tjtjfd d S )Nc                 S   sF   t |}t | |f}t | }tdD ]}| t || }q*|S rK  )r   rs  r   r  )r'  r#  r  r  r  r   r  rO   rO   rP   rt  J  s    

z8TestParfors.test_parfor_generate_fuse.<locals>.test_implr  r   r   )r   r   rZ  r   r  r   )rN   rt  r   rz  rO   rO   rP   test_parfor_generate_fuseG  s    	z%TestParfors.test_parfor_generate_fusec                 C   s>   dd }t dt j}t dt j}d|d< | ||| d S )Nc                 S   s   t | |S rR   )r   Zbitwise_andre  rO   rO   rP   rt  [  s    z.TestParfors.test_ufunc_expr.<locals>.test_implr   r   r   )r   rs  Zuint8r   )rN   rt  r  r  rO   rO   rP   test_ufunc_exprY  s
    zTestParfors.test_ufunc_exprc                 C   s"   dd }|  t|tjfd d S )Nc                 S   s(   t | f}t| D ]}|d ||< q|S )Nr  )unsafe_emptyr   r   r  r   rO   rO   rP   rt  d  s    
z;TestParfors.test_find_callname_intrinsic.<locals>.test_implr   )r   rZ  r   r  r~  rO   rO   rP   test_find_callname_intrinsicc  s    z(TestParfors.test_find_callname_intrinsicc                 C   s   dd }|  |d d S )Nc                 S   s4   d}t | D ]}|d7 }qt | D ]}|d7 }q"|S r   rq  r   rk  r   rO   rO   rP   rt  p  s    

z7TestParfors.test_reduction_var_reuse.<locals>.test_implrf  r}  r~  rO   rO   rP   test_reduction_var_reusen  s    	z$TestParfors.test_reduction_var_reusec                 C   s,   dd }|  |tdtdd d S )Nc                 S   s,   d}t | jd D ]}|| r|d7 }q|S Nr   r   r   r$  )r  condr  r   rO   rO   rP   rt  }  s
    
z8TestParfors.test_non_identity_initial.<locals>.test_implr   boolr   r   rs  r  r~  rO   rO   rP   test_non_identity_initial{  s    z%TestParfors.test_non_identity_initialc                 C   s,   dd }|  |tdtdd d S )Nc                 S   sF   d}d}t | jd D ]&}|| r4|d7 }|d7 }q|d7 }q|| S )Nr   r   r   r   r  )r  r  r  r  r   rO   rO   rP   rt    s    

z9TestParfors.test_if_not_else_reduction.<locals>.test_implr   r  r  r~  rO   rO   rP   test_if_not_else_reduction  s    
z&TestParfors.test_if_not_else_reductionc                 C   s   dd }|  |d d S )Nc                 S   sf   d}|d |d  }t |t j}t ||}t| D ]}||7 }q<t| D ]}||7 }qT|S N   ri   r   r   r   r#  int_ro  r   r   r   r   shpr  result1tmpr   rO   rO   rP   rt    s    

z?TestParfors.test_two_d_array_reduction_reuse.<locals>.test_implr  r}  r~  rO   rO   rP    test_two_d_array_reduction_reuse  s    z,TestParfors.test_two_d_array_reduction_reusec                 C   s   dd }|  |d d S )Nc                 S   s6   t dt j}t| D ]}|t |gt j7 }q|S r  )r   r#  r  r   r   r%  )r   resultr   rO   rO   rP   rt    s    z9TestParfors.test_one_d_array_reduction.<locals>.test_implr  r}  r~  rO   rO   rP   test_one_d_array_reduction  s    z&TestParfors.test_one_d_array_reductionc                 C   s   dd }|  |d d S )Nc                 S   sN   d}|d |d  }t |t j}t ||}t| D ]}||7 }q<|S r  r  r  rO   rO   rP   rt    s    
z9TestParfors.test_two_d_array_reduction.<locals>.test_implr  r}  r~  rO   rO   rP   test_two_d_array_reduction  s    z&TestParfors.test_two_d_array_reductionc                 C   s   dd }|  |d d S )Nc                 S   sJ   d}t |t j}t ddddddg|}t| D ]}||7 }q8|S )Nr   r  r  rm  rn  r.  r/  )r   r#  r  r%  r   r   r   r   r  r  r  r   rO   rO   rP   rt    s    
zJTestParfors.test_two_d_array_reduction_with_float_sizes.<locals>.test_implr  r}  r~  rO   rO   rP   +test_two_d_array_reduction_with_float_sizes  s    
z7TestParfors.test_two_d_array_reduction_with_float_sizesc                 C   s   dd }|  |d d S )Nc                 S   s@   d}dt |t j }dt | }t| D ]}||9 }q.|S )Nr  r   )r   rs  r  Z	ones_liker   r   r  rO   rO   rP   rt    s    
z>TestParfors.test_two_d_array_reduction_prod.<locals>.test_implr  r}  r~  rO   rO   rP   test_two_d_array_reduction_prod  s    
z+TestParfors.test_two_d_array_reduction_prodc                 C   s   dd }|  |d d S )Nc                 S   s8   d}t |t j}t| D ]}|t |t j7 }q|S )N)r   r   r>  )r   r#  r  r   r   rs  )r   r  r  r   rO   rO   rP   rt    s
    z;TestParfors.test_three_d_array_reduction.<locals>.test_implr  r}  r~  rO   rO   rP   test_three_d_array_reduction  s    	z(TestParfors.test_three_d_array_reductionc                 C   s&   dd }d}t |}| || d S )Nc                 S   s   |   d S r  )Zargsortr  rO   rO   rP   rt    s    z>TestParfors.test_preparfor_canonicalize_kws.<locals>.test_implr  r   ro  r   rg  rO   rO   rP   test_preparfor_canonicalize_kws  s    
z+TestParfors.test_preparfor_canonicalize_kwsc                 C   sH   dd }t dt d}| |t|f}| |||| d S )Nc                 S   s   | j S rR   r  r  rO   rO   rP   rt    s    z8TestParfors.test_preparfor_datetime64.<locals>.test_implr   zdatetime64[ns])r   r[  r  r   r   r   r   r   )rN   rt  r  r   rO   rO   rP   test_preparfor_datetime64  s    z%TestParfors.test_preparfor_datetime64c                 C   s    dd }|  |tjd d S )Nc                 S   sR   | j d }d}t|D ]6}dddh}|| d}|D ]}||7 }q6||7 }q|S )Nr   r   r   r   )r$  r   rV  )r  r   rk  r   Rr  r   rO   rO   rP   rt    s    




zITestParfors.test_no_hoisting_with_member_function_call.<locals>.test_implr  )r   r   r  r  r~  rO   rO   rP   *test_no_hoisting_with_member_function_call  s    z6TestParfors.test_no_hoisting_with_member_function_callc                 C   s   dd }|  | dS )z issue3671: X != 0 becomes an arrayexpr with operator.ne.
            That is turned into a parfor by devectorizing.  Make sure
            the return type of the devectorized operator.ne
            on integer types works properly.
        c                  S   s   t jdt jd} | dkS )Nr   r  r   )r   r#  r  r  rO   rO   rP   rt    s    z8TestParfors.test_array_compare_scalar.<locals>.test_implNr}  r~  rO   rO   rP   test_array_compare_scalar  s    z%TestParfors.test_array_compare_scalarc                 C   s(   dd }t d}| j||ddd d S )Nc                 S   s0   t | }| d| }|r(| d|d  }| S rx  )r   r  )r   Zhalfr  ZparrrO   rO   rP   rt    s
    z?TestParfors.test_array_analysis_optional_def.<locals>.test_implr  TFr?  r  rN   rt  r   rO   rO   rP    test_array_analysis_optional_def  s    
z,TestParfors.test_array_analysis_optional_defc              
   C   sd   dd }t jdtd}t jdtd}| ||| | t|ttjddttjddfd d S )Nc                 S   s`   t jt| t jd}t|}t|D ]}| | ||< q&t|D ]}|| ||  ||< qB|S r  )r   r[  r   r  r   r   )rp   rq   datar  r   rO   rO   rP   rt    s    z7TestParfors.test_prange_side_effects.<locals>.test_implr  r  r   r  )	r   ro  floatr   r   r   r   r  r  )rN   rt  r   r  rO   rO   rP   test_prange_side_effects  s    	z$TestParfors.test_prange_side_effectsc                 C   s"   dd }t d}| || d S )Nc                 S   s@   d}d}t t| D ]$}| |  |d |d  | 7  < q| S )Nrl  r>  r   r   )r   r   r   rp   Zatuprq   r   rO   rO   rP   rt  1  s
    "z*TestParfors.test_tuple1.<locals>.test_implr   r  r  rO   rO   rP   test_tuple10  s    
zTestParfors.test_tuple1c                 C   s"   dd }t d}| || d S )Nc                 S   s:   | j }d}tt| D ]}| |  |d | 7  < q| S )Nr>  r   )r$  r   r   r   r  rO   rO   rP   rt  <  s
    z*TestParfors.test_tuple2.<locals>.test_implr   r  r  rO   rO   rP   test_tuple2;  s    
zTestParfors.test_tuple2c                 C   s"   dd }t d}| || d S )Nc                 S   sN   t ddf}d}tt| D ](}| |  |d d |d  | 7  < q | S )Nr   r   r>  r   rj   r   )r   ro  r   r   r   r  rO   rO   rP   rt  G  s
    &z*TestParfors.test_tuple3.<locals>.test_implr   r  r  rO   rO   rP   test_tuple3F  s    
zTestParfors.test_tuple3c                 C   s"   dd }t d}| || d S )Nc                 S   sD   t ddd}d}tt| D ] }| |  |j|j | 7  < q| S Nr   r   rl   r>  )rk   r   r   r   rm   rn   rp   Zantuprq   r   rO   rO   rP   rt  R  s
    z/TestParfors.test_namedtuple1.<locals>.test_implr   r  r  rO   rO   rP   test_namedtuple1Q  s    
zTestParfors.test_namedtuple1c                    s0   t dd  fdd}td}| || d S )NTestNamedTuple2rl   c                    sD    ddd}d}t t| D ] }| |  |j|j | 7  < q| S r  )r   r   r   rm   rn   r  r  rO   rP   rt  ^  s
    z/TestParfors.test_namedtuple2.<locals>.test_implr   )r   r   ro  r   r  rO   r  rP   test_namedtuple2\  s    

zTestParfors.test_namedtuple2c                 C   sB   t ddg}dd }dd }|tdd}| j|||gd	 d S )
NTestNamedTuple3r  c                 S   s   d| j d d < d S )Nrj   r  r  rO   rO   rP   rt  m  s    z/TestParfors.test_namedtuple3.<locals>.test_implc                 S   s   t j| j|j d S rR   )r   r   r   r  ro   rO   rO   rP   r  p  s    z.TestParfors.test_namedtuple3.<locals>.comparerr   r  r  )r   r   r#  r   )rN   r  rt  r  r   rO   rO   rP   test_namedtuple3h  s
    zTestParfors.test_namedtuple3c              
   C   sd   dd }t dd }t dd }| ||| | t|ttjddttjddfd d S )Nc                 S   s   || 7 }|S rR   rO   ro   rO   rO   rP   rt  w  s    z1TestParfors.test_inplace_binop.<locals>.test_implr   r  r   r  )r   ro  r   r   r   r   r  r  rN   rt  r  r  rO   rO   rP   test_inplace_binopv  s    zTestParfors.test_inplace_binopc                 C   s&   dd }t ddg}| || d S )Nc                 S   sZ   t | }||f}tjd| d tjd}|dd d f }t| D ]\}}||||f< q@|S )Nr|  r  r   r   r   r#  Zuint64rE  rp   r   Zarray_shapeindicesZk_listr   rc  rO   rO   rP   rt    s    z0TestParfors.test_tuple_concat.<locals>.test_implr   r4  r  rO   rO   rP   test_tuple_concat  s    
zTestParfors.test_tuple_concatc                 C   s&   dd }t ddg}| || d S )Nc                 S   sb   t | }||f}tjd| d d d tjd}|dd d f }t| D ]\}}||||f< qH|S )Nr|  rG   r  r   r  r  rO   rO   rP   rt    s    zCTestParfors.test_tuple_concat_with_reverse_slice.<locals>.test_implr   r4  r  rO   rO   rP   $test_tuple_concat_with_reverse_slice  s    z0TestParfors.test_tuple_concat_with_reverse_slicec                 C   s"   dd }t d}| || d S )Nc                 S   s   | f| | f }|d   S rN  r  )rp   SrO   rO   rP   rt    s    z6TestParfors.test_array_tuple_concat.<locals>.test_implr   r   r  r  rO   rO   rP   test_array_tuple_concat  s    
z#TestParfors.test_array_tuple_concatc                 C   s"   dd }t d}| || d S )Nc                 S   s   | d S )Nr.  rO   r!  rO   rO   rP   rt    s    z3TestParfors.test_high_dimension1.<locals>.test_impl)r   r   r   r   r      r  r  rO   rO   rP   test_high_dimension1  s    
z TestParfors.test_high_dimension1c                 C   s$   dd }d}|  |t|| d S )Nc                 S   s   t |D ]}d| |< q
| S r  r   Zpndindexr   szr   rO   rO   rP   rt    s    
z-TestParfors.test_tuple_arg.<locals>.test_implr   rj   )r   r   r[  rN   rt  r  rO   rO   rP   test_tuple_arg  s    zTestParfors.test_tuple_argc                 C   s$   dd }d}|  |t|d d S )Nc                 S   s   t |D ]}d| |< q
| S r  r  r  rO   rO   rP   rt    s    
z=TestParfors.test_tuple_arg_not_whole_array.<locals>.test_implr  r   r   r   r   r#  r  rO   rO   rP   test_tuple_arg_not_whole_array  s    z*TestParfors.test_tuple_arg_not_whole_arrayc                 C   s"   dd }d}|  |t| d S )Nc                 S   s    d}t |D ]}d| |< q| S )Nr  r   r  r  rO   rO   rP   rt    s    
z6TestParfors.test_tuple_for_pndindex.<locals>.test_implr  r  r  rO   rO   rP   test_tuple_for_pndindex  s    z#TestParfors.test_tuple_for_pndindexc                 C   s$   dd }d}|  |t|d d S )Nc                 S   s$   |df}t |D ]}d| |< q| S r  r  )r   firstr  r   rO   rO   rP   rt    s    
z5TestParfors.test_tuple_arg_literal.<locals>.test_implr  r   r  r  rO   rO   rP   test_tuple_arg_literal  s    z"TestParfors.test_tuple_arg_literalc                    sX   dd dd  dd    fdd}t t d	d
fD ]}|| qFd S )Nc                 S   s   t |D ]}d| |< q
| S r  r  r  rO   rO   rP   rt    s    
z?TestParfors.test_tuple_of_literal_nonliteral.<locals>.test_implc                 S   s
   || dS )Nr  rO   )r   r   rO   rO   rP   r     s    z:TestParfors.test_tuple_of_literal_nonliteral.<locals>.callc                   S   s
   t dS )Nr  r   r#  rO   rO   rO   rP   r    r  z>TestParfors.test_tuple_of_literal_nonliteral.<locals>.<lambda>c                    s,   | }t  }| |}| d S rR   )r
   assertPreciseEqual)decf1f2gotr   expectedZ	get_inputrN   rt  rO   rP   r     s    z;TestParfors.test_tuple_of_literal_nonliteral.<locals>.checkTr8  r
   )rN   r   rz  rO   r  rP    test_tuple_of_literal_nonliteral  s    z,TestParfors.test_tuple_of_literal_nonliteralc                 C   s$   dd }d}|  |t|| d S )Nc                 S   s   t |D ]}d| |< q
| S r  r  r  rO   rO   rP   rt    s    
z0TestParfors.test_tuple_arg_1d.<locals>.test_implr   r  r  rO   rO   rP   test_tuple_arg_1d  s    zTestParfors.test_tuple_arg_1dc                 C   s"   dd }d}|  |t| d S )Nc                 S   s    d}t |D ]}d| |< q| S Nr  r   r  r  rO   rO   rP   rt    s    
z8TestParfors.test_tuple_arg_1d_literal.<locals>.test_implr  r  r  rO   rO   rP   test_tuple_arg_1d_literal  s    z%TestParfors.test_tuple_arg_1d_literalc                 C   s    dd }|  |tdd d S )Nc                 S   s   t |D ]}d| |< q
| S r  r  r  rO   rO   rP   rt    s    
z4TestParfors.test_int_arg_pndindex.<locals>.test_implr  r   r  r~  rO   rO   rP   test_int_arg_pndindex  s    z!TestParfors.test_int_arg_pndindexc                    sl   t dd   fdd}d}t||f}tjd d d d df tjf}| t||d | 	||| d S )Nc                 S   sF   t || d d d |d dD ] }| |d |f d | ||f< q d S Nr   r   r  )ur   Zevenr  r  rO   rO   rP   issue7854_proc  s    $z=TestParfors.test_prange_unknown_call1.<locals>.issue7854_procc                    sL   t d|d D ]} | |d| qt d|d D ]} | |d| q4| S r  r   r   )r  r  r   r  rO   rP   rt    s
    z8TestParfors.test_prange_unknown_call1.<locals>.test_implr   r   r   )
rA   r   r#  r   r  r   r  r   r   r   rN   rt  r  r  cptypesrO   r  rP   test_prange_unknown_call1  s    
z%TestParfors.test_prange_unknown_call1c                 C   s\   dd }d}t ||f}tjd d d d df tjf}| t||d | ||| d S )Nc                 S   s   t d|d D ]B}t|d d d |d dD ] }| |d |f d | ||f< q0qt d|d D ]>}t|d d |d dD ] }| |d |f d | ||f< qqd| S r  r^  )r  r  r   r  rO   rO   rP   rt    s       z6TestParfors.test_prange_index_calc1.<locals>.test_implr   r   r   	r   r#  r   r  r   r  r   r   r   r  rO   rO   rP   test_prange_index_calc1  s    	z#TestParfors.test_prange_index_calc1c                 C   s   dd }d}t ||f}t ||f}tjd d d d df tjd d d d df tjf}| t||d | |||| d S )Nc                 S   sp   t |D ]*}t|D ]}|||f d | ||f< qq
t |D ]}t|D ]}d|||f< qLq@| d |d  S )Nr   r   r  r^  )rp   rq   r  r   r  rO   rO   rP   rt  -  s    z9TestParfors.test_prange_reverse_order1.<locals>.test_implr   r   r   r  rN   rt  r  rp   rq   r  rO   rO   rP   test_prange_reverse_order1*  s    	4z&TestParfors.test_prange_reverse_order1c                 C   sN   dd }d}t |}tjd d  tjf}| t||d | ||| d S )Nc                 S   s<   d}t |D ]}|| |< qt |D ]}|| d 7 }q&|S )Nr   rj   r  )rp   r  rq   r   rO   rO   rP   rt  @  s    
z@TestParfors.test_prange_parfor_index_then_not.<locals>.test_implr   r   r  )rN   rt  r  rp   r  rO   rO   rP   !test_prange_parfor_index_then_not=  s    
z-TestParfors.test_prange_parfor_index_then_notc                 C   sf   dd }d}t |}t|}tjd d  tjtj|tjf}| 	t
||d | |||| d S )Nc                 S   sL   d}t |D ]}|||  | |< qt |D ]}|| | |d  7 }q.|S rD  r  )rp   tupr  rk  r   rO   rO   rP   rt  Q  s    zJTestParfors.test_prange_parfor_index_const_tuple_fusion.<locals>.test_implr   r   )r   r#  r   r   r  r   
containersZUniTupler  r   r   r   r  rO   rO   rP   +test_prange_parfor_index_const_tuple_fusionN  s    
z7TestParfors.test_prange_parfor_index_const_tuple_fusionc                 C   sf   dd }d}t |}t |}tjd d  tjd d  tjf}| t||d | |||| d S )Nc                 S   sL   t |D ]}| d ||< q
t |D ]}|| |< q&|d  | d 7  < |S )Nrj   r   r  )rp   rq   r  r   rO   rO   rP   rt  e  s    
zITestParfors.test_prange_non_parfor_index_then_opposite.<locals>.test_implr   r   r  r  rO   rO   rP   *test_prange_non_parfor_index_then_oppositeb  s    	

 z6TestParfors.test_prange_non_parfor_index_then_oppositec                 C   sF   ddd}t d}| j||d t jjdd gd | | d d S )	Nc                 S   s"   t dD ]}|d k	rd| |< qd S )Nr   r   rq  )arrpredr   rO   rO   rP   rt  v  s    z3TestParfors.test_prange_optional.<locals>.test_implr   c                 S   s   | |kS rR   rO   r   r  rO   rO   rP   r  ~  r  z2TestParfors.test_prange_optional.<locals>.<lambda>r  r2  )N)r   rs  r   r   r   r   r  rN   rt  r  rO   rO   rP   test_prange_optionalu  s    


z TestParfors.test_prange_optionalc              	   C   s>   dd }|  t}| | W 5 Q R X | dt|j d S )Nc                  S   s   d} | d S )Ng333333?g?r   rO   r  rO   rO   rP   rt    s    z8TestParfors.test_untraced_value_tuple.<locals>.test_implru  rv  ry  rO   rO   rP   test_untraced_value_tuple  s    z%TestParfors.test_untraced_value_tuplec              	   C   s>   dd }|  t}| | W 5 Q R X | dt|j d S )Nc                  S   s   d} | d d S )N)r  r   rO   r  rO   rO   rP   rt    s    zBTestParfors.test_recursive_untraced_value_tuple.<locals>.test_implru  rv  ry  rO   rO   rP   #test_recursive_untraced_value_tuple  s    z/TestParfors.test_recursive_untraced_value_tuplec                 C   sL   dd }t t jddf}| t||d tjdtjd}| || d S )Nc                 S   s   d}t | }t|tj}t|D ]}| | |d  ||< q"t |}t|tj}t|D ]}|| |d  ||< qZd}t |}	t|	D ]}
|||
 7 }q||d  S )Nr  r   r   r   r   r   r[  r  r   )r  rp   Zn1Zarr2r   Zn2Zarr3r  totalZn3r   rO   rO   rP   rt    s    z9TestParfors.test_untraced_value_parfor.<locals>.test_implr   r  r   r  )r   r  r  r   r   r   ro  r   )rN   rt  r  r  rO   rO   rP   test_untraced_value_parfor  s
    z&TestParfors.test_untraced_value_parforc                 C   s   dd }|  |td d S )Nc                 S   s<   d}t | jd D ]$}|r| d| |d d f< |d7 }q| S rD  )r   r$  )r   r   r   rO   rO   rP   rt    s    
z;TestParfors.test_setitem_2d_one_replaced.<locals>.test_impl)r   r   r  r~  rO   rO   rP   test_setitem_2d_one_replaced  s    
z(TestParfors.test_setitem_2d_one_replacedc                 C   sF   dd }t d}| ||dd | ||dd | ||dd d S )Nc                 S   s@   t | j}|r|t jS |r*|| }n||d  }|| j S r  )r   ro  r  r  r  )r  Zflag1Zflag2invretrO   rO   rP   rt    s    
z7TestParfors.test_1array_control_flow.<locals>.test_implr  TFr  r  rO   rO   rP   test_1array_control_flow  s
    

z$TestParfors.test_1array_control_flowc                 C   s6   dd }t d}| ||dd | ||dd d S )Nc                 S   s@   t | j}t || j| }|r,|| }n||d  }|| S r  r   ro  r  )r  r(  flaginv1inv2r  rO   rO   rP   rt    s    
z9TestParfors.test_2array_1_control_flow.<locals>.test_implr  r   TFr  r  rO   rO   rP   test_2array_1_control_flow  s    	
z&TestParfors.test_2array_1_control_flowc                 C   s6   dd }t d}| ||dd | ||dd d S )Nc                 S   sT   t | j}t || j| }|r4|| }|| }n||d  }||d  }|| S r  r  )r  r(  r  r  r  Zret1Zret2rO   rO   rP   rt    s    
z9TestParfors.test_2array_2_control_flow.<locals>.test_implr  r   TFr  r  rO   rO   rP   test_2array_2_control_flow  s    
z&TestParfors.test_2array_2_control_flowc                 C   s.   dd }|  |d | t|tjfd d S )Nc                 S   s   t j| t jd}t j| t jd}t| D ]"}t|D ]}||  d7  < q4q(t| D ]&}|dkrbqT|| ||d   ||< qT|dd  S )Nr  r   r   )r   r#  r  r   r   )r   rcr   r  rO   rO   rP   rt    s    z-TestParfors.test_issue8515.<locals>.test_implr  r   )r   r   r   r   r  r~  rO   rO   rP   test_issue8515  s    zTestParfors.test_issue8515c                 C   s4   dd }|  |dd | t|tjtjfd d S )Nc                 S   s8   t d}t|}t d}tt| |}|| | S Nr  )r   rs  r  ceilintr  )rp   rq   r  r  r
  rO   rO   rP   rt  	  s
    


z:TestParfors.test_fusion_no_side_effects.<locals>.test_implg@g333333@r   )r   r   r   r   r  r~  rO   rO   rP   test_fusion_no_side_effects 	  s    z'TestParfors.test_fusion_no_side_effectsN)Mrb   rJ   rc   r  rL  rQ  rS  rW  r[  r]  ra  rh  ro  rr  rs  rt  rw  ry  r<   r|  r~  r  r>   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO   rO   rO   rP   rJ  *  s   0
&





						

rJ  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestParforsLeaksc                 O   s.   | j |f| \}}| j|||f|| d S rR   r   r   rO   rO   rP   r   	  s    zTestParforsLeaks.checkc                 C   s4   t dddd }tdtj}| || d S )NTr8  c                 S   s   |   S rR   r  )r  rO   rO   rP   rt  	  s    z2TestParforsLeaks.test_reduction.<locals>.test_implr   r
   r   ro  r  r  r   r  rO   rO   rP   test_reduction	  s    
zTestParforsLeaks.test_reductionc                 C   s4   t dddd }tdtj}| || d S )NTr8  c                 S   s@   d}d}t | jD ]$}|| | 7 }|d| | d  7 }q|| S )Nr   r  r   )r   r  )r  rp   rq   r   rO   rO   rP   rt  	  s    z@TestParforsLeaks.test_multiple_reduction_vars.<locals>.test_implr   r  r  rO   rO   rP   test_multiple_reduction_vars	  s    
z-TestParforsLeaks.test_multiple_reduction_varsN)rb   rJ   rc   r   r  r  rO   rO   rO   rP   r  	  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d Z	e
dd Ze
dd Ze
dd Zdd Zdd Zdd Zdd Zdd Ze
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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9S ):TestParforsSlicec                 C   s   dd }|  |td d S )Nc                 S   s,   | j \}| d|d  | d|d   }|S Nr   r   r   r$  rp   r   rq   rO   rO   rP   rt  +	  s     z6TestParforsSlice.test_parfor_slice1.<locals>.test_implr   r   r   rs  r~  rO   rO   rP   test_parfor_slice1*	  s    z#TestParforsSlice.test_parfor_slice1c              	   C   sb   dd }|  |tdd | t }tdd|tdd W 5 Q R X | dt|j d S )Nc                 S   s(   | j \}| d|d  | d|  }|S r  r  rp   r   r   rq   rO   rO   rP   rt  3	  s    z6TestParforsSlice.test_parfor_slice2.<locals>.test_implr   r\  Tr8  do not match	r   r   rs  rw  r   r
   r   r   rx  ry  rO   rO   rP   test_parfor_slice22	  s
    $z#TestParforsSlice.test_parfor_slice2c                 C   s   dd }|  |td d S )Nc                 S   s>   | j \}}| d|d d|d f | d|d|f  }|S rD  r  r  rO   rO   rP   rt  @	  s    
0z6TestParforsSlice.test_parfor_slice3.<locals>.test_implr   r   r  r~  rO   rO   rP   test_parfor_slice3?	  s    z#TestParforsSlice.test_parfor_slice3c                 C   s   dd }|  |td d S )Nc                 S   s:   | j \}}| d d d|d f | d d d|f  }|S rD  r  r  rO   rO   rP   rt  H	  s    
,z6TestParforsSlice.test_parfor_slice4.<locals>.test_implr  r  r~  rO   rO   rP   test_parfor_slice4G	  s    z#TestParforsSlice.test_parfor_slice4c                 C   s   dd }|  |td d S )Nc                 S   s:   | j \}}| d|d d d f | d|d d f  }|S rD  r  r  rO   rO   rP   rt  P	  s    
,z6TestParforsSlice.test_parfor_slice5.<locals>.test_implr  r  r~  rO   rO   rP   test_parfor_slice5O	  s    z#TestParforsSlice.test_parfor_slice5c                 C   s   dd }|  |td d S )Nc                 S   s,   |   }| dd d f |d d df  }|S r  	transposerp   rq   r
  rO   rO   rP   rt  X	  s     z6TestParforsSlice.test_parfor_slice6.<locals>.test_implr  r  r~  rO   rO   rP   test_parfor_slice6W	  s    z#TestParforsSlice.test_parfor_slice6c              	   C   s^   dd }|  |td | t}tdd|td W 5 Q R X | dt|j d S )Nc                 S   s,   |   }| dd d f |dd d f  }|S r  r"  r$  rO   rO   rP   rt  `	  s     z6TestParforsSlice.test_parfor_slice7.<locals>.test_implr  Tr8  rl  r  r  ry  rO   rO   rP   test_parfor_slice7_	  s
    "z#TestParforsSlice.test_parfor_slice7c                 C   s$   dd }|  |tdd d S )Nc                 S   s:   | j \}}|  }| d|d|f |d|d|f< |S r  r$  r#  r  rO   rO   rP   rt  n	  s    
$z6TestParforsSlice.test_parfor_slice8.<locals>.test_implr\  r  r   r   ro  r   r~  rO   rO   rP   test_parfor_slice8l	  s    z#TestParforsSlice.test_parfor_slice8c                 C   s$   dd }|  |tdd d S )Nc                 S   s:   | j \}}|  }| d d d|f |d|d|f< |S r  r'  r  rO   rO   rP   rt  x	  s    
$z6TestParforsSlice.test_parfor_slice9.<locals>.test_implrN  rl  r(  r~  rO   rO   rP   test_parfor_slice9v	  s    z#TestParforsSlice.test_parfor_slice9c                 C   s$   dd }|  |tdd d S )Nc                 S   s2   | j \}}|  }| dd|f |dd|f< |S r  r'  r  rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice10.<locals>.test_implr\  r  r(  r~  rO   rO   rP   test_parfor_slice10	  s    z$TestParforsSlice.test_parfor_slice10c                 C   s$   dd }|  |tdd d S )Nc                 S   s@   | j \}}}|  }| d d dd|f |d d dd|f< |S r  r$  r   )rp   r   r   r(  rq   rO   rO   rP   rt  	  s    (z7TestParforsSlice.test_parfor_slice11.<locals>.test_impl   )r   r   r   r(  r~  rO   rO   rP   test_parfor_slice11	  s    z$TestParforsSlice.test_parfor_slice11c                 C   s$   dd }|  |tdd d S )Nc                 S   s2   | j \}}|  }| dd df |dddf< |S )Nr   r   rG   r,  r  rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice12.<locals>.test_implrN  rl  r(  r~  rO   rO   rP   test_parfor_slice12	  s    z$TestParforsSlice.test_parfor_slice12c                 C   s$   dd }|  |tdd d S )Nc                 S   s<   | j \}}|  }d}| d| |d f |dd|f< |S )NrG   r   r   r,  )rp   r   r   rq   r
  rO   rO   rP   rt  	  s
    
"z7TestParforsSlice.test_parfor_slice13.<locals>.test_implrN  rl  r(  r~  rO   rO   rP   test_parfor_slice13	  s    z$TestParforsSlice.test_parfor_slice13c                 C   s$   dd }|  |tdd d S )Nc                 S   s2   | j \}}|  }| dddf |dd df< |S )Nr   r   r   rG   r,  r  rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice14.<locals>.test_implrN  rl  r(  r~  rO   rO   rP   test_parfor_slice14	  s    z$TestParforsSlice.test_parfor_slice14c                 C   s$   dd }|  |tdd d S )Nc                 S   s8   | j \}}|  }| dddf |d|d  d f< |S )Nr   r2  r   r   r,  r  rO   rO   rP   rt  	  s    
"z7TestParforsSlice.test_parfor_slice15.<locals>.test_implrN  rl  r(  r~  rO   rO   rP   test_parfor_slice15	  s    z$TestParforsSlice.test_parfor_slice15c                 C   sZ   dd }|  |tdtdd tjdd tjdd tjf}| t||d dS )z This test is disabled because if n is larger than the array size
            then n and n-1 will both be the end of the array and thus the
            slices will in fact be of different sizes and unable to fuse.
        c                 S   s4   | j |j kstd| d|< d|d|d < | | S Nr   r   r   )r$  r   )rp   rq   r   rO   rO   rP   rt  	  s    z7TestParforsSlice.test_parfor_slice16.<locals>.test_implr      Nr   )	r   r   rs  r#  r   r  r  r   r   rN   rt  r|   rO   rO   rP   test_parfor_slice16	  s     z$TestParforsSlice.test_parfor_slice16c                 C   s    dd }|  |dtd d S )Nc                 S   s$   t | }t|}||| d < |S rR   r   r#  r   )r   r  r  r   rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice17.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_slice17	  s    z$TestParforsSlice.test_parfor_slice17c                 C   s   dd }|  | d S )Nc                  S   s*   t d} t dd| dd< | d }|S )Nr   r   r>  r   r6  r   )r   r#  ro  )rp   r  rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice18.<locals>.test_implr}  r~  rO   rO   rP   test_parfor_slice18	  s    z$TestParforsSlice.test_parfor_slice18c                 C   s   dd }|  |td d S )Nc                 S   s   | d d  d7  < | S rD  rO   r  rO   rO   rP   rt  	  s    z7TestParforsSlice.test_parfor_slice19.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_slice19	  s    z$TestParforsSlice.test_parfor_slice19c                 C   s   dd }| j |dd d S )Nc                  S   s"   t d} | dd  }t|}|S )Nr   r   )r   rs  r   )rp   r
  r  rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice20.<locals>.test_implFr?  r}  r~  rO   rO   rP   test_parfor_slice20	  s    z$TestParforsSlice.test_parfor_slice20c                 C   s2   dd }t jd}t jd}| ||| d S )Nc                 S   s4   |  | jd} | |jd}| |d dd d f kS )Nr   rG   )r   r  )x1x2rO   rO   rP   rt  	  s    z7TestParforsSlice.test_parfor_slice21.<locals>.test_implrj   r   )r   r  r`  r   rN   rt  r>  r?  rO   rO   rP   test_parfor_slice21	  s    z$TestParforsSlice.test_parfor_slice21c                 C   s.   dd }t d}t d}| ||| d S )Nc                 S   s0   t d}tdD ]}|| d d |f 7 }q|S r  )r   r#  r   )r>  r?  rq   r   rO   rO   rP   rt  	  s    
z7TestParforsSlice.test_parfor_slice22.<locals>.test_impl)r   r>  r   )r   r#  r%  r   r@  rO   rO   rP   test_parfor_slice22	  s    

z$TestParforsSlice.test_parfor_slice22c                 C   s   dd }|  |td d S )Nc                 S   s   d| d d< | S )Nr   r   rO   r!  rO   rO   rP   rt  
  s    z7TestParforsSlice.test_parfor_slice23.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_slice23
  s    z$TestParforsSlice.test_parfor_slice23c                 C   s2   dd }t ddD ]}| |dtd| qd S )Nc                 S   s*   t | }||d  }|d t| }|S rR   r9  r   r  r   r  r  rO   rO   rP   rt  
  s    
z7TestParforsSlice.test_parfor_slice24.<locals>.test_implr  r   r   r   r   rs  rN   rt  r   rO   rO   rP   test_parfor_slice24

  s    z$TestParforsSlice.test_parfor_slice24c                 C   s2   dd }t ddD ]}| |dtd| qd S )Nc                 S   s*   t | }|d | }|d t| }|S rR   r9  rD  rO   rO   rP   rt  
  s    
z7TestParforsSlice.test_parfor_slice25.<locals>.test_implrE  r  r   rF  rG  rO   rO   rP   test_parfor_slice25
  s    z$TestParforsSlice.test_parfor_slice25c                 C   s   dd }|  |td d S )Nc                 S   s.   | j \}|  }| dd ||d  d < |S )Nr2  r   r   r,  r  rO   rO   rP   rt  
  s    z7TestParforsSlice.test_parfor_slice26.<locals>.test_implr   r   r   ro  r~  rO   rO   rP   test_parfor_slice26
  s    z$TestParforsSlice.test_parfor_slice26c                 C   s   dd }|  |td d S )Nc                 S   s@   d}t | jd D ](}| | dkr*|d7 }|r| d | }qdS rD  r  )rp   Zn_valid_valsr   ZunusedrO   rO   rP   rt  *
  s    z7TestParforsSlice.test_parfor_slice27.<locals>.test_implr   rJ  r~  rO   rO   rP   test_parfor_slice27'
  s    z$TestParforsSlice.test_parfor_slice27c                    s   t ddd t dd d t d ddt d d d t d d dfD ]P  fdd}d}| || t|d	 |d	f} fd
d}| || q6d S )Nr   r   r   rG   r/  c                    sD   t | d | df}d}t| D ]}||| f  7 }q&|S Nr   r   )r   ro  r   r   r   r  r  tsrO   rP   rt  <
  s
    zHTestParforsSlice.test_parfor_array_access_lower_slice.<locals>.test_implr   r   c                    s2   d}t | jd D ]}|| | f  7 }q|S rN  )r   r   r$  r  )r  r  r   rN  rO   rP   rt  H
  s    )slicer   r   ro  r   rN   rt  r   r  rO   rN  rP   $test_parfor_array_access_lower_slice8
  s    
 
z5TestParforsSlice.test_parfor_array_access_lower_sliceN) rb   rJ   rc   r  r  r  r   r!  r%  r&  r>   r)  r*  r+  r.  r0  r1  r3  r4  r8  r:  r;  r<  r=  rA  rB  rC  rH  rI  rK  rL  rR  rO   rO   rO   rP   r  '	  s@   
	
	
			
		
	




	r  c                   @   s   e Zd Zdd ZdS )TestParforsOptionsc                 C   s   dd }|  |td tjd d  f}| t||d | t||ddd | t||dddd	 | t||dddd
d | t||dddddd | t||ddddddd | t||dddddddd d S )Nc                 S   sr   | j d }t|}tdd t|D }| ||  |d |< t|D ]}|| | |  ||< qHtdd |dS )Nr   c                 S   s   g | ]}|qS rO   rO   r   rO   rO   rP   r   X
  s     zMTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<listcomp>c                 S   s   | | S rR   rO   r  rO   rO   rP   r  \
  r  zKTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<lambda>)r$  r   rs  r%  r   r   r   )rp   r   rq   r
  r   rO   rO   rP   rt  U
  s    

z9TestParforsOptions.test_parfor_options.<locals>.test_implr   r   F)fusionr   )rT  comprehensionrj   )rT  rU  setitemr   )rT  rU  rV  r   r   )rT  rU  rV  r   	reductionr   )rT  rU  rV  r   rW  r\  r   )r   r   rs  r   r  r   r   r7  rO   rO   rP   test_parfor_optionsT
  sP    	        z&TestParforsOptions.test_parfor_optionsN)rb   rJ   rc   rX  rO   rO   rO   rP   rS  Q
  s   rS  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 )TestParforsBitMaskc                 C   s    dd }|  |tdd d S )Nc                 S   s   | |k}d| |< | S rN  rO   r  rO   rO   rP   rt  {
  s    z:TestParforsBitMask.test_parfor_bitmask1.<locals>.test_implr   rj   rJ  r~  rO   rO   rP   test_parfor_bitmask1z
  s    z'TestParforsBitMask.test_parfor_bitmask1c                 C   s,   dd }t d}|dk}| ||| d S )Nc                 S   s   d| |< | S rN  rO   ro   rO   rO   rP   rt  
  s    z:TestParforsBitMask.test_parfor_bitmask2.<locals>.test_implr   rj   r  r5  rO   rO   rP   test_parfor_bitmask2
  s    
z'TestParforsBitMask.test_parfor_bitmask2c                 C   s,   dd }t d}|dk}| ||| d S )Nc                 S   s   | | | |< | S rR   rO   ro   rO   rO   rP   rt  
  s    z:TestParforsBitMask.test_parfor_bitmask3.<locals>.test_implr   rj   r  r5  rO   rO   rP   test_parfor_bitmask3
  s    
z'TestParforsBitMask.test_parfor_bitmask3c                 C   s,   dd }t d}|dk}| ||| d S )Nc                 S   s   d|  | | |< | S r  rO   ro   rO   rO   rP   rt  
  s    z:TestParforsBitMask.test_parfor_bitmask4.<locals>.test_implr   rj   r  r5  rO   rO   rP   test_parfor_bitmask4
  s    
z'TestParforsBitMask.test_parfor_bitmask4c                 C   s,   dd }t d}|dk}| ||| d S )Nc                 S   s   | | | |  | |< | S rR   rO   ro   rO   rO   rP   rt  
  s    z:TestParforsBitMask.test_parfor_bitmask5.<locals>.test_implr   rj   r  r5  rO   rO   rP   test_parfor_bitmask5
  s    
z'TestParforsBitMask.test_parfor_bitmask5c              	   C   sd   dd }t d}|dk}t t|}| t}| |||| W 5 Q R X | dt|j	 d S )Nc                 S   s   || |< | S rR   rO   r$  rO   rO   rP   rt  
  s    z:TestParforsBitMask.test_parfor_bitmask6.<locals>.test_implr   rj   ru  )
r   ro  r#  r  rw  r   r   r   r   rx  )rN   rt  rp   rq   r
  rz  rO   rO   rP   test_parfor_bitmask6
  s    
z'TestParforsBitMask.test_parfor_bitmask6N)	rb   rJ   rc   rZ  r[  r\  r]  r^  r_  rO   rO   rO   rP   rY  w
  s   				rY  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dd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zed(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestParforsMiscz?
    Tests miscellaneous parts of ParallelAccelerator use.
    c              	   C   s   dd }t ddd|}tjdd:}td tjddd	 tjdd
tjjdd |  W 5 Q R X | t	|d dd |j
 D }| |dg d S )Nc                  S   s.   t d} t| jD ]}| |  |7  < q| S r  )r   rs  r   r  )r  r   rO   rO   rP   r   
  s    
z9TestParforsMisc.test_no_warn_if_cache_set.<locals>.pyfuncT)r9  cacherecordalwaysignoreZ	typeguard)actionmodulez.*TBB_INTERFACE_VERSION.*znumba\.np\.ufunc\.parallel.*)rf  messagecategoryrg  r   c                 S   s   g | ]}|j jqS rO   )r   has_dynamic_globals)r   r   rO   rO   rP   r   
  s   z=TestParforsMisc.test_no_warn_if_cache_set.<locals>.<listcomp>F)r
   warningscatch_warningssimplefilterfilterwarningsr   r   ZNumbaWarningr   r   Z	overloadsrX  )rN   r   r   raised_warningsrj  rO   rO   rP   test_no_warn_if_cache_set
  s$    
z)TestParforsMisc.test_no_warn_if_cache_setc              	   C   sP   dd }|  |d}t }|  W 5 Q R X |  D ]}| d| q:d S )Nc                  S   s>   t d} t dd| dd< td| d  td| d  | S )Nr   r   r>  r   r6  za[3]:r   )r   r#  ro  printr  rO   rO   rP   r   
  s
    
zITestParforsMisc.test_statement_reordering_respects_aliasing.<locals>.implrO   z	a[3]: 2.0)r   r5   r   getvaluer   r   )rN   r   r   stdoutlinerO   rO   rP   +test_statement_reordering_respects_aliasing
  s    z;TestParforsMisc.test_statement_reordering_respects_aliasingc                 C   sf   dd }t t jdg}tdd|}tjjj}z$dtjj_t j	|||| W 5 |tjj_X d S )Nc                 S   s
   t | S rR   )r   isinfr  rO   rO   rP   rt  
  s    z;TestParforsMisc.test_parfor_ufunc_typing.<locals>.test_implr   Tr8  )
r   r%  r  r
   r   r9  r:  sequential_parfor_loweringr   Zassert_array_equal)rN   rt  r  r   Zold_seq_flagrO   rO   rP   test_parfor_ufunc_typing
  s    

z(TestParforsMisc.test_parfor_ufunc_typingc                 C   s   dd }|  t|dd d S )Nc                  S   sJ   d} dddddg}t jj  |}t dD ]}| || 7 } q,| |d  S )Nr   r   r   r   r   rj   )r   r9  r:  Zinit_pranger   )resr  dummyr   rO   rO   rP   rt  
  s    z6TestParforsMisc.test_init_block_dce.<locals>.test_implrO   r   )r   rP  r~  rO   rO   rP   test_init_block_dce
  s    	z#TestParforsMisc.test_init_block_dcec                 C   s   dd }|  | d S )Nc                  S   s*   d} t dD ]}| d7 } qt| f}|S )Nr   r   r   r   r   r#  )rk  rH   r  rO   rO   rP   rt    s
    
zBTestParforsMisc.test_alias_analysis_for_parfor1.<locals>.test_implr}  r~  rO   rO   rP   test_alias_analysis_for_parfor1   s    z/TestParforsMisc.test_alias_analysis_for_parfor1c              	      s   d t dddG  fdddtG fdddt}td|d	d
d }| tjjj | 	t
j}|  W 5 Q R X |  t|j | tjjj d S )N
BROKEN_MSGTF)Zmutates_CFGZanalysis_onlyc                       s$   e Zd ZdZdd Z fddZdS )zVTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsZbreak_parforsc                 S   s   t |  d S rR   )r2   rz   rT   rO   rO   rP   rz     s    z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.__init__c                    sR   |j j D ]@}|jD ]0}t|tjjjrG  fdddt	}| |_
q dS d S )Nc                       s   e Zd Z fddZdS )zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Brokenc                    s   t  d S rR   )r   LoweringError)rN   otherr~  rO   rP   
difference%  s    zzTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Broken.differenceN)rb   rJ   rc   r  rO   r  rO   rP   Broken#  s   r  T)r+  r=  rX  rF  r   r   r9  r:  rG  r   Zraces)rN   r3  Zblkrd  r  r  rO   rP   run_pass  s    

z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_passN)rb   rJ   rc   _namerz   r  rO   r  rO   rP   BreakParfors  s   r  c                       s   e Zd Z fddZdS )z^TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompilerc                    s&   t | j}| t |  |gS rR   )r0   Zdefine_nopython_pipeliner3  Zadd_pass_afterr3   finalize)rN   pmr  rO   rP   define_pipelines.  s    zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompiler.define_pipelinesN)rb   rJ   rc   r  rO   r  rO   rP   BreakParforsCompiler,  s   r  )r9  Zpipeline_classc                  S   s   d} t dD ]}| d7 } q| S r  rq  )r   rH   rO   rO   rP   foo5  s    
zMTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.foo)r1   r2   r/   r
   assertFalser   r9  r:  rw  rw  r   r  r   r   rx  )rN   r  r  rz  rO   )r~  r  rP   0test_no_state_change_in_gufunc_lowering_on_error  s    
	

z@TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_errorc                    s   G dd dt j}|dt|tj G dd dt}t|fdd}t|dd	 }t	|d
ddiddd }t
dd  t
 fdd}tjjj}| | z||  | tjjj W 5 |tjj_X d S )Nc                   @   s   e Zd ZdS )z2TestParforsMisc.test_issue_5098.<locals>.DummyTypeNrb   rJ   rc   rO   rO   rO   rP   	DummyTypeH  s   r  Zmy_dummyc                   @   s   e Zd ZdS )z.TestParforsMisc.test_issue_5098.<locals>.DummyNr  rO   rO   rO   rP   DummyN  s   r  c                    s    S rR   rO   )valr
  )
dummy_typerO   rP   typeof_DummyQ  s    z5TestParforsMisc.test_issue_5098.<locals>.typeof_Dummyc                 S   s   t |j S rR   )r    contextZget_dummy_value)typobjr
  rO   rO   rP   unbox_indexU  s    z4TestParforsMisc.test_issue_5098.<locals>.unbox_indexmethod1r9  T)Zjit_optionsc                 S   s   dd }|S )Nc                 S   sp   dd }t |}tj|tjd}t|D ]}||| |||< q(t|d D ]}||  ||| |7  < qL|S )Nc                 S   s    |   }tj|t| < ||S rR   )r   r   r  rv  )rp   fr
  rO   rO   rP   baz\  s    zPTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foo.<locals>.bazr  r   r  )r  r  r   r  lengthZ
output_arrr   rO   rO   rP   _foo[  s    zCTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foorO   )r  r  r   r  rO   rO   rP   _get_method1Y  s    z5TestParforsMisc.test_issue_5098.<locals>._get_method1c                 S   s   |   S rR   r  )rf  rO   rO   rP   barj  s    z,TestParforsMisc.test_issue_5098.<locals>.barc                    s"   |  tdddgdddgg S )Nr  r  rm  rn  r.  r/  )r  r   r%  )rz  )r  rO   rP   test1n  s    z.TestParforsMisc.test_issue_5098.<locals>.test1)r   ZOpaquer   r!   ZOpaqueModelobjectr   registerr   r   r
   r   r9  r:  rw  r  )rN   r  r  r  r  r  r  Z
save_staterO   )r  r  rP   test_issue_5098G  s(    





zTestParforsMisc.test_issue_5098c              
   C   sn   t dddd }tdd& | tj}|d W 5 Q R X W 5 Q R X t|j}| d| | d	| d S )
NTr8  c                 S   s&   d}d}t dD ]}|||  7 }q|S )N)r   r   r   r   r   r   rq  )idxZbig_tupr,  r   rO   rO   rP   oversize_tuple~  s
    zMTestParforsMisc.test_oversized_tuple_as_arg_to_kernel.<locals>.oversize_tupleZNUMBA_PARFOR_MAX_TUPLE_SIZE3r   zUse of a tuplezin a parallel region)r
   r7   rw  r   rF  r   rx  r   )rN   r  rz  ZerrstrrO   rO   rP   %test_oversized_tuple_as_arg_to_kernel|  s    

z5TestParforsMisc.test_oversized_tuple_as_arg_to_kernelc                 C   sB   dd }d}t jjdd|d}t jjdd|d}| ||| d S )Nc                 S   s~   d}t j| j|| jd}| j}t|d D ]N}t|d D ]<}| ||f |||f  | ||f |||f   |||f< q:q*|S Nr   r  r   )r   fullr$  r  r   )Zimg_nirZimg_red	fillvalueZout_imgZdimsr  r   rO   rO   rP   	ndvi_njit  s    z1TestParforsMisc.test_issue5167.<locals>.ndvi_njit)r   r   r  g     @)lowr  r  )r   r  uniformr   )rN   r  Z
tile_shapeZarray1Zarray2rO   rO   rP   test_issue5167  s
    
zTestParforsMisc.test_issue5167c                 C   s^   dd }t dd }tjjdd}t dd|| |d	}|| |d	}tj|| d S )
Nc                 S   s   t j| jd | jd ft jd}t| jd D ]N}t|d | jd D ]4}|| | | | f| }||||f< ||||f< qFq.|S r  )r   r#  r$  r  r   r   )rp   r   	dist_argsr  r   r  rz  rO   rO   rP   
reproducer  s     z2TestParforsMisc.test_issue5065.<locals>.reproducerc                 S   s:   d}t | jd D ]}|| | ||  d 7 }qt|S )Nr   r   r   )r   r$  r   r  )r   r  r  r   rO   rO   rP   	euclidean  s    z1TestParforsMisc.test_issue5065.<locals>.euclidean)rj   r   r  Tr8  rO   )r
   r   r  r   r   r	  )rN   r  r  rp   r  r  rO   rO   rP   test_issue5065  s    	
zTestParforsMisc.test_issue5065c                 C   s,   dd }t dt df}| || d S )Nc                 S   s4   dgt |  }tt | D ]}t | | ||< q|S rN  )r   r   )myarrayr  r   rO   rO   rP   test_numba_parallel  s    z;TestParforsMisc.test_issue5001.<locals>.test_numba_parallelr  2   )r   r[  r   )rN   r  r  rO   rO   rP   test_issue5001  s    zTestParforsMisc.test_issue5001c                    s6   t dd  t dd fdd}|dgfd  d S )	Nc                 S   s   d S rR   rO   )gridsrO   rO   rP   r    s    z+TestParforsMisc.test_issue3169.<locals>.fooTr8  c                    s   t dD ]} |  qd S r  rq  )r  r   r  rO   rP   r    s    z+TestParforsMisc.test_issue3169.<locals>.barr   r   r  )rN   r  rO   r  rP   test_issue3169  s
    
zTestParforsMisc.test_issue3169c                    sD   t dd} fdd}tdddd  |d	d
d}| || d S )Nmytypero   c                    s   t dD ]} ||  q| jS rK  )r   rp   )mydatar   innerrO   rP   outer  s    z-TestParforsMisc.test_issue4846.<locals>.outerT)Znogilc                 S   s   | |j f}| |jf}d S rR   ro   )r   r  r  rc  rO   rO   rP   r    s    
z-TestParforsMisc.test_issue4846.<locals>.innerrp   rq   )r   r
   r   )rN   r  r  r  rO   r  rP   test_issue4846  s    

zTestParforsMisc.test_issue4846c                 C   s   dd }|  | d S )Nc                  S   s*   d} d}t t| D ]}|| | 7 }q|S )N)r   r   r   r   rj   r   )r   r   )r   rp   r   rO   rO   rP   test1b  s
    z.TestParforsMisc.test_issue3748.<locals>.test1br}  )rN   r  rO   rO   rP   test_issue3748  s    zTestParforsMisc.test_issue3748c                 C   s,   dd }d}t j|td}| ||| d S )Nc                 S   s<   t | d D ]*}t | d D ]}|d | || |< qq|S )Nr   r   g      @rq  )r  r  r   r  rO   rO   rP   parallel_test  s    z5TestParforsMisc.test_issue5277.<locals>.parallel_testr  r  )r   r#  r  r   )rN   r  r  r  rO   rO   rP   test_issue5277  s    zTestParforsMisc.test_issue5277c                 C   sL   t dddd }td}d}td}| |||||||| d S )NTr8  c                 S   s8   t dD ]}tdD ]}d|||f< qq|r4|d7 }|S r  )r   r   )r   methodr  r   r  rO   rO   rP   r    s    z5TestParforsMisc.test_issue5570_ssa_races.<locals>.foo)rj   rj   9   r&  )r
   r   r#  r  py_func)rN   r  r   r  r  rO   rO   rP   test_issue5570_ssa_races  s    



z(TestParforsMisc.test_issue5570_ssa_racesc                 C   sD   t dddd }tjd tjd}| |||| d S )NTr8  c                 S   s4   | }t ddD ]}||d d d d f }qt|S )Nr   r   )r   r   r  )r|   packagerh  Zz_stackrO   rO   rP   find_maxima_3D_jit  s    zDTestParforsMisc.test_issue6095_numpy_max.<locals>.find_maxima_3D_jitr   )r   r   r   )r
   r   r  r  r  r  )rN   r  r|   rO   rO   rP   test_issue6095_numpy_max  s    
z(TestParforsMisc.test_issue6095_numpy_maxc                 C   sJ   dd }d}d}t j||ft jd}t j||ft jd}| ||| d S )Nc                 S   sP   | j }|d }t|D ]4}| |d d f ||d d f< ||df  d7  < q|S rD  )r$  r   )gggg_nextgsrz  i_ggrO   rO   rP   rt  !  s    z3TestParforsMisc.test_issue5942_1.<locals>.test_implr   r   r  )r   r#  r  r   )rN   rt  rz  r   r  r  rO   rO   rP   test_issue5942_1  s    	z TestParforsMisc.test_issue5942_1c                 C   s"   dd }d}d}|  ||| d S )Nc                 S   s   t j| |ft jd}t j| |ft jd}t| D ]N}t|D ]}||||f< q<||d d f ||d d f< ||df  d7  < q0|S )Nr  r   r   )r   r#  r  r   r   )rz  r   r  r  r  r   rO   rO   rP   rt  3  s    z3TestParforsMisc.test_issue5942_2.<locals>.test_implr   r   r}  )rN   rt  rz  r   rO   rO   rP   test_issue5942_21  s    z TestParforsMisc.test_issue5942_2c                 C   sF   t dddd }tdddgdddgg}| |||| d S )NTr8  c                 S   s   t | jd D ]}tj}tjdddgtjd}dD ]B}tj| |d d f | }||k r2|}tj|||gtjd}q2| |d d f  |7  < q| S )Nr   r  )r   r   rG   )r   r$  r   r  r%  r  r  Znorm)r	  r   r   trr   Zdist_trO   rO   rP   r  H  s    z)TestParforsMisc.test_issue6102.<locals>.fr   r  )r
   r   r%  r  r  )rN   r  r	  rO   rO   rP   test_issue6102D  s    
zTestParforsMisc.test_issue6102c                 C   s    t dddd }| | d S )NTr8  c                  S   sP   d} t | f}t | d f}tt|D ]}t |||d  ||< q,|S r  )r   rs  r[  r   r   r  )r   Zna_maskr  r   rO   rO   rP   rt  Y  s    z1TestParforsMisc.test_issue6774.<locals>.test_impl)r
   r   r~  rO   rO   rP   test_issue6774X  s    
zTestParforsMisc.test_issue6774c                 C   s   dd }|  | d S )Nc                  S   s   t ttf} | S rR   )r   r#  _GLOBAL_INT_FOR_TESTING1_GLOBAL_INT_FOR_TESTING2bufrO   rO   rP   rt  e  s    z9TestParforsMisc.test_issue4963_globals.<locals>.test_implr}  r~  rO   rO   rP   test_issue4963_globalsd  s    z&TestParforsMisc.test_issue4963_globalsc                    s$   d d fdd}|  | d S )Nri   rj   c                     s   t  f} | S rR   r  r  Z_FREEVAR_INT_FOR_TESTING1Z_FREEVAR_INT_FOR_TESTING2rO   rP   rt  m  s    z:TestParforsMisc.test_issue4963_freevars.<locals>.test_implr}  r~  rO   r  rP   test_issue4963_freevarsj  s    z'TestParforsMisc.test_issue4963_freevarsN)rb   rJ   rc   r  rp  ru  rx  r{  r}  r  r  r  r  r  r  r  r>   r  r  r  r  r  r  r  r?   r  r  r  r  rO   rO   rO   rP   r`  
  s4   <5

r`  c                   @   sn   e Zd Zdd Zdd Zdd Z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S )TestParforsDiagnosticsc                 O   s.   | j |f| \}}| j|||f|| d S rR   r   r   rO   rO   rP   r   v  s    zTestParforsDiagnostics.checkc                 C   s$   |  |}|  |}| || d S rR   )_fusion_equivalentr   )rN   r  r  rp   rq   rO   rO   rP   assert_fusion_equivalencez  s    

z0TestParforsDiagnostics.assert_fusion_equivalencec                    sH   t t}t|  t| D ]"} fdd|| D ||  < q |S )Nc                    s   g | ]}|  qS rO   rO   r   Zmin_keyrO   rP   r     s     z=TestParforsDiagnostics._fusion_equivalent.<locals>.<listcomp>)r   r   r  keyssorted)rN   thingnewr   rO   r  rP   r    s
     z)TestParforsDiagnostics._fusion_equivalentNc              	   C   s   |d k	r|  ||  |d k	r.| ||j |d k	rD| ||j |d k	r|j }|D ]2}|D ]}	|	d |krb qZqbd||f }
t|
qZ|d k	r| }|  |t	| t
   tddD ]}|| qW 5 Q R X d S )Nr   z(Replacement for %s was not found. Had %sr   rj   )r   Zcount_parforsr  fusion_infonested_fusion_infor;  rX  r   hoisted_allocationsr   r5   r   dump)rN   r/  parfors_countr  r  r;  r  replr   Zreplacedr   hoisted_allocsrO   rO   rP   assert_diagnostics  s,    

z)TestParforsDiagnostics.assert_diagnosticsc                 C   sD   dd }|  | | |d}|jd }| j|ddddgid	 d S )
Nc                  S   s    d} t | }t | }|| S Nr   rT  r   rp   rq   rO   rO   rP   rt    s    

z9TestParforsDiagnostics.test_array_expr.<locals>.test_implrO   parfor_diagnosticsr   r   r   rj   )r  r  r   r   r<  r  rN   rt  r   r/  rO   rO   rP   test_array_expr  s    


z&TestParforsDiagnostics.test_array_exprc                 C   s:   dd }|  | | |d}|jd }| j|dd d S )Nc                  S   s,   d} t | }t| D ]}|d ||< q|S r  r   r[  r   )r   rp   r   rO   rO   rP   rt    s
    
z5TestParforsDiagnostics.test_prange.<locals>.test_implrO   r  r   r  r  r  rO   rO   rP   test_prange  s
    

z"TestParforsDiagnostics.test_prangec                 C   sF   dd }|  | | |d}|jd }| tdd |jD  dS )zEmake sure original user variable name is used in fusion info
        c                  S   sj   d} t | }t |}t || }d}t| d D ].}t| d D ]}||| ||d   7 }qFq6|S )Nr   r   r   r   )r   rs  sincosr   )r   r   rp   rq   rk  r   r  rO   rO   rP   rt    s    

z;TestParforsDiagnostics.test_user_varname.<locals>.test_implrO   r  c                 s   s   | ]}d |j kV  qdS )zslice(0, n, 1)N)rh  )r   r	  rO   rO   rP   rg    s     z;TestParforsDiagnostics.test_user_varname.<locals>.<genexpr>N)r   r   r<  r   anyZfusion_reportsr  rO   rO   rP   test_user_varname  s    

z(TestParforsDiagnostics.test_user_varnamec                 C   sB   dd }|  | | |d}|jd }| j|dddgid d S )Nc                  S   sF   d} t | | f}t| D ]&}t| D ]}|d | |||f< q&q|S r  r  )r   rp   r   r  rO   rO   rP   rt    s    z<TestParforsDiagnostics.test_nested_prange.<locals>.test_implrO   r  r   r   )r  r  r  r  rO   rO   rP   test_nested_prange  s    

z)TestParforsDiagnostics.test_nested_prangec                 C   sF   dd }|  | | |d}|jd }| j|dddgidgd	 d S )
Nc                  S   s   d} t | }t |}|S r  )r   rs  r  r  rO   rO   rP   rt    s    

zCTestParforsDiagnostics.test_function_replacement.<locals>.test_implrO   r  r   r   r   )r  r\  )r  r  r;  r  r  rO   rO   rP   test_function_replacement  s    

z0TestParforsDiagnostics.test_function_replacementc                 C   s:   dd }|  | | |d}|jd }| j|dd d S )Nc                  S   s4   d} t | d }d}t| D ]}||| 7 }q|S r5  )r   rs  r   )r   rp   rk  r   rO   rO   rP   rt    s    z8TestParforsDiagnostics.test_reduction.<locals>.test_implrO   r  r   r  r  r  rO   rO   rP   r    s
    

z%TestParforsDiagnostics.test_reductionc                 C   s:   dd }|  | | |d}|jd }| j|dd d S )Nc                  S   s   d} t | }d|d d < |S )Nr   r>  rr  )r   rp   rO   rO   rP   rt    s    
z6TestParforsDiagnostics.test_setitem.<locals>.test_implrO   r  r   r  r  r  rO   rO   rP   test_setitem  s
    

z#TestParforsDiagnostics.test_setitemc                 C   s:   dd }|  | | |d}|jd }| j|dd d S )Nc                  S   sL   d} d}d}t | D ]2}t|f}t|D ]}|||< q,||d 7 }q|S )Nr   rj   r   rG   )r   r   r#  r   )r   r   rk  r   tempr  rO   rO   rP   rt    s    
zBTestParforsDiagnostics.test_allocation_hoisting.<locals>.test_implrO   r  r   )r  r  r  rO   rO   rP   test_allocation_hoisting  s
    

z/TestParforsDiagnostics.test_allocation_hoisting)NNNNN)rb   rJ   rc   r   r  r  r  r  r  r  r  r  r  r  r  rO   rO   rO   rP   r  s  s"          
r  c                   @   s   e Zd Zdd Zdd ZdS )TestPrangeBasec                 C   s"  |j }t|j}|dkrFd|jks&ttdd |jD }t|j}n|jd}g }t	|D ],}|j
dkr`t|j|kr`||jd  q`|d t|}t|d }	tjdkrd|	d>  }	t|j}t|t|kst|D ]}
||
 }|	||< qt|}|j||d	}t|t }|S )
z
        This function does the actual code augmentation to enable the explicit
        testing of `prange` calls in place of `range`.
        Nr   c                 S   s   g | ]}|d kr|ndqS )r   r   rO   r   rO   rO   rP   r   2  s   z7TestPrangeBase.generate_prange_func.<locals>.<listcomp>LOAD_GLOBALr   r   )r   r  )co_codeco_names)__code__r   r   r   r   bytesr  rh  disBytecodeopnamerB   r  r   offsetr   rC   Z	PYVERSION	bytearrayreplacepytypesFunctionTypeglobals)rN   r   patch_instanceZpyfunc_codeZprange_namesZnew_codeZ	range_idxZrange_locationsinstrZ
prange_idxr   r  Zprange_codepfuncrO   rO   rP   generate_prange_func%  s<    





z#TestPrangeBase.generate_prange_funcc              	   O   s   | dd}| dd}| dd}| ||}tdd |D }| ||}	tjdd	}
td
 | ||}W 5 Q R X |r| || |r| 	||}t
d|if|}| j||	|f|| |
S )a
  
        The `prange` tester
        This is a hack. It basically switches out range calls for prange.
        It does this by copying the live code object of a function
        containing 'range' then copying the .co_names and mutating it so
        that 'range' is replaced with 'prange'. It then creates a new code
        object containing the mutation and instantiates a function to contain
        it. At this point three results are created:
        1. The result of calling the original python function.
        2. The result of calling a njit compiled version of the original
            python function.
        3. The result of calling a njit(parallel=True) version of the mutated
           function containing `prange`.
        The three results are then compared and the `prange` based function's
        llvm_ir is inspected to ensure the scheduler code is present.

        Arguments:
         pyfunc - the python function to test
         args - data arguments to pass to the pyfunc under test

        Keyword Arguments:
         patch_instance - iterable containing which instances of `range` to
                          replace. If not present all instance of `range` are
                          replaced.
         scheduler_type - 'signed', 'unsigned' or None, default is None.
                           Supply in cases where the presence of a specific
                           scheduler is to be asserted.
         check_fastmath - if True then a check will be performed to ensure the
                          IR contains instructions labelled with 'fast'
         check_fastmath_result - if True then a check will be performed to
                                 ensure the result of running with fastmath
                                 on matches that of the pyfunc
         Remaining kwargs are passed to np.testing.assert_almost_equal


        Example:
            def foo():
                acc = 0
                for x in range(5):
                    for y in range(10):
                        acc +=1
                return acc

            # calling as
            prange_tester(foo)
            # will test code equivalent to
            # def foo():
            #     acc = 0
            #     for x in prange(5): # <- changed
            #         for y in prange(10): # <- changed
            #             acc +=1
            #     return acc

            # calling as
            prange_tester(foo, patch_instance=[1])
            # will test code equivalent to
            # def foo():
            #     acc = 0
            #     for x in range(5): # <- outer loop (0) unchanged
            #         for y in prange(10): # <- inner loop (1) changed
            #             acc +=1
            #     return acc

        r  Nr   Fcheck_fastmath_resultc                 S   s   g | ]}t |qS rO   r   r   rO   rO   rP   r     s     z0TestPrangeBase.prange_tester.<locals>.<listcomp>Trb  rd  r   )r   r  r   r   rk  rl  rm  r   r   r   r   r   )rN   r   r|   r   r  r   r  r  r   r   ro  r   Z
fastcpfuncrO   rO   rP   prange_testerW  s     A
zTestPrangeBase.prange_testerN)rb   rJ   rc   r  r  rO   rO   rO   rP   r  #  s   2r  c                   @   s*  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Z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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGS )HTestPrangeBasicz Tests Prange c                 C   s   dd }| j |ddd d S )Nc                  S   s,   d} t | }t| D ]}d| ||< q|S )Nr   r  r   r#  r   r  rO   rO   rP   rt    s
    
z0TestPrangeBasic.test_prange01.<locals>.test_implr   Tr   r   r  r~  rO   rO   rP   test_prange01  s    zTestPrangeBasic.test_prange01c                 C   s   dd }| j |ddd d S )Nc                  S   s6   d} t | d }td| D ]}d| ||d < q|S )Nr   r   r  r  r  rO   rO   rP   rt    s
    z0TestPrangeBasic.test_prange02.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange02  s    zTestPrangeBasic.test_prange02c                 C   s   dd }| j |ddd d S )Nc                  S   s   d} t dD ]}| d7 } q| S Nr   r   r  r  r   rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange03.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange03  s    zTestPrangeBasic.test_prange03c                 C   s   dd }| j |ddd d S )Nc                  S   s   d} t dD ]}| d9 } q| S )Nr   r   r   r  r  rO   rO   rP   rt    s    
z3TestPrangeBasic.test_prange03mul.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange03mul  s    z TestPrangeBasic.test_prange03mulc                 C   s   dd }| j |ddd d S )Nc                  S   s   d} t dD ]}| d8 } q| S )Nr  r   r   r  r  rO   rO   rP   rt    s    
z3TestPrangeBasic.test_prange03sub.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange03sub  s    z TestPrangeBasic.test_prange03subc                 C   s   dd }| j |ddd d S )Nc                  S   s   d} t dD ]}| d } q| S r  r  r  rO   rO   rP   rt    s    
z3TestPrangeBasic.test_prange03div.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange03div  s    z TestPrangeBasic.test_prange03divc                 C   s   dd }| j |ddd d S )Nc                  S   s>   d} d}t d}tdD ]}|| kr0|||< qd||< q|S )Nr   r   r   r   r   r[  r   rp   rq   r  r   rO   rO   rP   rt    s    


z0TestPrangeBasic.test_prange04.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange04  s    
zTestPrangeBasic.test_prange04c                 C   s   dd }| j |ddd d S )Nc                  S   s>   d} t j| t jd}d}td| d dD ]}||| 7 }q(|S Nr   r  r   r   r   rs  r  r   r   r  r  r   rO   rO   rP   rt    s    z0TestPrangeBasic.test_prange05.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange05   s    zTestPrangeBasic.test_prange05c                 C   s   dd }| j |ddd d S )Nc                  S   s:   d} t j| t jd}d}tdddD ]}||| 7 }q$|S r!  r"  r#  rO   rO   rP   rt    s    z0TestPrangeBasic.test_prange06.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange06  s    zTestPrangeBasic.test_prange06c                 C   s   dd }| j |ddd d S )Nc                  S   s8   d} t j| t jd}d}t| dD ]}||| 7 }q"|S r!  r"  r#  rO   rO   rP   rt    s    z0TestPrangeBasic.test_prange07.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange07  s    zTestPrangeBasic.test_prange07c                 C   s   dd }| j |ddd d S )Nc                  S   sF   d} t | }d}tt|D ]"}tt|D ]}||| 7 }q.q|S rM  r   rs  r   r   r   r  rk  r   r  rO   rO   rP   rt  "  s    
z0TestPrangeBasic.test_prange08.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange08!  s    zTestPrangeBasic.test_prange08c                 C   s   dd }| j |ddd d S )Nc                  S   s>   d} t | }d}tdD ]}tdD ]}||| 7 }q&q|S rM  r   rs  r   r(  rO   rO   rP   rt  .  s    
z2TestPrangeBasic.test_prange08_1.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange08_1-  s    zTestPrangeBasic.test_prange08_1c                 C   s    dd }| j |dgddd d S )Nc                  S   s0   d} d}t | D ]}t | D ]}|d7 }qq|S Nr   r   r   r  )r   rk  r   r  rO   rO   rP   rt  :  s    z0TestPrangeBasic.test_prange09.<locals>.test_implr   r   Tr  r   r   r  r~  rO   rO   rP   test_prange099  s
    
zTestPrangeBasic.test_prange09c                 C   s    dd }| j |dgddd d S )Nc                  S   s<   d} d}t | D ]&}d}t | D ]}|d7 }q ||7 }q|S r,  r  )r   Zacc2r  Zacc1r   rO   rO   rP   rt  G  s    

z0TestPrangeBasic.test_prange10.<locals>.test_implr   r   Tr-  r  r~  rO   rO   rP   test_prange10F  s
    

zTestPrangeBasic.test_prange10z1list append is not thread-safe yet (#2391, #2408)c                 C   s   dd }| j |ddd d S )Nc                  S   s   d} dd t | D S )Nr   c                 S   s   g | ]}t |qS rO   )r   r  r  rO   rO   rP   r   Y  s     zDTestPrangeBasic.test_prange11.<locals>.test_impl.<locals>.<listcomp>r  r   rO   rO   rP   rt  W  s    z0TestPrangeBasic.test_prange11.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange11U  s    zTestPrangeBasic.test_prange11c                 C   s   dd }| j |ddd d S )Nc                  S   s6   d} d}t |}tt| D ]}| || 7 } q | S r}  r'  )rk  r   r  r   rO   rO   rP   rt  ^  s    
z0TestPrangeBasic.test_prange12.<locals>.test_implr   Tr  r  r~  rO   rO   rP   test_prange12]  s    zTestPrangeBasic.test_prange12c                 C   s$   dd }| j |tdddd d S )Nc                 S   s   d}t | D ]}|d7 }q|S rD  r  r  rO   rO   rP   rt  i  s    
z0TestPrangeBasic.test_prange13.<locals>.test_implr   r   Tr  )r  r   r  r~  rO   rO   rP   test_prange13h  s    zTestPrangeBasic.test_prange13c                 C   s&   dd }| j |tjdddd d S )Nc                 S   s*   d}t t| D ]}|| | d 7 }q|S )Nr   r   r   r   )r  r  r   rO   rO   rP   rt  r  s    z0TestPrangeBasic.test_prange14.<locals>.test_implr   r   Tr  )r  r   r  r  r~  rO   rO   rP   test_prange14q  s
    zTestPrangeBasic.test_prange14c                 C   s   dd }| j |dddd d S )Nc                 S   s,   d}t | D ]}td}||d 7 }q|S )Nr   r  r  )r   r   rs  )r'  rk  r   r   rO   rO   rP   rt    s
    
z0TestPrangeBasic.test_prange15.<locals>.test_implr  r   Tr  r  r~  rO   rO   rP   test_prange15~  s    
zTestPrangeBasic.test_prange15c                 C   s   dd }| j |dddd d S )Nc                 S   s"   d}t |  | D ]}|d7 }q|S rx  r  r'  rk  r   rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange16.<locals>.test_implr  r   Tr  r  r~  rO   rO   rP   test_prange16  s    
zTestPrangeBasic.test_prange16c                 C   s   dd }| j |dddd d S )Nc                 S   s0   d}t | }t|  | D ]}||| 7 }q|S rN  r*  r'  rk  r  r   rO   rO   rP   rt    s
    
z0TestPrangeBasic.test_prange17.<locals>.test_implr\  r   Tr  r  r~  rO   rO   rP   test_prange17  s    
zTestPrangeBasic.test_prange17c                 C   s   dd }| j |dddd d S )Nc                 S   sL   d}t | }t|  dD ],}||| 7 }td| D ]}||| 7 }q4q|S )Nr   rj   r*  )r'  rk  r  r   r  rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange18.<locals>.test_implr\  r   Tr  r  r~  rO   rO   rP   test_prange18  s    
zTestPrangeBasic.test_prange18c                 C   s   dd }| j |dddd d S )Nc                 S   sR   d}| d }t | |f}t|  | D ]&}t| |D ]}||||f 7 }q6q&|S r}  r*  )r'  rk  Mr  r   r  rO   rO   rP   rt    s    z0TestPrangeBasic.test_prange19.<locals>.test_implr\  r   Tr  r  r~  rO   rO   rP   test_prange19  s    
zTestPrangeBasic.test_prange19c                 C   s   dd }| j |dddd d S )Nc                 S   s.   d}t | }td| D ]}||| 7 }q|S )Nr   rG   r*  r8  rO   rO   rP   rt    s
    
z0TestPrangeBasic.test_prange20.<locals>.test_implr\  r   Tr  r  r~  rO   rO   rP   test_prange20  s    
zTestPrangeBasic.test_prange20c                 C   s   dd }| j |dddd d S )Nc                 S   s    d}t ddD ]}|d7 }q|S )Nr   r2  rG   r   r  r6  rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange21.<locals>.test_implr\  r   Tr  r  r~  rO   rO   rP   test_prange21  s    
zTestPrangeBasic.test_prange21c                 C   s   dd }| j |dddd d S )Nc                  S   sR   d} d}t d}tddD ]0}|| kr2|||< q|dk rDd||< qd||< q|S )	Nr   r   r   r/  r   r   rG   r>  r  r  rO   rO   rP   rt    s    



z0TestPrangeBasic.test_prange22.<locals>.test_implr   Tr   r   r  r  r~  rO   rO   rP   test_prange22  s
     zTestPrangeBasic.test_prange22c                 C   s4   dd }t dd d d }| j||dddd d S )Nc                 S   s   t t| D ]}|| |< q| S rR   r3  r  r   rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange23.<locals>.test_impl    r   r   Tr@  r   r#  r  rN   rt  r  rO   rO   rP   test_prange23  s    
 zTestPrangeBasic.test_prange23c                 C   s4   dd }t dd d d }| j||dddd d S )Nc                 S   s"   t t|  dD ]}|| |< q| S rN  r3  rB  rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange24.<locals>.test_implrC  r   r   Tr@  rD  rE  rO   rO   rP   test_prange24  s    
 zTestPrangeBasic.test_prange24c                 C   sd   dd }t d}| j||dgdddd | |t|f}|jd }| }| t	|d	 d S )
Nc                    s<   t  } fddt|D }t|D ]} | ||< q&|S )Nc                    s   g | ]}t  qS rO   )r   
zeros_like)r   rH   r  rO   rP   r     s     zDTestPrangeBasic.test_prange25.<locals>.test_impl.<locals>.<listcomp>)r   r   )r  r   r  r   rO   r  rP   rt    s
    z0TestPrangeBasic.test_prange25.<locals>.test_implr  r   r   T)r  r   r   r  r  r   )
r   rs  r  r   r   r   r<  r  r   r   )rN   rt  r  r   r/  r  rO   rO   rP   test_prange25  s    
 
zTestPrangeBasic.test_prange25c                 C   s4   dd }t dd d d }| j||dddd d S )Nc                 S   s,   | d d d }t t|D ]}|||< q| S rK  r3  )r  r  r   rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange26.<locals>.test_implrC  r   r   Tr@  rD  rE  rO   rO   rP   test_prange26  s    
 zTestPrangeBasic.test_prange26c                 C   sF   dd }| j |tdtddddddddddg
ddgddd	 d S )
Nc                 S   sB   t |d d D ],}t dD ]}t| |d |d  }qqdS r   )r   r   abs)rp   rq   r
  r  r   r,  rO   rO   rP   rt  
  s    z0TestPrangeBasic.test_prange27.<locals>.test_implr  r   r   r   r   Tr-  )r  r   ro  Zasarrayr~  rO   rO   rP   test_prange27  s    zTestPrangeBasic.test_prange27c              	   C   sx   dd }t ddgddgddgddgddgddgg}t ddgddgdd	gd	d
gd
dgg}| j|||dddd d S )Nc           
      S   sn   t t|}tdt|D ]L}||df }||df }| | }| | }|| }|d |d  }	|	||< q|S rD  )r   r#  r   r   )
r   r  r  r  Zi0i1ZPt1ZPt2rf  Zvl2rO   rO   rP   rt    s    
z0TestPrangeBasic.test_prange28.<locals>.test_impl      r  r   r   r   r   r   r   rj   r   Tr@  )r   r%  r  r  rO   rO   rP   test_prange28  s$    

 zTestPrangeBasic.test_prange28c                 C   s$   dd }|  |d |  |d d S )Nc                 S   s:   d}| r t dD ]}|d7 }qnt dD ]}|d8 }q(|S )Nr   r   r   r  )r  r  r   rO   rO   rP   rt  9  s    
z0TestPrangeBasic.test_prange29.<locals>.test_implTFr  r~  rO   rO   rP   test_prange297  s    
zTestPrangeBasic.test_prange29c                 C   s@   dd }t t ddd}t dddg}| |||d d S )	Nc           
      S   s   |j d }t| }tj||ftjd}t| | d | }t|D ]@}|| }|d | }	| ||	 |d d   |d d ||	f< qB|S r  )r$  r   r   r#  r  r   )
r   parZ
numthreadsZn_parZn_xr  Zchunklenr   r  r  rO   rO   rP   rt  H  s    
*z0TestPrangeBasic.test_prange30.<locals>.test_implr   r   r  r  rm  r   )r   r%  ro  r  )rN   rt  r   rQ  rO   rO   rP   test_prange30F  s    zTestPrangeBasic.test_prange30N)(rb   rJ   rc   r  r  r  r  r  r  r  r   r$  r%  r&  r)  r+  r.  r/  rH  skipr0  r1  r2  r4  r5  r7  r9  r;  r=  r>  r?  rA  rF  rG  rI  rJ  rL  rO  rP  rR  rO   rO   rO   rP   r    sH   

				
		

	


r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zed2d3 Zed4d5 Zd6S )7TestPrangeSpecificz4 Tests specific features/problems found under prangec                 C   s   dd }|  |d d S )Nc                 S   s.   d}t | D ]}|d7 }|dkr|d7 }q|S Nr   r   r   r  r   r
  r   rO   rO   rP   rt  a  s    
zRTestPrangeSpecific.test_prange_two_instances_same_reduction_var.<locals>.test_implr\  r  r~  rO   rO   rP   ,test_prange_two_instances_same_reduction_var_  s    z?TestPrangeSpecific.test_prange_two_instances_same_reduction_varc              	   C   sF   dd }|  tj}| |d W 5 Q R X d}| |t|j d S )Nc                 S   s.   d}t | D ]}|d7 }|dkr|d9 }q|S rU  r  rV  rO   rO   rP   rt  k  s    
zKTestPrangeSpecific.test_prange_conflicting_reduction_ops.<locals>.test_implr\  zBReduction variable c has multiple conflicting reduction operators.)rw  r   ZUnsupportedErrorr  r   r   rx  rN   rt  rz  r   rO   rO   rP   %test_prange_conflicting_reduction_opsj  s
    z8TestPrangeSpecific.test_prange_conflicting_reduction_opsc                 C   s   dd }|  | d S )Nc                  S   sJ   d } }t dD ]0}|dkr&| d7 } qtd}|d r|d7 }q| |fS )Nr   r   r   r  r  r|  )r  r  r   r   rO   rO   rP   rt  {  s    


zLTestPrangeSpecific.test_prange_two_conditional_reductions.<locals>.test_implr  r~  rO   rO   rP   &test_prange_two_conditional_reductionsy  s    
z9TestPrangeSpecific.test_prange_two_conditional_reductionsc                 C   s   dd }|  | d S )Nc                  S   s4   d} t dD ]"}t dD ]}|dkr| d7 } qq| S rD  r  )r  r   r   rO   rO   rP   rt    s    zCTestPrangeSpecific.test_prange_nested_reduction1.<locals>.test_implr  r~  rO   rO   rP   test_prange_nested_reduction1  s    z0TestPrangeSpecific.test_prange_nested_reduction1c              	   C   s   dd }|  t}|  W 5 Q R X | |d }| |d}| |d}|  t}|  W 5 Q R X | }| |d tj d S )Nc                  S   s,   d} t | }t| D ]}d| ||< q|S )NrC  r   r  r  rO   rO   rP   rt    s
    
z<TestPrangeSpecific.test_check_error_model.<locals>.test_implrO   r   )	rw  ZeroDivisionErrorr  r   r   r   r   r   r  )rN   rt  rz  r  ZpcresZpfcresr  rO   rO   rP   test_check_error_model  s    z)TestPrangeSpecific.test_check_error_modelc           
      C   s   dd }t ddd}| j||dddd | |d }tt|g}| ||}| 	|}|
 D ]<\}}| D ]*}	d	|	krx||	krx| |	d
d  qhqxqhd S )Nc                 S   s*   t t| D ]}| | }d|d d < q| S r  r3  )r  r   r  rO   rO   rP   rt    s    z?TestPrangeSpecific.test_check_alias_analysis.<locals>.test_implrC  r   r6  r   Tr@  ZdefineZnoaliasr   )r   r#  r   r  r  r   r   r   r   r   r   r   r   r   )
rN   rt  r  r  r   r   r   r   rf  rt  rO   rO   rP   test_check_alias_analysis  s    
 
z,TestPrangeSpecific.test_check_alias_analysisc              	   C   sF   dd }|  tj}| |d W 5 Q R X d}| |t|j d S )Nc                 S   s"   d}t d| dD ]}|d7 }q|S rx  r  r6  rO   rO   rP   rt    s    
zJTestPrangeSpecific.test_prange_raises_invalid_step_size.<locals>.test_implr  z4Only constant step size of 1 is supported for prange)rw  r   r:  r  r   r   rx  rX  rO   rO   rP   $test_prange_raises_invalid_step_size  s
    z7TestPrangeSpecific.test_prange_raises_invalid_step_sizec                 C   s   dd }| j |ddd | |d }| |d}| |}d}d}t|||f }td	|||f }| D ]H\}	}
|
 }t|D ]\}}|	|r qq| 
|	||d
   qpd S )Nc                  S   s&   d} d}t | D ]}||d 7 }q|S )Nr  r   r  r  r  rO   rO   rP   rt    s
    zFTestPrangeSpecific.test_prange_fastmath_check_works.<locals>.test_implr   Tr  rO   z%[A-Z_0-9]?(.[0-9]+)+[.]?[i]?z)\s+%s = fmul fast double %s, 5.000000e-01z\s+%s = fadd fast double %s, %sr   )r  r  r   r   r   compiler   r   rE  r   r   )rN   rt  r  r   r   Z_idZ
recipr_strZreciprocal_instZ	fadd_instr   Zkernelr   r   r   rO   rO   rP    test_prange_fastmath_check_works  s&    

z3TestPrangeSpecific.test_prange_fastmath_check_worksc                 C   s   dd }|  |d d S )Nc                 S   s8   t | | f}|d }t| D ]}|d ||< q| S rD  r   r#  r   r  )r   rq   rp   r  rO   rO   rP   rt    s
    z8TestPrangeSpecific.test_parfor_alias1.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_alias1  s    z%TestPrangeSpecific.test_parfor_alias1c                 C   s   dd }|  |d d S )Nc                 S   sF   t | | f}t| D ]&}|| }t| D ]}|| ||< q*q| S rR   rb  )r   rq   r   rp   r  rO   rO   rP   rt    s    z8TestPrangeSpecific.test_parfor_alias2.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_alias2  s    z%TestPrangeSpecific.test_parfor_alias2c                 C   s   dd }|  |d d S )Nc                 S   sb   t | | | f}t| D ]@}|| }t| D ]*}|| }t| D ]}|| | ||< q@q,q| S rR   rb  )r   rq   r   rp   r  r
  r   rO   rO   rP   rt     s    z8TestPrangeSpecific.test_parfor_alias3.<locals>.test_implr   r  r~  rO   rO   rP   test_parfor_alias3  s    	z%TestPrangeSpecific.test_parfor_alias3c                 C   s8   dd }|  |dd}|d }d}| |t|j d S )Nc                 S   s   t |D ]}| }q|S rR   r  )r   r  r  r   rO   rO   rP   rt    s    z8TestPrangeSpecific.test_parfor_race_1.<locals>.test_implr   r  r   zVariable k used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results.)r  r   r   rh  )rN   rt  ro  Zwarning_objZexpected_msgrO   rO   rP   test_parfor_race_1  s
    z%TestPrangeSpecific.test_parfor_race_1c                 C   s   dd }|  | dS )a   issue 3686: if a prange has something inside it that causes
            a nested parfor to be generated and both the inner and outer
            parfor use the same call variable defined outside the parfors
            then ensure that when that call variable is pushed into the
            parfor that the call variable isn't duplicated with the same
            name resulting in a redundant type lock.
        c                  S   sf   d} t j}tdD ]"}|d}| |t dd 7 } qtdD ]"}|d}| |t dd 7 } q>| S )Nr   r   r  r   )r   negativer   r#  )r  r  r   this_mattersrO   rO   rP   rt    s    zGTestPrangeSpecific.test_nested_parfor_push_call_vars.<locals>.test_implNr  r~  rO   rO   rP   !test_nested_parfor_push_call_vars  s    z4TestPrangeSpecific.test_nested_parfor_push_call_varsc                 C   sD   dd }d}t |||f}t j|t jd}| j|||dgd dS )a+   issue4903: a global is copied next to a parfor so that
            it can be inlined into the parfor and thus not have to be
            passed to the parfor (i.e., an unsupported function type).
            This global needs to be renamed in the block into which
            it is copied.
        c                 S   s   t t|}t t|}tdD ]T}|| }t|D ]}|t | ||f 7 }q8t|D ]}|t | ||f 7 }q\q$||fS r  )r   r#  r   r   r  )zztcZlhlcr   ntr  rO   rO   rP   rt  3  s    zATestPrangeSpecific.test_copy_global_for_parfor.<locals>.test_implr   r  r   )r  N)r   rs  r  r  )rN   rt  r   rj  rk  rO   rO   rP   test_copy_global_for_parfor,  s
    z.TestPrangeSpecific.test_copy_global_for_parforc                 C   s   dd }|  |d d S )Nc                 S   s0   d}t j}tdD ]}|d}||| 7 }q|S )Nr   r   r  )r   rg  r   )r   r  r  r   rh  rO   rO   rP   rt  D  s    zGTestPrangeSpecific.test_multiple_call_getattr_object.<locals>.test_implr  r  r~  rO   rO   rP   !test_multiple_call_getattr_objectC  s    z4TestPrangeSpecific.test_multiple_call_getattr_objectc                 C   s   dd }t jddtfdtfgd}t jddtfdtfgd}t jddtfdtfgd}|t j}|t j}|t j}t||}tt||}	t|dd}
t|
|}| ||	 | || d S )	Nc                 S   s    t t| D ]}d| j|< q| S r  )r   r   r   )r   r   rO   rO   rP   rt  P  s    zHTestPrangeSpecific.test_argument_alias_recarray_field.<locals>.test_implr   r   r  r  Tr8  )	r   r#  r  r  viewZrecarrayr   r
   r   )rN   rt  ZX1ZX2ZX3r  r  Zv3
python_resnjit_respa_funcpa_resrO   rO   rP   "test_argument_alias_recarray_fieldN  s    z5TestPrangeSpecific.test_argument_alias_recarray_fieldc                    s\   t dd   fdd}|d}t |d}t |dd}|d}| || | || dS )	z issue3699: test that mutable variable to call in loop
            is not hoisted.  The call in test_impl forces a manual
            check here rather than using prange_tester.
        c                 S   s"   | d }| d d }|  | |S )z If the variable X is hoisted in the test_impl prange
                then subsequent list_check calls would return increasing
                values.
            rG   r   )r   )r  r  rp   rO   rO   rP   
list_checki  s    
z>TestPrangeSpecific.test_mutable_list_param.<locals>.list_checkc                    s    t | D ]}dg} |}q|S r  rq  )r   r   r  rp   rv  rO   rP   rt  s  s    
z=TestPrangeSpecific.test_mutable_list_param.<locals>.test_implr   Tr8  Nr
   r   )rN   rt  rq  rr  rs  rt  rO   rw  rP   test_mutable_list_paramd  s    
	z*TestPrangeSpecific.test_mutable_list_paramc                 C   s>   dd }t jdddgtdt jddgtdg}| || d S )Nc                    s    t  fddtt D S )Nc                    s   g | ]}t  | qS rO   )r   r   r!  rO   rP   r     s     zXTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl.<locals>.<listcomp>)r   r%  r   r   r!  rO   r!  rP   rt    s    zDTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_implr   r   r   r  )r   r%  r  r  r  rO   rO   rP   test_list_comprehension_prange  s    &z1TestPrangeSpecific.test_list_comprehension_prangec                 C   s,   dd }t jdt jd}| ||dd d S )Nc                 S   sZ   t | j}t| jd D ]:}| | d d }|dkr:d}|dkrFd}|||g||< q|S )Nr   g     o@)r   r#  r$  r   )imagerp   rq   r[  r   r	  hrO   rO   rP   rt    s    z>TestPrangeSpecific.test_ssa_false_reduction.<locals>.test_implr  r  r   )r   r#  r  r  )rN   rt  r{  rO   rO   rP   test_ssa_false_reduction  s    z+TestPrangeSpecific.test_ssa_false_reductionc                 C   s   dd }|  | d S )Nc                  S   s@   d} t j| t jd}tdD ]}dg}d|d< |d ||< q|S )Nrj   r  r   r   )r   r[  r  r   )r   rp   r   r  rO   rO   rP   rt    s    z@TestPrangeSpecific.test_list_setitem_hoisting.<locals>.test_implr  r~  rO   rO   rP   test_list_setitem_hoisting  s    	z-TestPrangeSpecific.test_list_setitem_hoistingc                 C   sB   t dt jfg}dd }dd }| j|t jd|d|gd d S )	Nr  c                 S   s   t dD ]}d| | d< qd S )Nr   r  r  )statesr   rO   rO   rP   rt    s    z?TestPrangeSpecific.test_record_array_setitem.<locals>.test_implc                 S   s    | d d |d d kst d S )Nr   r  )r   ro   rO   rO   rP   r    s    z>TestPrangeSpecific.test_record_array_setitem.<locals>.comparerr   )r$  r  r  )r   r  r  r  r#  )rN   state_dtypert  r  rO   rO   rP   test_record_array_setitem  s    z,TestPrangeSpecific.test_record_array_setitemc                 C   sF   t dt jfg}dd }t jd|d}dd }| j|||gd d S )	Nr   c                 S   s*   | j }t| j D ]}d| | d |< q| S )Nr>  r   )r  r   )r  r   r   rO   rO   rP   rt    s    zKTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.test_implr   r  c                 S   s   t j| | d S rR   r  ro   rO   rO   rP   r    s    zJTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.comparerr  )r   r  r  r#  r  )rN   r  rt  r  r  rO   rO   rP   %test_record_array_setitem_yield_array  s    z8TestPrangeSpecific.test_record_array_setitem_yield_arrayc                 C   s   dd }|  |dd d S )Nc                 S   sZ   t | f}|dkr4t| D ]}||  d7  < qnt| D ]}||  d7  < q<|d S )Nr   r   r   r  )r  caser  r   rO   rO   rP   rt    s    z4TestPrangeSpecific.test_issue7501.<locals>.test_implr   r   r  r~  rO   rO   rP   test_issue7501  s    
z!TestPrangeSpecific.test_issue7501c                 C   s(   dd }d}t j|}| || d S )Nc           
      S   s   d}t dddg}|jd }| jd }d}t|D ]`}| | }|| d  d|d   }t |}	||	t ||  t t t ||	  7 }q4|S )Nr  rN  r  r.  r   r   )r   r%  r$  r   r  r  r  r  )
r  rq   Zpointsr'  r   Zexpsr   prz  r   rO   rO   rP   rt    s    


2z6TestPrangeSpecific.test_kde_example.<locals>.test_implr  )r   r  r  r  rQ  rO   rO   rP   test_kde_example  s    z#TestPrangeSpecific.test_kde_examplec                 C   s.   t jtjddgdt jd}| d|  d S )Nz-mz#numba.tests.parfors_max_label_errorr  )rI   stderrzTEST PASSED)subpcheck_outputsys
executableSTDOUTr   decode)rN   r  rO   rO   rP   test_issue_due_to_max_label  s    
z.TestPrangeSpecific.test_issue_due_to_max_labelc                 C   s"   dd }t d}| || d S )Nc                 S   s6   t | }t | }tt| D ]}| ||< q |S rR   )r   rH  r  r   r   r  )r   r  r  r   rO   rO   rP   rt    s
    

z4TestPrangeSpecific.test_issue7578.<locals>.test_implr2  )r   ro  r  r  rO   rO   rP   test_issue7578  s    	
z!TestPrangeSpecific.test_issue7578N) rb   rJ   rc   r  rW  rY  rZ  r[  r>   r]  r^  r_  ra  rc  rd  re  rf  ri  rn  ro  ru  ry  rz  r}  r~  r  r  r  r  r:   r  r  rO   rO   rO   rP   rT  [  s<   

	


rT  c                   @   sl   e Zd 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S )TestParforChunksizingz:
    Tests chunksize handling in ParallelAccelerator.
    Fc                 C   s   t d d S rN  r   rT   rO   rO   rP   setUp	  s    zTestParforChunksizing.setUpc                 C   s   t d d S rN  r  rT   rO   rO   rP   tearDown  s    zTestParforChunksizing.tearDownc                 C   s>   |  t d td |  t d td |  t d d S Nr   r6  )r   r   r   rT   rO   rO   rP   $test_python_parallel_chunksize_basic  s
    z:TestParforChunksizing.test_python_parallel_chunksize_basicc              	   C   sB   |  t d td |  t d W 5 Q R X |  t d d S r  )r   r   r   rT   rO   rO   rP   test_python_with_chunksize  s    
z0TestParforChunksizing.test_python_with_chunksizec                 C   sV   t dd }t dd }| | d |d | | d |d | | d d S )Nc                   S   s   t  S rR   )r   rO   rO   rO   rP   get_cs   s    zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.get_csc                 S   s   t | S rR   r  r!  rO   rO   rP   set_cs$  s    zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.set_csr   r6  rx  )rN   r  r  rO   rO   rP   "test_njit_parallel_chunksize_basic  s    

z8TestParforChunksizing.test_njit_parallel_chunksize_basicc                 C   sB   t dd }|d\}}}| |d | |d | |d d S )Nc              	   S   s0   t  }td t  }W 5 Q R X t  }|||fS )Nr6  )r   r   )r   cs1cs2cs3rO   rO   rP   rt  0  s
    
zATestParforChunksizing.test_njit_with_chunksize.<locals>.test_implr6  r   rx  )rN   rt  r  r  r  rO   rO   rP   test_njit_with_chunksize.  s    
z.TestParforChunksizing.test_njit_with_chunksizec                 C   sh   t dddd }dD ]L}tdD ]>}||d |\}}| t|dk | t|d	k q"qd
S )z Test that all the iterations get run if you set the
            chunksize.  Also check that the chunksize that each
            worker thread sees has been reset to 0. Tr8  c              	   S   sX   t |}t |d}t| * t|D ]}t ||< d||< q,W 5 Q R X ||fS )Nir  )r   r#  r  r   r   r   r   )csr   ry  inner_csr   rO   rO   rP   rt  C  s    
zLTestParforChunksizing.test_all_iterations_reset_chunksize.<locals>.test_impl)i  i  i  i  r  r   r  r   N)r
   r   r   r   all)rN   rt  r  r   ry  r  rO   rO   rP   #test_all_iterations_reset_chunksize>  s    
z9TestParforChunksizing.test_all_iterations_reset_chunksizec              	   C   sB   |  t}tdd }|  W 5 Q R X d}| |t|j d S )Nc                   S   s   t d d S )NrG   r  rO   rO   rO   rP   neg_testY  s    zMTestParforChunksizing.test_njit_parallel_chunksize_negative.<locals>.neg_test/chunksize must be greater than or equal to zero)rw  r   r
   r   r   rx  )rN   r;  r  r   rO   rO   rP   %test_njit_parallel_chunksize_negativeV  s    
z;TestParforChunksizing.test_njit_parallel_chunksize_negativec              	   C   s8   |  t}td W 5 Q R X d}| |t|j d S )NrG   r  )rw  r   r   r   r   rx  rN   r;  r   rO   rO   rP   'test_python_parallel_chunksize_negativeb  s    z=TestParforChunksizing.test_python_parallel_chunksize_negativec              	   C   sD   |  tj}tdd }|  W 5 Q R X d}| |t|j d S )Nc                   S   s   t d d S )Ninvalid_typer  rO   rO   rO   rP   r   l  s    zMTestParforChunksizing.test_njit_parallel_chunksize_invalid_type.<locals>.impl)The parallel chunksize must be an integer)rw  r   ZTypingErrorr
   r   r   rx  )rN   r;  r   r   rO   rO   rP   )test_njit_parallel_chunksize_invalid_typej  s    
z?TestParforChunksizing.test_njit_parallel_chunksize_invalid_typec              	   C   s8   |  t}td W 5 Q R X d}| |t|j d S )Nr  r  )rw  	TypeErrorr   r   r   rx  r  rO   rO   rP   +test_python_parallel_chunksize_invalid_typeu  s    zATestParforChunksizing.test_python_parallel_chunksize_invalid_typeN)rb   rJ   rc   r  rd   r  r  r  r  r  r  r  r  r  r  r  rO   rO   rO   rP   r    s   r  c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )TestParforsVectorizerFc                 O   s:  | dd}| dd}| dd}| dd}||d	}	g }
|	 D ]\}}|
t|| qF|
d
  |
d  tdd |D }| |d }|dkr| ||}n| ||}| |}|r
t	
d}||j }| t|d | |d
 | | |i  |W  5 Q R  W  5 Q R  S Q R X W 5 Q R X d S )Nrx   Fcpu_namezskylake-avx512
assertionsTcpu_featuresz-prefer-256-bit)ZNUMBA_CPU_NAMEZNUMBA_CPU_FEATURESr   r   c                 S   s   g | ]}t |qS rO   r   r   rO   rO   rP   r     s     z8TestParforsVectorizer.get_gufunc_asm.<locals>.<listcomp>z%call\s+\w+\*\s+@do_scheduling_(\w+)\()r   r   r   r7   r   r  r   r   r   r   r`  findallr   r   r   r   r   ZassertNotEqual)rN   r   Zschedule_typer|   r   rx   r  r  r  Zenv_optsZ	overridesr   rf  r   Zpfunc_vectorizabler   asmZschedtymatchesrO   rO   rP   get_gufunc_asm  s0    

z$TestParforsVectorizer.get_gufunc_asmc                 C   s   dd }t d}| j|d|dd}| j|d|dd}| D ]6}| d|k | d	|kpbd
|k | d|k q>| D ]R}| d|k | d	|k | d|kod
|k | d|k | d|k q~dS ) This checks that if fastmath is set and the underlying hardware
        is suitable, and the function supplied is amenable to fastmath based
        vectorization, that the vectorizer actually runs.
        c                 S   s,   t | }d}t|D ]}|t|7 }q|S rN  r   r   r   r  )r  r   rk  r   rO   rO   rP   will_vectorize  s
    zJTestParforsVectorizer.test_vectorizer_fastmath_asm.<locals>.will_vectorizer   r   Trx   FZvaddpdvsqrtpd__svml_sqrtzmmvsqrtsdZvaddsdN)r   r#  r  rX  r   )rN   r  r  Zfast_asmZslow_asmrf  rO   rO   rP   test_vectorizer_fastmath_asm  s$    



z2TestParforsVectorizer.test_vectorizer_fastmath_asmc              	   C   s   dd }dd }t d}tdd* | j|d|d	d
}| j|d|d	d
}W 5 Q R X | D ].}| d|k | d|k | d|k q\| D ]6}| d|kpd|k | d|k | d|k qdS )r  c                 S   s0   t | }t| dD ]}t| | | |< q| S rN  r  r  r   r   rO   rO   rP   will_not_vectorize  s    zTTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_not_vectorizec                 S   s,   t | }t|D ]}t| | | |< q| S rR   r  r  rO   rO   rP   r    s    zPTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_vectorizer   NUMBA_BOUNDSCHECK0r   Tr  r   r  r  r  r  ZvmovupdN)r   r#  r7   r  rX  r   )rN   r  r  r  Z	novec_asmZvec_asmrf  rO   rO   rP   "test_unsigned_refusal_to_vectorize  s$    


z8TestParforsVectorizer.test_unsigned_refusal_to_vectorizec              	   C   s  dd }dd }t dd& | j|ddd	}| j|d
dd	}W 5 Q R X dd }| D ]\}}||} qlqV| D ]\}}||}	 qqtddlm}
 | t|t|	 t||	D ]^\}}||krqq|
dd ||}| }|D ],}|d dkr| ||d |d  d qqdS )z This checks vectorization for signed vs unsigned variants of a
        trivial accumulator, the only meaningful difference should be the
        presence of signed vs. unsigned unpack instructions (for the
        induction var).
        c                  S   s&   d} d}t |  dD ]}||7 }q|S )N   r   r   r  r  rO   rO   rP   signed_variant  s
    
zMTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.signed_variantc                  S   s"   d} d}t | D ]}||7 }q|S )Nr  r   r  r  rO   rO   rP   unsigned_variant  s
    
zOTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.unsigned_variantr  r  r   Tr  r   c                 S   s`   g }|   D ]N}| }|dkr|ds|ds|dsd|ks|tdd| q|S )N rF   rH   "r   z[	])r   strip
startswithr   r   sub)r  rk  r   ZspdrO   rO   rP   strip_instrs  s    zKTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.strip_instrsr   )SequenceMatcherc                 S   s   | dkS )N	rO   r!  rO   rO   rP   r  9  r  zGTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.<lambda>insertr/  rG   r  N)	r7   r  r   difflibr  r   r   r   Zget_opcodes)rN   r  r  Z
signed_asmZunsigned_asmr  r   rf  Zsigned_instrZunsigned_instrsmrp   rq   r  r   r   rO   rO   rP   test_signed_vs_unsigned_vec_asm  s4    	z5TestParforsVectorizer.test_signed_vs_unsigned_vec_asmN)	rb   rJ   rc   rd   r  r8   r  r  r  rO   rO   rO   rP   r  }  s   %
'
+r  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	 TestParforReductionSetNumThreadszCTest execution correctness on reductions with set_num_threads.
    c                    sP   t j}d|  |d tdd fdd}|}|}| || d S )Nr   r   Tr8  c                    s@   d}t |  t D ]&}d|  }t | t }||7 }q|S rD  r   r   r   Znthreadsrk  r   Z
local_maskZgntr<  maskrO   rP   udtI  s    
z6TestParforReductionSetNumThreads.test_add.<locals>.udtr   NUMBA_NUM_THREADSr
   r  r  rN   r'  r  expectr  rO   r  rP   test_addD  s    

z)TestParforReductionSetNumThreads.test_addc                    sV   t dtj}d|  |d tdd fdd}|}|}| || d S )Nr   r   r   Tr8  c                    s@   d}t |  t D ]&}d|  }t | t }||9 }q|S r  r  r  r  rO   rP   r  _  s    
z6TestParforReductionSetNumThreads.test_mul.<locals>.udt)r  r   r  r
   r  r  r  rO   r  rP   test_mulX  s    

z)TestParforReductionSetNumThreads.test_mulc                    sP   t j}d|  |d tdd fdd}|}|}| || d S )Nr   r   Tr8  c                    sB   d}t |  t D ](}d|  }t | t }t||}q|S r  )r   r   r   r  r  r  rO   rP   r  s  s    z6TestParforReductionSetNumThreads.test_max.<locals>.udtr  r  rO   r  rP   r  n  s    

z)TestParforReductionSetNumThreads.test_maxN)rb   rJ   rc   r  r  r  r  rO   rO   rO   rP   r  @  s   r  c                   @   s   e Zd Ze dd ZdS )TestDiagnosticEnvVarc              	   C   sL   dt jd< t }tdddd }|  W 5 Q R X | }| d| d S )N4ZNUMBA_PARALLEL_DIAGNOSTICSTr8  c                  S   s.   d} t j| t jd}t| D ]}d||< q|S )Nr  r  r   )r   r#  r  r   )r   rq   r   rO   rO   rP   r     s
    
z<TestDiagnosticEnvVar.test_diagnostics_env_var1.<locals>.implzParallel Accelerator Optimizing)osenvironr5   r
   rr  r   )rN   rs  r   Z
the_outputrO   rO   rP   test_diagnostics_env_var1  s    

z.TestDiagnosticEnvVar.test_diagnostics_env_var1N)rb   rJ   rc   r4   Zrun_test_in_subprocessr  rO   rO   rO   rP   r    s   r  __main__)N)r  r   r  r   r  re   r  
subprocessr   r	  rk  	functoolsr   r\  r   Znumpy.randomr   r  collectionsr   r   r   	itertoolsr   r	   r  Znumba.parfors.parforr   r
   r   r   r   r   r   r   r   Z
numba.corer   r   r   r   r   r   r   r   r   Znumba.extendingr   r   r   r   r    r!   Znumba.core.registryr"   Znumba.core.annotationsr#   Znumba.core.ir_utilsr$   r%   r&   r'   r(   r)   r*   Znumba.np.unsafe.ndarrayr+   r  Znumba.core.bytecoder,   Znumba.core.compilerr-   r.   r/   r0   Znumba.core.compiler_machineryr1   r2   Znumba.core.typed_passesr3   Znumba.tests.supportr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Znumba.core.extendingrA   rB   rC   ri  rH  rD   rI  rf   Zx86_onlyr  r  rk   rr   rs   r  r  r)  rC  r   rM  rP  rK  rZ  rY  r`  r_  rb  r  r1  rj  r  r  rD  rJ  r  r  rS  rY  r`  r  r  r  rT  r  r  r  r  rb   mainrO   rO   rO   rP   <module>   s   (0 $<=
	  $B	
" ,*          g  +%=   @ 0    '   )z BB
