o
    8ήcZ                    @   sL  d dl m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.m/Z/ d d	l0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d d
l7m8Z8 d dl9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZE d dlFmGZG d dlHmIZImJZJmKZKmLZL d dlMmNZNmOZO d dlPmQZQ d dlRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ d dl`maZa d dlbZbd dlcZceYG dd deSZdeceef dvdZgdZhdZieddZjdd Zke_G dd deSZld d! Zmd"d# Znd$d% Zod&d' Zpd(d) Zqd*d+ Zrd,d- Zsd.d/ Ztd0d1 Zud2d3 Zvd4d5 Zwd_d6d7Zxd8d9 ZyG d:d; d;ezZ{eYG d<d= d=elZ|eYG d>d? d?elZ}eYG d@dA dAelZ~G dBdC dCeSZeYG dDdE dEelZeYG dFdG dGeUelZeYG dHdI dIelZeYG dJdK dKelZeYG dLdM dMelZeYG dNdO dOelZeYG dPdQ dQelZG dRdS dSelZeYG dTdU dUeZeYG dVdW dWeZeYG dXdY dYeSZeYegG dZd[ d[eZeYG d\d] d]eSZed^kr$ec  dS dS )`    )sqrtNreducerandn)defaultdict
namedtuple)cyclechain)njitprangeparallel_chunksizeget_parallel_chunksizeset_parallel_chunksizeset_num_threadsget_num_threadstypeof)typesutils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_jitablec                   @   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._)test_module
test_classtimeout)
__module__idsplitsubprocess_test_runner_TIMEOUT)selfthemodtest_clazz_name rT   ?/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_parfors.pyrunnerM   s   
zTestParforsRunner.runnerc                 C      |    d S NrV   rQ   rT   rT   rU   test_TestParforBasicU      z&TestParforsRunner.test_TestParforBasicc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforNumericalMiscX   r\   z.TestParforsRunner.test_TestParforNumericalMiscc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforNumPy[   r\   z&TestParforsRunner.test_TestParforNumPyc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParfors^   r\   z"TestParforsRunner.test_TestParforsc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsBitMaska   r\   z)TestParforsRunner.test_TestParforsBitMaskc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsDiagnosticsd   r\   z-TestParforsRunner.test_TestParforsDiagnosticsc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsLeaksg   r\   z'TestParforsRunner.test_TestParforsLeaksc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsMiscj   r\   z&TestParforsRunner.test_TestParforsMiscc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsOptionsm   r\   z)TestParforsRunner.test_TestParforsOptionsc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsSlicep   r\   z'TestParforsRunner.test_TestParforsSlicec                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestParforsVectorizers   r\   z,TestParforsRunner.test_TestParforsVectorizerc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestPrangeBasicv   r\   z&TestParforsRunner.test_TestPrangeBasicc                 C   rW   rX   rY   rZ   rT   rT   rU   test_TestPrangeSpecificy   r\   z)TestParforsRunner.test_TestPrangeSpecificN)__name__rL   __qualname___numba_parallel_test_platformmachinerP   rV   r[   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rT   rT   rT   rU   rD   ?   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.
    NrT   abrT   rT   rU   null_comparer   s   ry   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)r0   cflagsnrtpflagsr   ParallelOptionsauto_parallelfast_pflagsFastMathOptionsfastmathsuperrz   __init__rQ   args	__class__rT   rU   r      s   zTestParforsBase.__init__c                 C   s   t |||dS N)flags)r/   )rQ   funcsigr   rT   rT   rU   _compile_this      zTestParforsBase._compile_thisc                 C      | j ||| jdS r   )r   r}   rQ   r   r   rT   rT   rU   compile_parallel      z TestParforsBase.compile_parallelc                 C   r   r   )r   r   r   rT   rT   rU   compile_parallel_fastmath   r   z)TestParforsBase.compile_parallel_fastmathc                 C   r   r   )r   r{   r   rT   rT   rU   compile_njit   r   zTestParforsBase.compile_njitc                 O   s2   t dd |D }| ||}| ||}||fS )Nc                 S      g | ]}t |qS rT   numbar   .0xrT   rT   rU   
<listcomp>       z/TestParforsBase.compile_all.<locals>.<listcomp>)tupler   r   )rQ   pyfuncr   kwargsr   cpfunccfuncrT   rT   rU   compile_all   s   zTestParforsBase.compile_allc                 O   sZ  | dd}| dd}| dd}| dd}	| dd}
dd	 }|| }|| }|| }|j| }|| }|j| }|
du ratjj||fi | tjj||fi | | t|t| n*t|t|
kskJ t||||
D ]\}}}}|||fi | |||fi | qr|	r| 	|| |dur|j||  }tjj||fi | dS 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 ]K}t|tjr||d q	t|tjr(||  q	t|tjr4|| q	t|t rB|t	| q	t|t
rQ||d d   q	tdt |S )Nkz%Unsupported argument type encountered)r   
isinstancenpndarrayappendcopynumbernumbersNumberdeepcopylist
ValueError)r   new_argsr   rT   rT   rU   	copy_args   s    

z:TestParforsBase.check_parfors_vs_others.<locals>.copy_args)
popentry_pointr   testingassert_almost_equalassertEqualtypelenzipr   )rQ   r   r   r   r   r   r   r   r   r   check_args_for_equalityr   py_argspy_expected	njit_argsnjit_outputparfor_argsparfor_outputpyargnjitarg	parforargargcompparfor_fastmath_outputrT   rT   rU   check_parfors_vs_others   s<   


z'TestParforsBase.check_parfors_vs_othersc                 O   s6   | j |g|R  \}}| j|||g|R i | 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   rQ   r   r   r   r   r   rT   rT   rU   check  s    zTestParforsBase.checkc              	   K   s\   | D ](}|  ttt| | j|g|R i | W d   n1 s&w   Y  qdS )zHRun self.check(impl, ...) on array data generated from arg_gen.
        N)subTestr   mapr   r   )rQ   implarg_genr   r   rT   rT   rU   check_variants  s   
zTestParforsBase.check_variantsc              	   K   sd   | D ],}|  ttt| ttt|}| t||d W d   n1 s*w   Y  qdS )zXRun self.countParfors(impl, ...) on array types generated from
        arg_gen.
           N)r   r   r   r   r   assertGreaterEqualcountParfors)rQ   r   r   r   r   argtysrT   rT   rU   count_parfors_variants$  s   
z&TestParforsBase.count_parfors_variantsc                 C   sH   d}|d ur|dv 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)rQ   cresr   scheduler_strmsgrT   rT   rU   r   .  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   s6    t dd V  t dd V  t dd V  d S Nr   r      r   linspacerT   nrT   rU   gen=  s   z)TestParforsBase.gen_linspace.<locals>.genc                    s   g | ]}t  qS rT   )nextr   i)srcrT   rU   r   C      z0TestParforsBase.gen_linspace.<locals>.<listcomp>)r	   range)rQ   r   ctr   rT   )r   r   rU   gen_linspace:  s   
zTestParforsBase.gen_linspacec                 c   sr    | 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      g | ]}| d qS )r      reshaper   rT   rT   rU   r   L      z9TestParforsBase.gen_linspace_variants.<locals>.<listcomp>   )r   r   c                 S   r   rT   r   asfortranarrayr   rT   rT   rU   r   P  r   c                 S   r   ))r   r      r   r   rT   rT   rU   r   S  r      c                 S   r   rT   r   r   rT   rT   rU   r   W  r   N)r   )rQ   r   arr2dsarr3dsrT   rT   rU   gen_linspace_variantsE  s   z%TestParforsBase.gen_linspace_variantsNc                    s8    fdd|D }|dur|D ]
}|t |v sJ q|S )z. helper function to filter out modules by namec                    s   g | ]	} |j v r|qS rT   namer   magicstrrT   rU   r   [  s    z/TestParforsBase._filter_mod.<locals>.<listcomp>N)str)rQ   modr  checkstrfiltr   rT   r   rU   _filter_modY  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      g | ]}|qS rT   rT   r   rT   rT   rU   r   c      z7TestParforsBase._get_gufunc_modules.<locals>.<listcomp>)r  )r   _codegen_engine_ee_modulesr  )rQ   r   r  r  r  rT   rT   rU   _get_gufunc_modulesa  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   )rQ   r   fnr  gufunc_modsr   r  rT   rT   rU   _get_gufunc_infof  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  )rQ   r   rT   rT   rU   _get_gufunc_irp  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 rX   )r  emit_assembly)r  tmrT   rU   emit_asm  r   z1TestParforsBase._get_gufunc_asm.<locals>.emit_asm)r   r	  _tmr  )rQ   r   r  rT   r  rU   _get_gufunc_asmz  s   
zTestParforsBase._get_gufunc_asmc           
         sP     ||} |}dd } fdd}| D ]\}}||}	||	 qd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 ur|| q|S )Nz\bfast\b)
splitlinesresearchr   )r   splitted	fast_instr   mrT   rT   rU   _get_fast_instructions  s   
z?TestParforsBase.assert_fastmath.<locals>._get_fast_instructionsc                    sF   d}| D ]}d}|D ]}|d }||v r|d7 }q
  |dk qd S )N)faddfsubfmulfdivfremfcmpr   z fastr   )
assertTrue)instrsopsinstcountopmatchrZ   rT   rU   _assert_fast  s   z5TestParforsBase.assert_fastmath.<locals>._assert_fastN)r   r  items)
rQ   r   r   r   _irr   r.  r   guirr*  rT   rZ   rU   assert_fastmath  s   
	

zTestParforsBase.assert_fastmathrX   )ri   rL   rj   __doc__rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r2  __classcell__rT   rT   r   rU   rz      s,    X




rz   c                 C   s   t | | }d| | }|t | }|| | | | }|| }	dd|  }
dd|	  }|t | |  }|| }| |
 | }|| |  }|S )N      ?      ?)r   logr   exp)sptpricestrikerate
volatilitytimevlogtermpowtermdend1d2NofXd1NofXd2futureValuec1callputrT   rT   rU   blackscholes_impl  s   rI  c                 C   sF   t |D ]}|tddt|  t||   d |  |8 }q|S Nr6  )r   r   dotr8  )YXw
iterationsr   rT   rT   rU   lr_impl  s   6rP  c                    s|   | j \}t|D ]0}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 | ]}t t d d f |d d f  d qS Nr   )r   r   sumr   j)A	centroidsr   rT   rU   r     s    22example_kmeans_test.<locals>.<listcomp>.<listcomp>r   r   )rU  rV  	numCenterr   rU   r     
    
z'example_kmeans_test.<locals>.<listcomp>c                    s    g | ]} |d d f   qS rX   argminr   )distrT   rU   r     s     c                    s&   g | ]  fd dt D qS )c                    s0   g | ]}t  k|f t k qS rT   r   rR  rS  )rU  r   labelsrT   rU   r     s    (rW  rX  rY  )rU  Dra  r[  rU   r     r\  )shaper   r   array)rU  rZ  numIterinit_centroidsNlrT   )rU  rb  rV  r_  ra  rZ  rU   example_kmeans_test  s   

ri  c                 K   s  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)|_*W d    ||fS 1 sw   Y  ||fS )
Nr   T)typedzbefore-inferencerT   )func_irtypemap	calltypesliftedlifted_fromr   return_typehtml_output)swappedzafter-inference)diagnostics)+r   Contextr   
CPUContextr   run_frontendr~   TestPipeliner$   nested_contextrefreshr   InlineClosureCallPassstaterk  runr   rewrite_registryapplyr   type_inference_stage	typingctx	targetctxr   rl  rp  rm  r%   TypeAnnotationr   HTMLr   parforsparforParforDiagnosticsPreParforPassreplaced_fnsr0   
ParforPassmetadatar(   blocks_definitions)	test_funcr   kwsr  r  test_iroptionstpinline_passrH   rs  preparfor_passr   parfor_passrT   rT   rU   get_optimized_numba_ir  sd   





++r  c           
      K   s^   t | |fi |\}}d}|j D ]\}}t|jD ]\}}	t|	tjjj	r+|d7 }qq|S Nr   r   )
r  r  r/  	enumeratebodyr   r   r  r  Parfor)
r  r   r  r  r  	ret_countlabelblockr   r*  rT   rT   rU   r   
  s   r   c                 K   s&   t | |fi |\}}t|j|jjS rX   )r  _count_arrays_innerr  r{  rl  r  r   r  r  r  rT   rT   rU   countArrays  s   r  c                 K   sj   t | |fi |\}}|j}d}| D ]\}}t|jD ]\}	}
t|
tjjj	r1|t
|
jj7 }qq|S Nr   )r  r  r/  r  r  r   r   r  r  r  r   
init_block)r  r   r  r  r  r  r  r  r  r   r*  rT   rT   rU   get_init_block_size  s   r  c           	      C   s   d}t  }|  D ]>\}}t|jD ]4\}}t|tjjjr/|j	
 }|j|d< |t||7 }t|tjrFt||jj tjrF||jj qq	|t|7 }|S r  )setr/  r  r  r   r   r  r  r  	loop_bodyr   r  r  r   Assigntargetr   r   ArrayCompatibleaddr   )	r  rl  r  arr_setr  r  r   r*  parfor_blocksrT   rT   rU   r  '  s$   


r  c                 K   s<   t | |fi |\}}d}|j D ]	}|t||7 }q|S r  )r  r  values_count_array_allocs_inner)r  r   r  r  r  r  r  rT   rT   rU   countArrayAllocs9  s
   r  c                 C   s   d}|j D ]J}t|tjjjr&|t| |j7 }|j	 D ]	}|t| |7 }qt|t
jrOt|jt
jrO|jjdkrOtt| |jdksKtt| |jdkrO|d7 }q|S )Nr   rG  )emptynumpy)r-   znumba.np.unsafe.ndarrayr   )r  r   r   r  r  r  r  r  r  r  r   r  valueExprr,  r'   r&   )rk  r  r  r*  rx   rT   rT   rU   r  B  s$   

r  c                 K   s(   t | |fi |\}}t||j|jjS rX   )r  &_count_non_parfor_array_accesses_innerr  r{  rl  r  rT   rT   rU   countNonParforArrayAccessesS  s   r  c           	      C   s  d}|d u r	t  }| D ]~\}}|jD ]v}t|tjjjr9||j	j
 |j }|j|d< |t| |||7 }qt|rUt||jjj
 tjrUt| t||sU|d7 }qt|rpt||jj
 tjrpt| t||sp|d7 }qt|tjrt|jtjr|jj
|v r||jj
 qq|S r  )r  r/  r  r   r   r  r  r  r  	index_varr   r  r   r  r  r*   r  r   r  _uses_indicesr,   r+   r  r   r  Var)	f_irr  rl  parfor_indicesr  r  r  stmtr  rT   rT   rU   r  X  sJ   







r  c                 C   sX   |j |v rdS tt| |}t|tjr*|jdkr*tdd |jD }t	||@ dkS dS )NTbuild_tuplec                 s   s    | ]}|j V  qd S rX   r   )r   vrT   rT   rU   	<genexpr>  s    z _uses_indices.<locals>.<genexpr>r   F)
r   r'   r)   r   r   r  r,  r  r/  r   )r  index	index_setind_defvarnamesrT   rT   rU   r  z  s   
r  c                   @      e Zd Zdd ZdS )rw  c                 C   sN   t  | _|| j_|| j_|| j_|| j_d | j_d | j_d | j_	i | j_
d S rX   )r   	StateDictr{  r  r  r   rk  rl  rp  rm  r  )rQ   r  r  r   r  rT   rT   rU   r     s   
zTestPipeline.__init__N)ri   rL   rj   r   rT   rT   rT   rU   rw    s    rw  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   sD   t j| g|R   ttdd}tdtd||jg| _d S )N      (@r   r         @      @)rz   r   r   r   arangeTsimple_args)rQ   r   r  rT   rT   rU   r     s    zTestParforBasic.__init__c                 C   R   dd }|  t}| | W d    n1 sw   Y  | dt|j d S )Nc                   S   
   t dS )NrT   r   onesrT   rT   rT   rU   	test_impl     
z0TestParforBasic.test_simple01.<locals>.test_impl'@do_scheduling' not foundassertRaisesAssertionErrorr   r   r  	exceptionrQ   r  raisesrT   rT   rU   test_simple01  
   zTestParforBasic.test_simple01c                 C      dd }|  | d S )Nc                   S   r  )Nr   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple02.<locals>.test_implr   rQ   r  rT   rT   rU   test_simple02     zTestParforBasic.test_simple02c                 C   r  )Nc                   S   r  Nr   r   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple03.<locals>.test_implr  r  rT   rT   rU   test_simple03  r  zTestParforBasic.test_simple03c                 C   r  )Nc                   S   r  Nr   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple04.<locals>.test_implr  r  rT   rT   rU   test_simple04  r  zTestParforBasic.test_simple04c                 C   r  )Nc                   S   s   t jdt jdS )Nr  dtyper   r  
complex128rT   rT   rT   rU   r    s   z0TestParforBasic.test_simple07.<locals>.test_implr  r  rT   rT   rU   test_simple07  r  zTestParforBasic.test_simple07c                 C   r  )Nc                   S   s   t dt d S r  r  rT   rT   rT   rU   r       z0TestParforBasic.test_simple08.<locals>.test_implr  r  rT   rT   rU   test_simple08  r  zTestParforBasic.test_simple08c                 C   r  )Nc                   S   r  )Nr   r   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple09.<locals>.test_implr  r  rT   rT   rU   test_simple09  r  zTestParforBasic.test_simple09c                 C   r  )Nc                   S   r  )Nr   r   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple10.<locals>.test_implr  r  rT   rT   rU   test_simple10  r  zTestParforBasic.test_simple10c                 C   r  )Nc                   S   s   t dd S Nr   r   r6  r  rT   rT   rT   rU   r    r   z0TestParforBasic.test_simple11.<locals>.test_implr  r  rT   rT   rU   test_simple11  r  zTestParforBasic.test_simple11c                 C   r  )Nc                   S   s   t dt d S r  r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple12.<locals>.test_implr  r  rT   rT   rU   test_simple12  r  zTestParforBasic.test_simple12c                 C   r  )Nc                   S   r  rJ  )r   r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple13.<locals>.test_implr  r  r  rT   rT   rU   test_simple13  r  zTestParforBasic.test_simple13c                 C   r  )Nc                   S   s   t ddd d S )Nr  r      r  rT   rT   rT   rU   r    r  z0TestParforBasic.test_simple14.<locals>.test_implr  r  rT   rT   rU   test_simple14  r  zTestParforBasic.test_simple14c                 C       dd }| j |g| jR   d S )Nc                 S   s   | |  S rX   rT   v1v2m1m2rT   rT   rU   r       z0TestParforBasic.test_simple15.<locals>.test_implr   r  r  rT   rT   rU   test_simple15     zTestParforBasic.test_simple15c                 C   r  )Nc                 S   s   || S rX   rT   r  rT   rT   rU   r    r  z0TestParforBasic.test_simple16.<locals>.test_implr  r  rT   rT   rU   test_simple16  r   zTestParforBasic.test_simple16c                 C   r  )Nc                 S   s   ||  S rX   rT   r  rT   rT   rU   r    r  z0TestParforBasic.test_simple17.<locals>.test_implr  r  rT   rT   rU   test_simple17  r   zTestParforBasic.test_simple17c                 C   r  )Nc                 S   s   |j tj|d  S r  )r  r   linalgsvdr  rT   rT   rU   r       z0TestParforBasic.test_simple18.<locals>.test_implr  r  rT   rT   rU   test_simple18     zTestParforBasic.test_simple18c                 C   r  )Nc                 S   s   t ||S rX   r   rK  r  rT   rT   rU   r    r\   z0TestParforBasic.test_simple19.<locals>.test_implr  r  rT   rT   rU   test_simple19  r  zTestParforBasic.test_simple19c                 C   s\   dd }|  t}| j|g| jR   W d    n1 sw   Y  | dt|j d S )Nc                 S   s   t ||S rX   r  r  rT   rT   rU   r    r\   z0TestParforBasic.test_simple20.<locals>.test_implr  )r  r  r   r  r   r  r  r  rT   rT   rU   test_simple20  s
   zTestParforBasic.test_simple20c                 C   r  )Nc                 S      t | | S rX   r  r  rT   rT   rU   r    r\   z0TestParforBasic.test_simple21.<locals>.test_implr  r  rT   rT   rU   test_simple21  r  zTestParforBasic.test_simple21c                 C   r  )Nc                 S   s   t | |  S rX   r`  r  rT   rT   rU   r  	  r   z0TestParforBasic.test_simple22.<locals>.test_implr  r  rT   rT   rU   test_simple22  r   zTestParforBasic.test_simple22c                 C   r  )Nc                 S   s2   d|  }d|  }dt |d |d  dk  d S )Nr   r   r   r   r`  )r  r  r  r  r   yrT   rT   rU   r    s   "z0TestParforBasic.test_simple23.<locals>.test_implr  r  rT   rT   rU   test_simple23     zTestParforBasic.test_simple23c                 C   r  )Nc                  S   s2   d} t | | f}t | }t |d d |f S )Nr  )r   r  r  rR  )r   rU  rx   rT   rT   rU   r    s   
z0TestParforBasic.test_simple24.<locals>.test_implr  r  rT   rT   rU   test_simple24  s   zTestParforBasic.test_simple24c                 C   s    dd }| j |g| jR   dS )zAsame as corresponding test_simple_<n> case but using operator.addc                 S   r  rX   operatorr  r  rT   rT   rU   r    r\   z:TestParforBasic.test_simple_operator_15.<locals>.test_implNr  r  rT   rT   rU   test_simple_operator_15  s   z'TestParforBasic.test_simple_operator_15c                 C   r  )Nc                 S   s   t ||S rX   r  r  rT   rT   rU   r  &  r\   z:TestParforBasic.test_simple_operator_16.<locals>.test_implr  r  rT   rT   rU   test_simple_operator_16$     z'TestParforBasic.test_simple_operator_16c                 C   r  )Nc                 S   s   t || S rX   r  r  rT   rT   rU   r  -  r\   z:TestParforBasic.test_simple_operator_17.<locals>.test_implr  r  rT   rT   rU   test_simple_operator_17+  r  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   rT   rw   rT   rT   rU   r  4  s   z5TestParforBasic.test_inplace_alias.<locals>.test_implc                 S      t j| | d S rX   r   r   assert_equalrv   rT   rT   rU   comparer8  r   z4TestParforBasic.test_inplace_alias.<locals>.comparerr   r   r   r  r   )rQ   r  r  r   rT   rT   rU   test_inplace_alias2  s   
z"TestParforBasic.test_inplace_aliasN)"ri   rL   rj   r3  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  rT   rT   rT   rU   r    sH    






r  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ranfrR  )r   r   r  rT   rT   rU   r  D  s   "z2TestParforNumericalMisc.test_pi.<locals>.test_impli r   decimalr   )r   r   r   r   int64r  intpr  rT   rT   rU   test_piC  s   zTestParforNumericalMisc.test_pic                 C   s*   t jd d  fd }| tt|d d S Nrq   r   )r   float64r   r   rI  r   rT   rT   rU   test_blackscholesM  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   rP  r  r   rT   rT   rU   test_logistic_regressionR  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   ri  r   Arrayr)  r&  r   r  )rQ   rg  rb  centersrU  rf  arg_typsrT   rT   rU   test_kmeansY  s   
z#TestParforNumericalMisc.test_kmeansN)	ri   rL   rj   r3  r'  r*  r>   r,  r3  rT   rT   rT   rU   r   ?  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.S )/TestParforNumPyz'Tests NumPy functionality under parforsc                 C   s>   dd }t ddddd}t ddd}| ||| d S )Nc                 S      t | |S rX   r  rw   r  rT   rT   rU   r  p  r\   z-TestParforNumPy.test_mvdot.<locals>.test_implr   r   r  r   r   )r   r   r   r   )rQ   r  rU  r  rT   rT   rU   
test_mvdotn  s   zTestParforNumPy.test_mvdotc                    sb   t jt jt jt jfD ]$  fdd}| |d | t|tj	fd | t
|tjfd q
d S )Nc                    s"   t | } |}| }|| S rX   r   r  rR  )r   rU  r.  Br,  rT   rU   r  z  s   
zBTestParforNumPy.test_fuse_argmin_argmax_max_min.<locals>.test_impl   r   r   )r   r^  argmaxminmaxr   r   r   r   r%  r  r&  r  rT   r:  rU   test_fuse_argmin_argmax_max_minx  s   z/TestParforNumPy.test_fuse_argmin_argmax_max_minc                 C   "   dd }|  t|tjfd d S )Nc                 S   s   t | }|d S r  r   r   rU  rT   rT   rU   r       zDTestParforNumPy.test_np_random_func_direct_import.<locals>.test_implr   r   r   r   r%  r  rT   rT   rU   !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 qd S )Nc                 S   
   t | S rX   r   r  r   rT   rT   rU   
test_impl1  r  z/TestParforNumPy.test_arange.<locals>.test_impl1c                 S   s
   t |S rX   rF  )sr   rT   rT   rU   
test_impl2  r  z/TestParforNumPy.test_arange.<locals>.test_impl2c                 S      t | ||S rX   rF  )rH  r   trT   rT   rU   
test_impl3  r   z/TestParforNumPy.test_arange.<locals>.test_impl3            >@r   rq   r   complexr   )rQ   rG  rI  rL  argrT   rT   rU   test_arange  s   zTestParforNumPy.test_arangec                 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   r5  rX   r   )startstoprT   rT   rU   rG    r\   z1TestParforNumPy.test_linspace.<locals>.test_impl1c                 S   rJ  rX   r   )rT  rU  numrT   rT   rU   rI    r   z1TestParforNumPy.test_linspace.<locals>.test_impl2rM  rN  rO  r   rq   r      rP  )rQ   rG  rI  rR  rT   rT   rU   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 rX   meanrU  rT   rT   rU   r    r  z,TestParforNumPy.test_mean.<locals>.test_impld   r   r   sizer   r.  r   c                      
     dS r  r   rT   rZ   rT   rU   <lambda>     
 z+TestParforNumPy.test_mean.<locals>.<lambda>r   r!  r"  randintr   r   r   r   r0  r)  r   r   )rQ   r  rg  rU  r9  data_genrT   rZ   rU   	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   rY  rX   )varr\  rT   rT   rU   r    r  z+TestParforNumPy.test_var.<locals>.test_implr]  r   r   r^                ?r   r.  r   c                      r`  r  ra  rT   rZ   rT   rU   rb    rc  z*TestParforNumPy.test_var.<locals>.<lambda>rd  )rQ   r  rg  rU  r9  r.  rf  rT   rZ   rU   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   rY  rX   )stdr\  rT   rT   rU   r    r  z+TestParforNumPy.test_std.<locals>.test_implr]  r   r   r^  ri  r   r.  r   c                      r`  r  ra  rT   rZ   rT   rU   rb    rc  z*TestParforNumPy.test_std.<locals>.<lambda>)r   r!  r"  re  r   r   r0  r)  r   r   r   r   )rQ   r  rg  rU  r9  r.  argtyrf  rT   rZ   rU   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 rX   )r   r!  r"  rA  rT   rT   rU   r       z5TestParforNumPy.test_random_parfor.<locals>.test_implr   NrC  r  rT   rT   rU   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^          r6  r   r   )highr_  r   )	r   r!  standard_normalr   normal	chisquarere  
triangularrR  r   rU  r9  r.  rb  EFrT   rT   rU   r    s   z/TestParforNumPy.test_randoms.<locals>.test_implrN  g?)rtolr   )r   r   r   r   r   r   assert_allcloser   r   r   r%  rQ   r  r   r   r   	py_outputrT   rT   rU   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 rp  )r   r!  rs  r   rt  ru  re  rv  rw  rT   rT   rU   r    s   z4TestParforNumPy.test_dead_randoms.<locals>.test_implrN  r   )r   r   r   r   r   r   r   r%  r|  rT   rT   rU   test_dead_randoms  s   	
z!TestParforNumPy.test_dead_randomsc              	      sv  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 ]7}	 	|	t
jd d  f}
 t}|
t jg t jd	 W d    n1 sw   Y   |t|j qc fd
d} ||  ||  ||  || d S )Nc                 S   rY  rX   r=  r\  rT   rT   rU   rG    r  z,TestParforNumPy.test_min.<locals>.test_impl1c                 S   rE  rX   )r   r=  r\  rT   rT   rU   rI    r  z,TestParforNumPy.test_min.<locals>.test_impl2   r   r^  zDzero-size array to reduction operation minimum which has no identityr  c                      r`  r  ra  rT   rZ   rT   rU   rb  &  rc  z*TestParforNumPy.test_min.<locals>.<lambda>r   r!  r"  re  astypeint32rd  infr   r   r   r%  r  r   r   r   r  r  r   r   rQ   rG  rI  r   rU  r9  r.  rb  r   r   pcfuncerf  rT   rZ   rU   test_min  s6   zTestParforNumPy.test_minc              	      sz  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 ]7}	 	|	t
jd d  f}
 t}|
t jg t jd	 W d    n1 sw   Y   |t|j qe fd
d} ||  ||  ||  || d S )Nc                 S   rY  rX   )r>  r\  rT   rT   rU   rG  -  r  z,TestParforNumPy.test_max.<locals>.test_impl1c                 S   rE  rX   )r   r>  r\  rT   rT   rU   rI  0  r  z,TestParforNumPy.test_max.<locals>.test_impl2r  r   r^  zDzero-size array to reduction operation maximum which has no identityr  c                      r`  r  ra  rT   rZ   rT   rU   rb  K  rc  z*TestParforNumPy.test_max.<locals>.<lambda>r  r  rT   rZ   rU   test_max,  s6   zTestParforNumPy.test_maxc              	      s|  dd }dd }d}t g d}t jjd|dt j}t j||f}t d	d
t jddg} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]7}	 	|	t
jd d  f}
 t}|
t jg t jd W d    n1 sw   Y   |t|j qf fdd} ||  ||  ||  || d S )Nc                 S   rY  rX   )r<  r\  rT   rT   rU   rG  R  r  z/TestParforNumPy.test_argmax.<locals>.test_impl1c                 S   rE  rX   )r   r<  r\  rT   rT   rU   rI  U  r  z/TestParforNumPy.test_argmax.<locals>.test_impl2r  )r6  rq  r         @r  r   r^  r6  rq  r  r  z*attempt to get argmax of an empty sequencer  c                      r`  r  ra  rT   rZ   rT   rU   rb  o  rc  z-TestParforNumPy.test_argmax.<locals>.<lambda>r   rd  r!  re  r  r  r"  nanr   r   r   r%  r  r   r   r   r  r  r   r   r  rT   rZ   rU   test_argmaxQ  6   zTestParforNumPy.test_argmaxc              	      s|  dd }dd }d}t g d}t jjd|dt j}t j||f}t d	d
t jd
dg} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]7}	 	|	t
jd d  f}
 t}|
t jg t jd W d    n1 sw   Y   |t|j qf fdd} ||  ||  ||  || d S )Nc                 S   rY  rX   r]  r\  rT   rT   rU   rG  v  r  z/TestParforNumPy.test_argmin.<locals>.test_impl1c                 S   rE  rX   )r   r^  r\  rT   rT   rU   rI  y  r  z/TestParforNumPy.test_argmin.<locals>.test_impl2r  )r6  rq  r  rq  r  r   r^  r6  rq  r  z*attempt to get argmin of an empty sequencer  c                      r`  r  ra  rT   rZ   rT   rU   rb    rc  z-TestParforNumPy.test_argmin.<locals>.<lambda>r  r  rT   rZ   rU   test_argminu  r  zTestParforNumPy.test_argminc                 C   sF   dd }t d}| || ttjddf}| t||d d S )Nc                 S      |  d | S N      @fillr   rT   rT   rU   r       
z4TestParforNumPy.test_ndarray_fill.<locals>.test_implr   r   r.  r   zerosr   r   r0  r)  r   r   rQ   r  r   rl  rT   rT   rU   test_ndarray_fill  
   
z!TestParforNumPy.test_ndarray_fillc                 C   sF   dd }t d}| || ttjddf}| t||d d S )Nc                 S   r  r  r  r  rT   rT   rU   r    r  z6TestParforNumPy.test_ndarray_fill2d.<locals>.test_implr   r   r   r.  r   r  r  rT   rT   rU   test_ndarray_fill2d  r  z#TestParforNumPy.test_ndarray_fill2dc                 C   ,   dd }t g d}d}| ||| d S )Nc                 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   rw   rx   result_matrixsub_azresult_datarT   rT   rU   r       z<TestParforNumPy.test_reshape_with_neg_one.<locals>.test_implr6  r  r  r        @      @r  g       @g      "@g      $@g      &@r  r   r   rd  r   rQ   r  rw   rx   rT   rT   rU   test_reshape_with_neg_one     
z)TestParforNumPy.test_reshape_with_neg_onec                 C   r  )Nc                 S   r  )Nr   r  r   ir  r  rT   rT   rU   r    r  z>TestParforNumPy.test_reshape_with_large_neg.<locals>.test_implr  r   r  r  rT   rT   rU   test_reshape_with_large_neg  r  z+TestParforNumPy.test_reshape_with_large_negc                 C   st   |  tj}tdddd }tg d}d}||| W d    n1 s(w   Y  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  )rw   rx   rmr  r  r  rT   rT   rU   r    s   zETestParforNumPy.test_reshape_with_too_many_neg_one.<locals>.test_implr  r   z7The reshape API may only include one negative argument.)	r  r   UnsupportedRewriteErrorr   r   rd  r   r  r  )rQ   raisedr  rw   rx   r   rT   rT   rU   "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 rX   )r   rR  prodr=  r>  rh  r   rT   rT   rU   r    s   2z0TestParforNumPy.test_0d_array.<locals>.test_impl   Fr   )r   r   rd  r  rT   rT   rU   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 rQ  )r   rR  realimag)r  rT   rT   rU   r    s   z6TestParforNumPy.test_real_imag_attr.<locals>.test_implrq   y      ?      ?r   )r   r  r   r   r   r   r  )rQ   r  r  rT   rT   rU   test_real_imag_attr  s   $z#TestParforNumPy.test_real_imag_attrN)ri   rL   rj   r3  r>   r7  r?  rD  rS  rX  rg  rj  rm  ro  r~  r  r  r  r  r  r  r  r  r  r  r  r  rT   rT   rT   rU   r4  j  s2    
	
%%$$		r4  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   s   |  tj(}tdddd }tddddd	}tddd	}||| W d
   n1 s1w   Y  d}| |t|j	 d
S )zu
        This test is in place until issues with the 'parallel'
        target on 32 bit hardware are fixed.
        Tr  c                 S   r5  rX   r  r6  rT   rT   rU   ddot     zHTestParforsUnsupported.test_unsupported_combination_raises.<locals>.ddotr   r   r  r   r   NzCThe 'parallel' target is not currently supported on 32 bit hardware)
r  r   UnsupportedParforsErrorr   r   r   r   r   r  r  )rQ   r  r  rU  r  r   rT   rT   rU   #test_unsupported_combination_raises  s   
	z:TestParforsUnsupported.test_unsupported_combination_raisesN)	ri   rL   rj   r3  unittestskipIfr=   r>   r  rT   rT   rT   rU   r    s
    r  c                   @   s$  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Z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 ZFdS )TestParforsz6 Tests cpython, reduction and various parfors featuresc                    s    dd }  | fdd d S )Nc                 S   s   | | | S rX   rT   )rw   r   r  rT   rT   rU   r    r\   z,TestParfors.test_arraymap.<locals>.test_implc                      r`  Nr   ra  rT   rZ   rT   rU   rb    rc  z+TestParfors.test_arraymap.<locals>.<lambda>)r   r  rT   rZ   rU   test_arraymap  s   zTestParfors.test_arraymapc                 C   (   dd }|  | | t|dd d S )Nc                  S   s"   t d} t d}t | | S )Nr   r      )r   rd  r  rR  rM  rL  rT   rT   rU   r       

z0TestParfors.test_0d_broadcast.<locals>.test_implrT   r   r   r   r   r  rT   rT   rU   test_0d_broadcast     
zTestParfors.test_0d_broadcastc                 C   r  )Nc                  S   s"   t d} t d}t | | S Nr  )r   r  r  rR  r  rT   rT   rU   r    r  z-TestParfors.test_2d_parfor.<locals>.test_implrT   r   r  r  rT   rT   rU   test_2d_parfor  r  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 r  r   r  r  r  rT   rT   rU   case1%  s   

z)TestParfors.test_nd_parfor.<locals>.case1c                      s   t   dS rQ  )r
   r   rT   r  rQ   rT   rU   rb  *  s    z,TestParfors.test_nd_parfor.<locals>.<lambda>c                 S   s   t | | S rX   r`  r  rT   rT   rU   r  ,  r   z-TestParfors.test_nd_parfor.<locals>.test_impl)r   r   )rQ   rf  r  rT   r  rU   test_nd_parfor$  s
   zTestParfors.test_nd_parforc                    s,   ddl m   fdd}d}| || d S )Nr   r  c                    s    | }|d S r  rT   rA  r  rT   rU   r  4  rB  z9TestParfors.test_np_func_direct_import.<locals>.test_implo   )r  r  r   rQ   r  r   rT   r  rU   test_np_func_direct_import2  s   z&TestParfors.test_np_func_direct_importc                 C   sr   dd }|  |dd | t}tdd|}|dd W d    n1 s'w   Y  d}| |t|j d S )Nc                 S   s"   t | }t |}t || S rX   r8  )r  r   rU  r9  rT   rT   rU   r  ;  r  z2TestParfors.test_size_assertion.<locals>.test_implr   Tr  	   zSizes of A, B do not match)r   r  r  r   r   r  r  )rQ   r  r  r   r   rT   rT   rU   test_size_assertion:  s   zTestParfors.test_size_assertionc                 C   s6   dd }d}t j|}t |}| |||| d S )Nc                 S   sT   t dD ]"}t|| d |d | d D ]}d||< | | dkr&d||< qq|S )Nr   r   r   r   r   r   )r   is_positiverg  r   rT  rT   rT   rU   r  I  s   "z'TestParfors.test_cfg.<locals>.test_implr]  )r   r!  randr  r   )rQ   r  rg  r   r  rT   rT   rU   test_cfgG  s
   	
zTestParfors.test_cfgc                 C   s  dd }d}t j|}| || t jjd|dt j}| || dd }|   | | W d    n1 s<w   Y  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 S )Nc                 S   s   d}t dd | |S )Nr   c                 S   s
   t | |S rX   r  rv   rT   rT   rU   rb  Z  rc  <TestParfors.test_reduce.<locals>.test_impl.<locals>.<lambda>r   )rU  init_valrT   rT   rU   r  X  s   z*TestParfors.test_reduce.<locals>.test_implr  r   r^  c                  S   s   dd } t | tg ddS )Nc                 S   s   | d S rQ  rT   r  rT   rT   rU   rb  d      r  r   r   r   r   rq   r   )r   r   rd  )grT   rT   rU   r  c  s      c                 S   s   t | | dk S r  r`  r\  rT   rT   rU   r  l  r   c                 S   s&   | d d df }t | |dkdf S )Nr   r   r   r`  rU  r9  rT   rT   rU   r  r  s   )   r   c                 S   s*   | d d df }t | |dkddf S )Nr   r   r   r   r`  r  rT   rT   rU   r  y  s   r   )r   r!  r"  r   re  r  r  assertTypingErrorr   r   r   r   r)  rQ   r  r   rU  rT   rT   rU   test_reduceW  s&   
*zTestParfors.test_reducec                 C   X   dd }d}|  t}| |d}W d    n1 sw   Y  | |t|j d S )Nc                  S   s    d} t dD ]}t| } q| S r  )r   cmathr   accr   rT   rT   rU   r    s   z9TestParfors.test_use_of_reduction_var1.<locals>.test_implCUse of reduction variable acc in an unsupported reduction function.rT   r  r   r   r   r  r  rQ   r  r   r  r  rT   rT   rU   test_use_of_reduction_var1  s   z&TestParfors.test_use_of_reduction_var1c                 C   sZ   dd }d}|  tj}| |d}W d    n1 sw   Y  | |t|j d S )Nc                  S   s   d} t dD ]}| d } q| S Nr]  r   r   r  rT   rT   rU   r       
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.rT   )r  r   NumbaValueErrorr   r   r  r  r  rT   rT   rU   test_unsupported_floordiv1  s   z&TestParfors.test_unsupported_floordiv1c                 C   r  )Nc                  S   s"   d} t dD ]}| |d N } q| S r  r  r  rT   rT   rU   r    s   z4TestParfors.test_unsupported_xor1.<locals>.test_implr  rT   r  r  rT   rT   rU   test_unsupported_xor1  s   z!TestParfors.test_unsupported_xor1c                 C   2   dd }d}|  || | t|tjfd d S )Nc                 S   s   t | }| S rX   r8  rA  rT   rT   rU   r    s   
z8TestParfors.test_parfor_array_access1.<locals>.test_implr  r   )r   r   r  r   r&  r  rT   rT   rU   test_parfor_array_access1  s   z%TestParfors.test_parfor_array_access1c                 C   r  )Nc                 S   sb   t | }d}d} tt|D ]}||| 7 }qtt|D ]}|| kr,| || 7 } q ||  S r  )r   r  r   r   r   r   rU  r  r   rT   rT   rU   r    s   
z8TestParfors.test_parfor_array_access2.<locals>.test_implr  r   r   r   r  r   r&  r  rT   rT   rU   test_parfor_array_access2  s   z%TestParfors.test_parfor_array_access2c                 C   sZ   dd }d}|  tj}| || W d    n1 sw   Y  | 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   r  r%  r   r   r   r  rT   rT   rU   r    s   z8TestParfors.test_parfor_array_access3.<locals>.test_implr  z Overwrite of parallel loop index)r  r   r  r   r   r  r  )rQ   r  r   r  rT   rT   rU   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
v  |j
d }d	}	d }
|jD ]}t|tjjjr[d
}	|}
qM| |	 d	}|
j D ]'}|jD ]!}t|tjrt|jtjr|jjdkrd
}| |
j|jjv  qmqh| | d S )Nc                 S   r5  rX   r  )rU  rx   rT   rT   rU   r    r\   z8TestParfors.test_parfor_array_access4.<locals>.test_implr  r   r   r.  r   r   FTr  )r   r!  r"  r   r  r   r0  r)  r'  r   r  r  r   r   r  r  r  r  r  r   r  r  r  r,  r  r/  )rQ   r  r   drU  rx   r  r  r  parfor_foundr  r  build_tuple_foundblrT   rT   rU   test_parfor_array_access4  sD   




z%TestParfors.test_parfor_array_access4c                 C   "   dd }t d}| || d S )Nc                 S   s,   t t| D ]
}| jd| |< q| d S Nr   r   )r   r   r   r  r   )rw   r   rT   rT   rU   r     s   z5TestParfors.test_parfor_dtype_type.<locals>.test_implr   r  )rQ   r  rw   rT   rT   rU   test_parfor_dtype_type  s   
z"TestParfors.test_parfor_dtype_typec                 C   r  )Nc                 S   s>   t | df}d}t| D ]}|||d d f  7 }q|S )Nr   r   )r   r  r   r   rR  r   rM  r  r   rT   rT   rU   r  
  s
   z8TestParfors.test_parfor_array_access5.<locals>.test_implr  r   r  r  rT   rT   rU   test_parfor_array_access5  s   z%TestParfors.test_parfor_array_access5c                 C   r  )Nc                 S   s&   t dD ]
}d| d  | d< q| d S )Nr   r   r   r  )outr   rT   rT   rU   r    s   z8TestParfors.test_parfor_hoist_setitem.<locals>.test_implr   r  )rQ   r  r
  rT   rT   rU   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 r  )r   r  r   rK  )rg  rb  rN  rM  rL  r   r9  rT   rT   rU   r  #  s   

z8TestParfors.test_parfor_generate_fuse.<locals>.test_implr  r   r   )r   r   r  r   r&  r   )rQ   r  r   r   rT   rT   rU   test_parfor_generate_fuse   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   r5  rX   )r   bitwise_andr  rT   rT   rU   r  4  r\   z.TestParfors.test_ufunc_expr.<locals>.test_implr   r   r   )r   r  uint8r   )rQ   r  rU  r9  rT   rT   rU   test_ufunc_expr2  s
   zTestParfors.test_ufunc_exprc                 C   r@  )Nc                 S   s(   t | f}t| D ]}|d ||< q	|S )Nr  )unsafe_emptyr   r   rU  r   rT   rT   rU   r  =  s   
z;TestParfors.test_find_callname_intrinsic.<locals>.test_implr   )r   r  r   r&  r  rT   rT   rU   test_find_callname_intrinsic<  s   z(TestParfors.test_find_callname_intrinsicc                 C      dd }|  |d d S )Nc                 S   s4   d}t | D ]}|d7 }qt | D ]}|d7 }q|S r   r  r   r  r   rT   rT   rU   r  I  s   

z7TestParfors.test_reduction_var_reuse.<locals>.test_implr  r  r  rT   rT   rU   test_reduction_var_reuseG  s   	z$TestParfors.test_reduction_var_reusec                 C   ,   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   rc  )rU  condrH  r   rT   rT   rU   r  V  s   z8TestParfors.test_non_identity_initial.<locals>.test_implr   boolr   r   r  r  r  rT   rT   rU   test_non_identity_initialT  s   $z%TestParfors.test_non_identity_initialc                 C   r  )Nc                 S   sF   d}d}t | jd D ]}|| r|d7 }|d7 }q|d7 }q|| S )Nr   r   r   r   r  )rU  r  rH  rK  r   rT   rT   rU   r  `  s   

z9TestParfors.test_if_not_else_reduction.<locals>.test_implr   r  r  r  rT   rT   rU   test_if_not_else_reduction^  s   $
z&TestParfors.test_if_not_else_reductionc                 C   r  )Nc                 S   sf   d}|d |d  }t |t j}t ||}t| D ]}||7 }qt| D ]}||7 }q*|S N   rp   r   r   r   r  int_r  r   r   r   r   shpr_  result1tmpr   rT   rT   rU   r  m  s   

z?TestParfors.test_two_d_array_reduction_reuse.<locals>.test_implr]  r  r  rT   rT   rU    test_two_d_array_reduction_reusel  s   z,TestParfors.test_two_d_array_reduction_reusec                 C   r  )Nc                 S   s6   t dt j}t| D ]}|t |gt j7 }q|S r  )r   r  r"  r   r   rd  )r   resultr   rT   rT   rU   r  ~  s   z9TestParfors.test_one_d_array_reduction.<locals>.test_implr]  r  r  rT   rT   rU   test_one_d_array_reduction}     z&TestParfors.test_one_d_array_reductionc                 C   r  )Nc                 S   sN   d}|d |d  }t |t j}t ||}t| D ]}||7 }q|S r  r!  r#  rT   rT   rU   r    s   
z9TestParfors.test_two_d_array_reduction.<locals>.test_implr]  r  r  rT   rT   rU   test_two_d_array_reduction  s   z&TestParfors.test_two_d_array_reductionc                 C   r  )Nc                 S   sB   d}t |t j}t g d|}t| D ]}||7 }q|S )Nr   )r6  r  r  r  r  r  )r   r  float32rd  r   r   r   r   r$  r%  r&  r   rT   rT   rU   r    s   
zJTestParfors.test_two_d_array_reduction_with_float_sizes.<locals>.test_implr]  r  r  rT   rT   rU   +test_two_d_array_reduction_with_float_sizes  s   
z7TestParfors.test_two_d_array_reduction_with_float_sizesc                 C   r  )Nc                 S   s@   d}dt |t j }dt | }t| D ]}||9 }q|S )Nr  r   )r   r  r"  	ones_liker   r   r-  rT   rT   rU   r    s   
z>TestParfors.test_two_d_array_reduction_prod.<locals>.test_implr]  r  r  rT   rT   rU   test_two_d_array_reduction_prod  s   
z+TestParfors.test_two_d_array_reduction_prodc                 C   r  )Nc                 S   s8   d}t |t j}t| D ]}|t |t j7 }q|S )N)r   r   r  )r   r  r"  r   r   r  )r   r$  r%  r   rT   rT   rU   r    s
   z;TestParfors.test_three_d_array_reduction.<locals>.test_implr]  r  r  rT   rT   rU   test_three_d_array_reduction     	z(TestParfors.test_three_d_array_reductionc                 C   s&   dd }d}t |}| || d S )Nc                 S   s   |   d S r  )argsortr\  rT   rT   rU   r    r\   z>TestParfors.test_preparfor_canonicalize_kws.<locals>.test_implr  r   r  r   r  rT   rT   rU   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 rX   r  r\  rT   rT   rU   r    s   z8TestParfors.test_preparfor_datetime64.<locals>.test_implr   zdatetime64[ns])r   r  r  r   r   r   r   r   )rQ   r  rU  r   rT   rT   rU   test_preparfor_datetime64  s   z%TestParfors.test_preparfor_datetime64c                 C   s    dd }|  |tjd d S )Nc                 S   sP   | j d }d}t|D ]}h d}|| d}|D ]}||7 }q||7 }q|S )Nr   >   r   r   r   )rc  r   r  )rM  r   r  r   Rr&  r   rT   rT   rU   r    s   



zITestParfors.test_no_hoisting_with_member_function_call.<locals>.test_implrN  )r   r   r!  r"  r  rT   rT   rU   *test_no_hoisting_with_member_function_call  s   z6TestParfors.test_no_hoisting_with_member_function_callc                 C      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"  rM  rT   rT   rU   r    s   z8TestParfors.test_array_compare_scalar.<locals>.test_implNr  r  rT   rT   rU   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 r  )r   rR  )r   halfr_  parrrT   rT   rU   r    s
   z?TestParfors.test_array_analysis_optional_def.<locals>.test_implr  TFr  r  rQ   r  r   rT   rT   rU    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 ]}|| ||  ||< q!|S )Nr  )r   r  r   r)  r   r   )rw   rx   datar_  r   rT   rT   rU   r    s   z7TestParfors.test_prange_side_effects.<locals>.test_implr]  r  r   r.  )	r   r  floatr   r   r   r   r0  r)  )rQ   r  r   r  rT   rT   rU   test_prange_side_effects  s   	z$TestParfors.test_prange_side_effectsc                 C   r  )Nc                 S   s@   d}d}t t| D ]}| |  |d |d  | 7  < q| S )Nr  r  r   r   )r   r   r   rw   atuprx   r   rT   rT   rU   r  
  s
   "z*TestParfors.test_tuple1.<locals>.test_implr   r4  r>  rT   rT   rU   test_tuple1	     
zTestParfors.test_tuple1c                 C   r  )Nc                 S   s:   | j }d}tt| D ]}| |  |d | 7  < q| S )Nr  r   )rc  r   r   r   rC  rT   rT   rU   r    s
   z*TestParfors.test_tuple2.<locals>.test_implr   r4  r>  rT   rT   rU   test_tuple2  rF  zTestParfors.test_tuple2c                 C   r  )Nc                 S   sN   t ddf}d}tt| D ]}| |  |d d |d  | 7  < q| S )Nr   r   r  r   rq   r   )r   r  r   r   r   rC  rT   rT   rU   r     s
   &z*TestParfors.test_tuple3.<locals>.test_implr   r4  r>  rT   rT   rU   test_tuple3  rF  zTestParfors.test_tuple3c                 C   r  )Nc                 S   sD   t ddd}d}tt| D ]}| |  |j|j | 7  < q| S Nr   r   rs   r  )rr   r   r   r   rt   ru   rw   antuprx   r   rT   rT   rU   r  +  
   z/TestParfors.test_namedtuple1.<locals>.test_implr   r4  r>  rT   rT   rU   test_namedtuple1*  rF  zTestParfors.test_namedtuple1c                    s0   t dd  fdd}td}| || d S )NTestNamedTuple2rs   c                    sD    ddd}d}t t| D ]}| |  |j|j | 7  < q| S rI  )r   r   r   rt   ru   rJ  rN  rT   rU   r  7  rL  z/TestParfors.test_namedtuple2.<locals>.test_implr   )r   r   r  r   r>  rT   rO  rU   test_namedtuple25  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 )Nrq   r  r  rT   rT   rU   r  F  r   z/TestParfors.test_namedtuple3.<locals>.test_implc                 S   s   t j| j|j d S rX   )r   r   r   r  rv   rT   rT   rU   r  I  r  z.TestParfors.test_namedtuple3.<locals>.comparerr   rR  r  )r   r   r  r   )rQ   rQ  r  r  r   rT   rT   rU   test_namedtuple3A  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 rX   rT   rv   rT   rT   rU   r  P     z1TestParfors.test_inplace_binop.<locals>.test_implr   r]  r   r.  )r   r  r   r   r   r   r0  r)  rQ   r  rM  rL  rT   rT   rU   test_inplace_binopO  s   zTestParfors.test_inplace_binopc                 C   &   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  uint64r  rw   r   array_shapeindicesk_listr   r  rT   rT   rU   r  ]  s   z0TestParfors.test_tuple_concat.<locals>.test_implr   r  r>  rT   rT   rU   test_tuple_concat[  s   
zTestParfors.test_tuple_concatc                 C   rW  )Nc                 S   sb   t | }||f}tjd| d d d tjd}|dd d f }t| D ]
\}}||||f< q$|S )Nr  rG   r  r   rX  rZ  rT   rT   rU   r  l  s   zCTestParfors.test_tuple_concat_with_reverse_slice.<locals>.test_implr   r  r>  rT   rT   rU   $test_tuple_concat_with_reverse_slicej  s   z0TestParfors.test_tuple_concat_with_reverse_slicec                 C   r  )Nc                 S   s   | f| | f }|d   S r  rR  )rw   SrT   rT   rU   r  |  s   z6TestParfors.test_array_tuple_concat.<locals>.test_implr   r   r  r>  rT   rT   rU   test_array_tuple_concatz  s   
z#TestParfors.test_array_tuple_concatc                 C   r  )Nc                 S   s   | d S )Nr  rT   r  rT   rT   rU   r    r  z3TestParfors.test_high_dimension1.<locals>.test_impl)r   r   r   r   r      r  r>  rT   rT   rU   test_high_dimension1  s   
z TestParfors.test_high_dimension1c                 C   $   dd }d}|  |t|| d S )Nc                 S      t |D ]}d| |< q| S r  r   pndindexr   szr   rT   rT   rU   r       
z-TestParfors.test_tuple_arg.<locals>.test_implr   rq   )r   r   r  rQ   r  rk  rT   rT   rU   test_tuple_arg     zTestParfors.test_tuple_argc                 C   $   dd }d}|  |t|d d S )Nc                 S   rg  r  rh  rj  rT   rT   rU   r    rl  z=TestParfors.test_tuple_arg_not_whole_array.<locals>.test_implrm  r   r   r   r   r  rn  rT   rT   rU   test_tuple_arg_not_whole_array  rp  z*TestParfors.test_tuple_arg_not_whole_arrayc                 C   "   dd }d}|  |t| d S )Nc                 S       d}t |D ]}d| |< q| S )Nrm  r   rh  rj  rT   rT   rU   r       
z6TestParfors.test_tuple_for_pndindex.<locals>.test_implrm  rs  rn  rT   rT   rU   test_tuple_for_pndindex     z#TestParfors.test_tuple_for_pndindexc                 C   rq  )Nc                 S   s$   |df}t |D ]}d| |< q	| S r(  rh  )r   firstrk  r   rT   rT   rU   r    s   
z5TestParfors.test_tuple_arg_literal.<locals>.test_implrm  r   rs  rn  rT   rT   rU   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 ]}|| q#d S )Nc                 S   rg  r  rh  rj  rT   rT   rU   r    rl  z?TestParfors.test_tuple_of_literal_nonliteral.<locals>.test_implc                 S   s
   || dS )Nrr  rT   )r   r  rT   rT   rU   rG    r  z:TestParfors.test_tuple_of_literal_nonliteral.<locals>.callc                   S   r  )Nr  r   r  rT   rT   rT   rU   rb    rc  z>TestParfors.test_tuple_of_literal_nonliteral.<locals>.<lambda>c                    s,   | }t  }| |}| d S rX   )r   assertPreciseEqual)decf1f2gotrG  expected	get_inputrQ   r  rT   rU   r     s   z;TestParfors.test_tuple_of_literal_nonliteral.<locals>.checkTr  r   )rQ   r   r   rT   r  rU    test_tuple_of_literal_nonliteral  s   
z,TestParfors.test_tuple_of_literal_nonliteralc                 C   rf  )Nc                 S   rg  r  rh  rj  rT   rT   rU   r    rl  z0TestParfors.test_tuple_arg_1d.<locals>.test_implr   rs  rn  rT   rT   rU   test_tuple_arg_1d  rp  zTestParfors.test_tuple_arg_1dc                 C   ru  )Nc                 S   rv  Nr  r   rh  rj  rT   rT   rU   r    rw  z8TestParfors.test_tuple_arg_1d_literal.<locals>.test_implr  rs  rn  rT   rT   rU   test_tuple_arg_1d_literal  ry  z%TestParfors.test_tuple_arg_1d_literalc                 C       dd }|  |tdd d S )Nc                 S   rg  r  rh  rj  rT   rT   rU   r    rl  z4TestParfors.test_int_arg_pndindex.<locals>.test_implr  r   rs  r  rT   rT   rU   test_int_arg_pndindex  r  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   rX  )ur   evenr_  rT  rT   rT   rU   issue7854_proc  s   $z=TestParfors.test_prange_unknown_call1.<locals>.issue7854_procc                    sL   t d|d D ]	} | |d| qt d|d D ]	} | |d| q| S r  r   r   )r  r_  r   r  rT   rU   r    s
   z8TestParfors.test_prange_unknown_call1.<locals>.test_implr   r   r   )
rC   r   r  r   r)  r   r%  r   r   r   rQ   r  r_  r  cptypesrT   r  rU   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 ]!}t|d d d |d dD ]}| |d |f d | ||f< qqt d|d D ]}t|d d |d dD ]}| |d |f d | ||f< q@q2| S r  r  )r  r_  r   rT  rT   rT   rU   r    s    z6TestParfors.test_prange_index_calc1.<locals>.test_implr   r   r   	r   r  r   r)  r   r%  r   r   r   r  rT   rT   rU   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< q&q | d |d  S )Nr   r   r  r  )rw   rx   r_  r   rT  rT   rT   rU   r    s   z9TestParfors.test_prange_reverse_order1.<locals>.test_implr   r   r   r  rQ   r  r_  rw   rx   r  rT   rT   rU   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   rq   r  )rw   r_  rx   r   rT   rT   rU   r    s   
z@TestParfors.test_prange_parfor_index_then_not.<locals>.test_implr   r   r  )rQ   r  r_  rw   r  rT   rT   rU   !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 r  r  )rw   tupr_  r  r   rT   rT   rU   r  *  s   zJTestParfors.test_prange_parfor_index_const_tuple_fusion.<locals>.test_implr   r   )r   r  r   r   r)  r   
containersUniTupler&  r   r   r   r  rT   rT   rU   +test_prange_parfor_index_const_tuple_fusion'  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 )Nrq   r   r  )rw   rx   r_  r   rT   rT   rU   r  >  s   
zITestParfors.test_prange_non_parfor_index_then_opposite.<locals>.test_implr   r   r  r  rT   rT   rU   *test_prange_non_parfor_index_then_opposite;  s   	

 z6TestParfors.test_prange_non_parfor_index_then_oppositec                 C   r  )Nc                  S   s   d} | d S )Ng333333?g?r   rT   r  rT   rT   rU   r  P  s   z8TestParfors.test_untraced_value_tuple.<locals>.test_implr  r  r  rT   rT   rU   test_untraced_value_tupleN  
   z%TestParfors.test_untraced_value_tuplec                 C   r  )Nc                  S   s   d} | d d S )N)r  r   rT   r  rT   rT   rU   r  Z  s   zBTestParfors.test_recursive_untraced_value_tuple.<locals>.test_implr  r  r  rT   rT   rU   #test_recursive_untraced_value_tupleX  r  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  ||< q-d}t |}	t|	D ]}
|||
 7 }qD||d  S )Nr  r   r   rq  r   r   r  r)  r   )arrrw   n1arr2r   n2arr3rT  totaln3r   rT   rT   rU   r  d  s   z9TestParfors.test_untraced_value_parfor.<locals>.test_implr   r.  r   r  )r   r0  r%  r   r   r   r  r   )rQ   r  rR  r  rT   rT   rU   test_untraced_value_parforb  s
   z&TestParfors.test_untraced_value_parforc                 C      dd }|  |td d S )Nc                 S   s<   d}t | jd D ]}|r| d| |d d f< |d7 }q	| S r  )r   rc  )r   r+  r   rT   rT   rU   r  |  s   
z;TestParfors.test_setitem_2d_one_replaced.<locals>.test_impl)r   r   rs  r  rT   rT   rU   test_setitem_2d_one_replacedz  s   
z(TestParfors.test_setitem_2d_one_replacedN)Gri   rL   rj   r3  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.  r0  r1  r5  r6  r8  r;  r?  rB  rE  rG  rH  rM  rP  rS  rV  r^  r_  rc  re  ro  rt  rx  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rT   rT   rT   rU   r  
  s    )
&





						

r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestParforsLeaksc                 O   6   | j |g|R  \}}| j|||g|R i | d S rX   r   r   rT   rT   rU   r         zTestParforsLeaks.checkc                 C   4   t dddd }tdtj}| || d S )NTr  c                 S   rY  rX   r`  )r  rT   rT   rU   r       z2TestParforsLeaks.test_reduction.<locals>.test_implr   r   r   r  r  r)  r   rQ   r  r  rT   rT   rU   test_reduction  s   
zTestParforsLeaks.test_reductionc                 C   r  )NTr  c                 S   s@   d}d}t | jD ]}|| | 7 }|d| | d  7 }q	|| S )Nrq  r6  r   )r   r_  )r  rw   rx   r   rT   rT   rU   r    s   z@TestParforsLeaks.test_multiple_reduction_vars.<locals>.test_implr   r  r  rT   rT   rU   test_multiple_reduction_vars  s   
z-TestParforsLeaks.test_multiple_reduction_varsN)ri   rL   rj   r   r  r  rT   rT   rT   rU   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   r  )Nc                 S   s,   | j \}| d|d  | d|d   }|S Nr   r   r   rc  rw   r   rx   rT   rT   rU   r        z6TestParforsSlice.test_parfor_slice1.<locals>.test_implr   r   r   r  r  rT   rT   rU   test_parfor_slice1     z#TestParforsSlice.test_parfor_slice1c                 C   sv   dd }|  |tdd | t}tdd|tdd W d    n1 s+w   Y  | dt|j d S )Nc                 S   s(   | j \}| d|d  | d|  }|S r  r  rw   r  r   rx   rT   rT   rU   r    s   z6TestParforsSlice.test_parfor_slice2.<locals>.test_implr   r  Tr  do not match	r   r   r  r  r  r   r   r  r  r  rT   rT   rU   test_parfor_slice2  s   z#TestParforsSlice.test_parfor_slice2c                 C   r  )Nc                 S   s>   | j \}}| d|d d|d f | d|d|f  }|S r  r  r  rT   rT   rU   r    s   
0z6TestParforsSlice.test_parfor_slice3.<locals>.test_implr   r   r  r  rT   rT   rU   test_parfor_slice3  r  z#TestParforsSlice.test_parfor_slice3c                 C   r  )Nc                 S   s:   | j \}}| d d d|d f | d d d|f  }|S r  r  r  rT   rT   rU   r       
,z6TestParforsSlice.test_parfor_slice4.<locals>.test_implr  r  r  rT   rT   rU   test_parfor_slice4  r  z#TestParforsSlice.test_parfor_slice4c                 C   r  )Nc                 S   s:   | j \}}| d|d d d f | d|d d f  }|S r  r  r  rT   rT   rU   r    r  z6TestParforsSlice.test_parfor_slice5.<locals>.test_implr  r  r  rT   rT   rU   test_parfor_slice5  r  z#TestParforsSlice.test_parfor_slice5c                 C   r  )Nc                 S   s,   |   }| dd d f |d d df  }|S r  	transposerw   rx   crT   rT   rU   r    r  z6TestParforsSlice.test_parfor_slice6.<locals>.test_implr  r  r  rT   rT   rU   test_parfor_slice6  r  z#TestParforsSlice.test_parfor_slice6c                 C   sr   dd }|  |td | t}tdd|td W d    n1 s)w   Y  | dt|j d S )Nc                 S   s,   |   }| dd d f |dd d f  }|S r  r  r  rT   rT   rU   r    r  z6TestParforsSlice.test_parfor_slice7.<locals>.test_implrb  Tr  r  r  r  r  rT   rT   rU   test_parfor_slice7  s   z#TestParforsSlice.test_parfor_slice7c                 C   $   dd }|  |tdd d S )Nc                 S   s:   | j \}}|  }| d|d|f |d|d|f< |S r  rc  r  r  rT   rT   rU   r       
$z6TestParforsSlice.test_parfor_slice8.<locals>.test_implr  rb  r   r   r  r   r  rT   rT   rU   test_parfor_slice8     z#TestParforsSlice.test_parfor_slice8c                 C   r  )Nc                 S   s:   | j \}}|  }| d d d|f |d|d|f< |S r  r  r  rT   rT   rU   r    r  z6TestParforsSlice.test_parfor_slice9.<locals>.test_implr  r  r  r  rT   rT   rU   test_parfor_slice9  r  z#TestParforsSlice.test_parfor_slice9c                 C   r  )Nc                 S   s2   | j \}}|  }| dd|f |dd|f< |S r+  r  r  rT   rT   rU   r       
z7TestParforsSlice.test_parfor_slice10.<locals>.test_implr  rb  r  r  rT   rT   rU   test_parfor_slice10  r  z$TestParforsSlice.test_parfor_slice10c                 C   r  )Nc                 S   s@   | j \}}}|  }| d d dd|f |d d dd|f< |S r+  rc  r   )rw   r  r   rh  rx   rT   rT   rU   r  	  s   (z7TestParforsSlice.test_parfor_slice11.<locals>.test_impl   )r   r   r   r  r  rT   rT   rU   test_parfor_slice11	     z$TestParforsSlice.test_parfor_slice11c                 C   r  )Nc                 S   s2   | j \}}|  }| dd df |dddf< |S )Nr   r   rG   r  r  rT   rT   rU   r  	  r  z7TestParforsSlice.test_parfor_slice12.<locals>.test_implr  r  r  r  rT   rT   rU   test_parfor_slice12	  r  z$TestParforsSlice.test_parfor_slice12c                 C   r  )Nc                 S   s<   | j \}}|  }d}| d| |d f |dd|f< |S )NrG   r   r   r  )rw   r  r   rx   r  rT   rT   rU   r  	  s
   
"z7TestParforsSlice.test_parfor_slice13.<locals>.test_implr  r  r  r  rT   rT   rU   test_parfor_slice13	  s   z$TestParforsSlice.test_parfor_slice13c                 C   r  )Nc                 S   s2   | j \}}|  }| dddf |dd df< |S )Nr   r   r   rG   r  r  rT   rT   rU   r  $	  r  z7TestParforsSlice.test_parfor_slice14.<locals>.test_implr  r  r  r  rT   rT   rU   test_parfor_slice14#	  r  z$TestParforsSlice.test_parfor_slice14c                 C   r  )Nc                 S   s8   | j \}}|  }| dddf |d|d  d f< |S )Nr   r  r   r   r  r  rT   rT   rU   r  -	  s   
"z7TestParforsSlice.test_parfor_slice15.<locals>.test_implr  r  r  r  rT   rT   rU   test_parfor_slice15,	  r  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J d| d|< d|d|d < | | S Nr   r   r   r  )rw   rx   r   rT   rT   rU   r  ;	  s   z7TestParforsSlice.test_parfor_slice16.<locals>.test_implr      Nr   )	r   r   r  r  r   r)  r%  r   r   rQ   r  r   rT   rT   rU   test_parfor_slice165	  s    z$TestParforsSlice.test_parfor_slice16c                 C   s    dd }|  |dtd d S )Nc                 S   s$   t | }t|}||| d < |S rX   r   r  r   )r  rU  r9  r   rT   rT   rU   r  F	  s   
z7TestParforsSlice.test_parfor_slice17.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_slice17E	  s   z$TestParforsSlice.test_parfor_slice17c                 C   r  )Nc                  S   s*   t d} t dd| dd< | d }|S )Nr   r   r  r   r  r   )r   r  r  )rw   r  rT   rT   rU   r  P	  s   
z7TestParforsSlice.test_parfor_slice18.<locals>.test_implr  r  rT   rT   rU   test_parfor_slice18N	  s   z$TestParforsSlice.test_parfor_slice18c                 C   r  )Nc                 S   s   | d d  d7  < | S r  rT   r:  rT   rT   rU   r  Z	     z7TestParforsSlice.test_parfor_slice19.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_slice19X	     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   r  r   )rw   r  rH  rT   rT   rU   r  b	  s   
z7TestParforsSlice.test_parfor_slice20.<locals>.test_implFr  r  r  rT   rT   rU   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x2rT   rT   rU   r  k	  s   z7TestParforsSlice.test_parfor_slice21.<locals>.test_implrq   r   )r   r!  r  r   rQ   r  r  r  rT   rT   rU   test_parfor_slice21j	  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  rx   r   rT   rT   rU   r  u	  s   
z7TestParforsSlice.test_parfor_slice22.<locals>.test_impl)r   r  r   )r   r  rd  r   r  rT   rT   rU   test_parfor_slice22t	  s   

z$TestParforsSlice.test_parfor_slice22c                 C   r  )Nc                 S   s   d| d d< | S )Nr   r   rT   r  rT   rT   rU   r  	     z7TestParforsSlice.test_parfor_slice23.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_slice23	  r  z$TestParforsSlice.test_parfor_slice23c                 C   2   dd }t ddD ]}| |dtd| q	d S )Nc                 S   s*   t | }||d  }|d t| }|S rX   r  r  rU  r   r9  r.  rT   rT   rU   r  	     
z7TestParforsSlice.test_parfor_slice24.<locals>.test_implrd  r   r   r   r   r  rQ   r  r   rT   rT   rU   test_parfor_slice24	     z$TestParforsSlice.test_parfor_slice24c                 C   r  )Nc                 S   s*   t | }|d | }|d t| }|S rX   r  r  rT   rT   rU   r  	  r  z7TestParforsSlice.test_parfor_slice25.<locals>.test_implr  rd  r   r  r  rT   rT   rU   test_parfor_slice25	  r  z$TestParforsSlice.test_parfor_slice25c                 C   r  )Nc                 S   s.   | j \}|  }| dd ||d  d < |S )Nr  r   r   r  r  rT   rT   rU   r  	  s   z7TestParforsSlice.test_parfor_slice26.<locals>.test_implr   r   r   r  r  rT   rT   rU   test_parfor_slice26	  s   z$TestParforsSlice.test_parfor_slice26c                 C   r  )Nc                 S   s@   d}t | jd D ]}| | dkr|d7 }|r| d | }q	dS r  r  )rw   n_valid_valsr   unusedrT   rT   rU   r  	  s   z7TestParforsSlice.test_parfor_slice27.<locals>.test_implr   r  r  rT   rT   rU   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 ](  fdd}d}| || t|d	 |d	f} fd
d}| || qd S )Nr   r   r   rG   r  c                    sD   t | d | df}d}t| D ]}||| f  7 }q|S Nr   r   )r   r  r   r   r   rR  r  tsrT   rU   r  	  s
   zHTestParforsSlice.test_parfor_array_access_lower_slice.<locals>.test_implr   r   c                    s2   d}t | jd D ]}|| | f  7 }q
|S r  )r   r   rc  rR  )rM  r  r   r  rT   rU   r  	  s   )slicer   r   r  r   rQ   r  r   rM  rT   r  rU   $test_parfor_array_access_lower_slice	  s   z5TestParforsSlice.test_parfor_array_access_lower_sliceN) ri   rL   rj   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  rT   rT   rT   rU   r    sB    
	
	
			
		
	




	r  c                   @   r  )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 ]}|| | |  ||< q$tdd |dS )Nr   c                 S   r  rT   rT   r   rT   rT   rU   r   	  r  zMTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<listcomp>c                 S   s   | | S rX   rT   )r   r  rT   rT   rU   rb  	  r  zKTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<lambda>)rc  r   r  rd  r   r   r   )rw   r   rx   r  r   rT   rT   rU   r  	  s   

z9TestParforsOptions.test_parfor_options.<locals>.test_implr   r   F)fusionr   )r	  comprehensionrq   )r	  r
  setitemr   )r	  r
  r  r   r   )r	  r
  r  r   	reductionr   )r	  r
  r  r   r  r  r   )r   r   r  r   r)  r   r   r  rT   rT   rU   test_parfor_options	  s@   	z&TestParforsOptions.test_parfor_optionsN)ri   rL   rj   r  rT   rT   rT   rU   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S )TestParforsBitMaskc                 C   r  )Nc                 S   s   | |k}d| |< | S r  rT   r  rT   rT   rU   r  	  s   z:TestParforsBitMask.test_parfor_bitmask1.<locals>.test_implr   rq   r  r  rT   rT   rU   test_parfor_bitmask1	  s   z'TestParforsBitMask.test_parfor_bitmask1c                 C   ,   dd }t d}|dk}| ||| d S )Nc                 S   s   d| |< | S r  rT   rv   rT   rT   rU   r   
  rT  z:TestParforsBitMask.test_parfor_bitmask2.<locals>.test_implr   rq   r4  r  rT   rT   rU   test_parfor_bitmask2	     
z'TestParforsBitMask.test_parfor_bitmask2c                 C   r  )Nc                 S   s   | | | |< | S rX   rT   rv   rT   rT   rU   r  	
  r  z:TestParforsBitMask.test_parfor_bitmask3.<locals>.test_implr   rq   r4  r  rT   rT   rU   test_parfor_bitmask3
  r  z'TestParforsBitMask.test_parfor_bitmask3c                 C   r  )Nc                 S   s   d|  | | |< | S rQ  rT   rv   rT   rT   rU   r  
  rn  z:TestParforsBitMask.test_parfor_bitmask4.<locals>.test_implr   rq   r4  r  rT   rT   rU   test_parfor_bitmask4
  r  z'TestParforsBitMask.test_parfor_bitmask4c                 C   r  )Nc                 S   s   | | | |  | |< | S rX   rT   rv   rT   rT   rU   r  
  r  z:TestParforsBitMask.test_parfor_bitmask5.<locals>.test_implr   rq   r4  r  rT   rT   rU   test_parfor_bitmask5
  r  z'TestParforsBitMask.test_parfor_bitmask5c                 C   sx   dd }t d}|dk}t t|}| t}| |||| W d    n1 s,w   Y  | dt|j	 d S )Nc                 S   s   || |< | S rX   rT   r  rT   rT   rU   r  $
  rT  z:TestParforsBitMask.test_parfor_bitmask6.<locals>.test_implr   rq   r  )
r   r  r  rR  r  r  r   r   r  r  )rQ   r  rw   rx   r  r  rT   rT   rU   test_parfor_bitmask6#
  s   
z'TestParforsBitMask.test_parfor_bitmask6N)	ri   rL   rj   r  r  r  r  r  r  rT   rT   rT   rU   r  	  s    				r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Ze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 d    n1 s7w   Y  | t	|d dd |j
 D }| |dg d S )Nc                  S   s.   t d} t| jD ]
}| |  |7  < q
| S Nr]  )r   r  r   r_  )r  r   rT   rT   rU   r   9
  s   
z9TestParforsMisc.test_no_warn_if_cache_set.<locals>.pyfuncT)r  cacherecordalwaysignore	typeguard)actionmodulez.*TBB_INTERFACE_VERSION.*znumba\.np\.ufunc\.parallel.*)r  messagecategoryr   r   c                 S   s   g | ]}|j jqS rT   )r   has_dynamic_globals)r   r   rT   rT   rU   r   O
  s    z=TestParforsMisc.test_no_warn_if_cache_set.<locals>.<listcomp>F)r   warningscatch_warningssimplefilterfilterwarningsr   r   NumbaWarningr   r   	overloadsr  )rQ   r   r   raised_warningsr#  rT   rT   rU   test_no_warn_if_cache_set7
  s&   
z)TestParforsMisc.test_no_warn_if_cache_setc                 C   sd   dd }|  |d}t }|  W d    n1 sw   Y  |  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   r  za[3]:r   )r   r  r  printr  rT   rT   rU   r   T
  s
   
zITestParforsMisc.test_statement_reordering_respects_aliasing.<locals>.implrT   z	a[3]: 2.0)r   r7   r   getvaluer  r   )rQ   r   r   stdoutlinerT   rT   rU   +test_statement_reordering_respects_aliasingS
  s   
z;TestParforsMisc.test_statement_reordering_respects_aliasingc                 C   sn   dd }t t jdg}tdd|}tjjj}zdtjj_t j	|||| W |tjj_d S |tjj_w )Nc                 S   rE  rX   )r   isinfr\  rT   rT   rU   r  b
  r  z;TestParforsMisc.test_parfor_ufunc_typing.<locals>.test_implrq  Tr  )
r   rd  r  r   r   r  r  sequential_parfor_loweringr   assert_array_equal)rQ   r  rU  r   old_seq_flagrT   rT   rU   test_parfor_ufunc_typinga
  s   

z(TestParforsMisc.test_parfor_ufunc_typingc                 C   s   dd }|  t|dd d S )Nc                  S   sD   d} g d}t jj  |}t dD ]}| || 7 } q| |d  S )Nr   r  rq   r   )r   r  r  init_pranger   )resr  dummyr   rT   rT   rU   r  r
  s   z6TestParforsMisc.test_init_block_dce.<locals>.test_implrT   r   )r   r  r  rT   rT   rU   test_init_block_dcep
  s   	z#TestParforsMisc.test_init_block_dcec                 C   r  )Nc                  S   s*   d} t dD ]}| d7 } qt| f}|S )Nr   r   r   r   r   r  )r  rH   r@  rT   rT   rU   r  ~
  s
   
zBTestParforsMisc.test_alias_analysis_for_parfor1.<locals>.test_implr  r  rT   rT   rU   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 d    n1 sBw   Y  |  t|j | tjjj d S )N
BROKEN_MSGTF)mutates_CFG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>.BreakParforsbreak_parforsc                 S   s   t |  d S rX   )r4   r   rZ   rT   rT   rU   r   
  r   z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.__init__c                    sR   |j j D ] }|jD ]}t|tjjjr#G  fdddt	}| |_
q dS d S )Nc                          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  rX   )r   LoweringError)rQ   otherr<  rT   rU   
difference
  r  zzTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Broken.differenceN)ri   rL   rj   rD  rT   rC  rT   rU   Broken
      rE  T)rk  r  r  r  r   r   r  r  r  r   races)rQ   r{  blkr  rE  rC  rT   rU   run_pass
  s   
z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_passN)ri   rL   rj   _namer   rI  rT   rC  rT   rU   BreakParfors
  s    rK  c                       r@  )z^TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompilerc                    s&   t | j}| t |  |gS rX   )r2   define_nopython_pipeliner{  add_pass_afterr5   finalize)rQ   pmrK  rT   rU   define_pipelines
  s   zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompiler.define_pipelinesN)ri   rL   rj   rQ  rT   rP  rT   rU   BreakParforsCompiler
  rF  rR  )r  pipeline_classc                  S   s   d} t dD ]}| d7 } q| S r  r  )r   rH   rT   rT   rU   foo
  s   
zMTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.foo)r3   r4   r1   r   assertFalser   r  r  r2  r  r   rA  r   r  r  )rQ   rR  rT  r  rT   )r<  rK  rU   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 |tjj_d S |tjj_w )Nc                   @      e Zd ZdS )z2TestParforsMisc.test_issue_5098.<locals>.DummyTypeNri   rL   rj   rT   rT   rT   rU   	DummyType
      rY  my_dummyc                   @   rW  )z.TestParforsMisc.test_issue_5098.<locals>.DummyNrX  rT   rT   rT   rU   Dummy
  rZ  r\  c                    s    S rX   rT   )valr  )
dummy_typerT   rU   typeof_Dummy
     z5TestParforsMisc.test_issue_5098.<locals>.typeof_Dummyc                 S   s   t |j S rX   )r"   contextget_dummy_value)typobjr  rT   rT   rU   unbox_index
  s   z4TestParforsMisc.test_issue_5098.<locals>.unbox_indexmethod1r  T)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  < q&|S )Nc                 S   s    |   }tj|t| < ||S rX   )r   r   r  r1  )rw   fr  rT   rT   rU   baz
  s   zPTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foo.<locals>.bazr  r   r  )rd  r  r   ri  length
output_arrr   rT   rT   rU   _foo
  s   zCTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foorT   )rd  r  r   rl  rT   rT   rU   _get_method1
  s   z5TestParforsMisc.test_issue_5098.<locals>._get_method1c                 S   rY  rX   rZ  )r  rT   rT   rU   bar
  r  z,TestParforsMisc.test_issue_5098.<locals>.barc                    s   |  tg dg dg S )Nr6  r  r  )r  r  r  )rf  r   rd  )r   )rn  rT   rU   test1
  s   z.TestParforsMisc.test_issue_5098.<locals>.test1)r   Opaquer   r#   OpaqueModelobjectr    registerr!   r   r   r   r  r  r2  rU  )rQ   rY  r\  r_  re  rm  rp  
save_staterT   )rn  r^  rU   test_issue_5098
  s(   





zTestParforsMisc.test_issue_5098c              	   C   s   t dddd }tdd" | tj}|d W d    n1 s$w   Y  W d    n1 s3w   Y  t|j}| d| | d	| d S )
NTr  c                 S   s&   d}d}t dD ]}|||  7 }q|S )N)r   r   r   r   r   r   r  )idxbig_tupr  r   rT   rT   rU   oversize_tuple
  s
   zMTestParforsMisc.test_oversized_tuple_as_arg_to_kernel.<locals>.oversize_tupleNUMBA_PARFOR_MAX_TUPLE_SIZE3r   zUse of a tuplezin a parallel region)r   r9   r  r   r  r  r  r   )rQ   ry  r  errstrrT   rT   rU   %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 ]'}t|d D ]}| ||f |||f  | ||f |||f   |||f< qq|S Nr   r  r   )r   fullrc  r  r   )img_nirimg_red	fillvalueout_imgdimsr  r   rT   rT   rU   	ndvi_njit  s   z1TestParforsMisc.test_issue5167.<locals>.ndvi_njit)r   r   r6  g     @)lowrr  r_  )r   r!  uniformr   )rQ   r  
tile_shapearray1array2rT   rT   rU   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 ](}t|d | jd D ]}|| | | | g|R  }||||f< ||||f< q#q|S r~  )r   r  rc  r,  r   r   )rw   r_  	dist_argsr(  r   rT  r   rT   rT   rU   
reproducer  s    z2TestParforsMisc.test_issue5065.<locals>.reproducerc                 S   s:   d}t | jd D ]}|| | ||  d 7 }q	t|S )Nrq  r   r   )r   rc  r   r   )r   r  r(  r   rT   rT   rU   	euclidean'  s   
z1TestParforsMisc.test_issue5065.<locals>.euclidean)rq   r   r^  Tr  rT   )r   r   r!  r   r   r{  )rQ   r  r  rw   r  r  rT   rT   rU   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 r  )r   r   )myarrayr(  r   rT   rT   rU   test_numba_parallel7  s   z;TestParforsMisc.test_issue5001.<locals>.test_numba_parallelr]  2   )r   r  r   )rQ   r  r  rT   rT   rU   test_issue50015  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 rX   rT   )gridsrT   rT   rU   rT  B  r`  z+TestParforsMisc.test_issue3169.<locals>.fooTr  c                    s   t dD ]} |  qd S r  r  )r  r   rT  rT   rU   rn  F  s   
z+TestParforsMisc.test_issue3169.<locals>.barr   r   r  )rQ   rn  rT   r  rU   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mytyperv   c                    s   t dD ]} ||  q| jS r  )r   rw   )mydatar   innerrT   rU   outerS  s   z-TestParforsMisc.test_issue4846.<locals>.outerT)nogilc                 S   s   | |j f}| |jf}d S rX   rv   )r   r  rh  r  rT   rT   rU   r  X  s   
z-TestParforsMisc.test_issue4846.<locals>.innerrw   rx   )r   r   r   )rQ   r  r  r  rT   r  rU   test_issue4846N  s   

zTestParforsMisc.test_issue4846c                 C   r  )Nc                  S   s*   d} d}t t| D ]}|| | 7 }q
|S )Nr  r   )r   r   )r   rw   r   rT   rT   rU   test1bc  s
   z.TestParforsMisc.test_issue3748.<locals>.test1br  )rQ   r  rT   rT   rU   test_issue3748a  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      @r  )r_  r  r   r  rT   rT   rU   parallel_testn  s
   z5TestParforsMisc.test_issue5277.<locals>.parallel_testr  r  )r   r  intr   )rQ   r  r_  r  rT   rT   rU   test_issue5277l  s   zTestParforsMisc.test_issue5277c                 C   sL   t dddd }td}d}td}| |||||||| d S )NTr  c                 S   s8   t dD ]}tdD ]}d|||f< q
q|r|d7 }|S r  )r   r   )r   methodr
  r   rT  rT   rT   rU   rT  z  s   z5TestParforsMisc.test_issue5570_ssa_races.<locals>.foo)rq   rq   9   r  )r   r   r  r}  py_func)rQ   rT  r   r  r
  rT   rT   rU   test_issue5570_ssa_racesy  s   



z(TestParforsMisc.test_issue5570_ssa_racesc                 C   sD   t dddd }tjd tjd}| |||| d S )NTr  c                 S   s4   | }t ddD ]}||d d d d f }qt|S )Nr   r   )r   r   r>  )r   packager  z_stackrT   rT   rU   find_maxima_3D_jit  s   
zDTestParforsMisc.test_issue6095_numpy_max.<locals>.find_maxima_3D_jitr   )r   r   r   )r   r   r!  r/  r}  r  )rQ   r  r   rT   rT   rU   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 ]}| |d d f ||d d f< ||df  d7  < q|S r  )rc  r   )gggg_nextgsr   i_ggrT   rT   rU   r    s   z3TestParforsMisc.test_issue5942_1.<locals>.test_implr   r   r  )r   r  r  r   )rQ   r  r   r   r  r  rT   rT   rU   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 ]'}t|D ]}||||f< q||d d f ||d d f< ||df  d7  < q|S )Nr  r   r   )r   r  r  r   r   )r   r   r  r  r  r   rT   rT   rU   r    s   z3TestParforsMisc.test_issue5942_2.<locals>.test_implr   r   r  )rQ   r  r   r   rT   rT   rU   test_issue5942_2  s   z TestParforsMisc.test_issue5942_2c                 C   sB   t dddd }tg dg dg}| |||| d S )NTr  c                 S   s   t | jd D ]?}tj}tjg dtjd}dD ]!}tj| |d d f | }||k r9|}tj|||gtjd}q| |d d f  |7  < q| S )Nr   )r   r   r   r  )r   r   rG   )r   rc  r   r  rd  r,  r  norm)rr   r_  trr   dist_trT   rT   rU   rh    s   z)TestParforsMisc.test_issue6102.<locals>.f)rq  rq  rq  )rq  rq  r6  )r   r   rd  r}  r  )rQ   rh  r  rT   rT   rU   test_issue6102  s   
zTestParforsMisc.test_issue6102c                 C   s    t dddd }| | d S )NTr  c                  S   sP   d} t | f}t | d f}tt|D ]}t |||d  ||< q|S r(  )r   r  r  r   r   rR  )r   na_maskr(  r   rT   rT   rU   r    s   z1TestParforsMisc.test_issue6774.<locals>.test_impl)r   r   r  rT   rT   rU   test_issue6774  s   
zTestParforsMisc.test_issue6774c                 C   r  )Nc                  S   s   t ttf} | S rX   )r   r  _GLOBAL_INT_FOR_TESTING1_GLOBAL_INT_FOR_TESTING2bufrT   rT   rU   r       z9TestParforsMisc.test_issue4963_globals.<locals>.test_implr  r  rT   rT   rU   test_issue4963_globals  s   z&TestParforsMisc.test_issue4963_globalsc                    s$   d d fdd}|  | d S )Nrp   rq   c                     s   t  f} | S rX   r|  r  _FREEVAR_INT_FOR_TESTING1_FREEVAR_INT_FOR_TESTING2rT   rU   r    r  z:TestParforsMisc.test_issue4963_freevars.<locals>.test_implr  r  rT   r  rU   test_issue4963_freevars  s   z'TestParforsMisc.test_issue4963_freevarsN)ri   rL   rj   r3  r+  r0  r5  r9  r;  rV  rv  r}  r  r  r  r  r@   r  r  r  r  r  r  r  rA   r  r  r  r  rT   rT   rT   rU   r  2
  s6    <5

r  c                   @   st   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   r  rX   r   r   rT   rT   rU   r     r  zTestParforsDiagnostics.checkc                 C   s$   |  |}|  |}| || d S rX   )_fusion_equivalentr   )rQ   r  r  rw   rx   rT   rT   rU   assert_fusion_equivalence  s   

z0TestParforsDiagnostics.assert_fusion_equivalencec                    sH   t t}t|  t| D ]} fdd|| D ||  < q|S )Nc                    s   g | ]}|  qS rT   rT   r   min_keyrT   rU   r     r   z=TestParforsDiagnostics._fusion_equivalent.<locals>.<listcomp>)r   r   r=  keyssorted)rQ   thingnewr   rT   r  rU   r    s
    z)TestParforsDiagnostics._fusion_equivalentNc                 C   s   |d ur|  ||  |d ur| ||j |d ur"| ||j |d urG|j }|D ]}|D ]
}	|	d |kr; nq1d||f }
t|
q-|d urW| }|  |t	| t
  tddD ]}|| q`W d    d S 1 ssw   Y  d S )Nr   z(Replacement for %s was not found. Had %sr   rq   )r   count_parforsr  fusion_infonested_fusion_infor  r  r  hoisted_allocationsr   r7   r   dump)rQ   rs  parfors_countr  r  r  r  replr   replacedr   hoisted_allocsrT   rT   rU   assert_diagnostics
  s4   
"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   r  r   rw   rx   rT   rT   rU   r  (  s   

z9TestParforsDiagnostics.test_array_expr.<locals>.test_implrT   parfor_diagnosticsr   r   r   rq   )r  r  r   r   r  r  rQ   r  r   rs  rT   rT   rU   test_array_expr'  s   



z&TestParforsDiagnostics.test_array_exprc                 C   :   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   rw   r   rT   rT   rU   r  5  
   
z5TestParforsDiagnostics.test_prange.<locals>.test_implrT   r  r   r  r  r  rT   rT   rU   test_prange4  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 }q#q|S )Nr   r   r   r   )r   r  sincosr   )r   r   rw   rx   r  r   rT  rT   rT   rU   r  D  s   

z;TestParforsDiagnostics.test_user_varname.<locals>.test_implrT   r  c                 s   s    | ]}d |j v V  qdS )zslice(0, n, 1)N)r!  )r   r  rT   rT   rU   r  U  s    z;TestParforsDiagnostics.test_user_varname.<locals>.<genexpr>N)r   r   r  r'  anyfusion_reportsr  rT   rT   rU   test_user_varnameA  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   rw   r   rT  rT   rT   rU   r  X  s   z<TestParforsDiagnostics.test_nested_prange.<locals>.test_implrT   r  r   r   )r  r  r  r  rT   rT   rU   test_nested_prangeW  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   r  r^  r  rT   rT   rU   r  g  s   

zCTestParforsDiagnostics.test_function_replacement.<locals>.test_implrT   r  r   r   r   )r^  r  )r  r  r  r  r  rT   rT   rU   test_function_replacementf  s   


z0TestParforsDiagnostics.test_function_replacementc                 C   r  )Nc                  S   s4   d} t | d }d}t| D ]}||| 7 }q|S r  )r   r  r   )r   rw   r  r   rT   rT   rU   r  u  s   z8TestParforsDiagnostics.test_reduction.<locals>.test_implrT   r  r   r  r  r  rT   rT   rU   r  t  s
   

z%TestParforsDiagnostics.test_reductionc                 C   r  )Nc                  S   s   d} t | }d|d d < |S )Nr   r  r  )r   rw   rT   rT   rU   r    s   
z6TestParforsDiagnostics.test_setitem.<locals>.test_implrT   r  r   r  r  r  rT   rT   rU   test_setitem  s
   

z#TestParforsDiagnostics.test_setitemc                 C   r  )Nc                  S   sL   d} d}d}t | D ]}t|f}t|D ]}|||< q||d 7 }q
|S )Nr   rq   r   rG   )r   r   r  r   )r   r  r  r   temprT  rT   rT   rU   r    s   
zBTestParforsDiagnostics.test_allocation_hoisting.<locals>.test_implrT   r  r   )r  r  r  rT   rT   rU   test_allocation_hoisting  s
   

z/TestParforsDiagnostics.test_allocation_hoisting)NNNNN)ri   rL   rj   r   r  r  r  r  r  r  r  r  r  r  r  rT   rT   rT   rU   r    s     
r  c                   @   s   e Zd Zdd Zdd ZdS )TestPrangeBasec                 C   sh  |j }t|j}|du r#d|jv sJ tdd |jD }t|j}nQ|jd}g }t|D ]}|j	dkrD|j
|krD||jd  q0|d t|}t|d }	t|j}t|t|kscJ |D ]
}
||
 }|	||< qet|}|jg}tjdkr||j ||j ||j|j|j||j||j|j|j|j|j|j|jg t j!| }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   rT   r   rT   rT   rU   r     s    z7TestPrangeBase.generate_prange_func.<locals>.<listcomp>LOAD_GLOBALr   r   )r   r  )$__code__r   co_namesr   bytesco_coder  disBytecodeopnamerR  r   offsetr   	bytearrayco_argcountr   	PYVERSIONco_posonlyargcountco_kwonlyargcountextend
co_nlocalsco_stacksizeco_flags	co_constsco_varnamesco_filenameco_nameco_firstlineno	co_lnotabco_freevarsco_cellvarspytypesCodeTypeFunctionTypeglobals)rQ   r   patch_instancepyfunc_codeprange_namesnew_code	range_idxrange_locationsinstr
prange_idxr   rw  co_argsprange_codepfuncrT   rT   rU   generate_prange_func  sZ   







z#TestPrangeBase.generate_prange_funcc                 O   s   | dd}| dd}| dd}| ||}tdd |D }| ||}	tjdd	}
td
 | ||}W d   n1 sCw   Y  |rP| || |rb| 	||}t
d|ifi |}| j||	|g|R i | |
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   r   rT   r   r   rT   rT   rU   r   .  r   z0TestPrangeBase.prange_tester.<locals>.<listcomp>Tr  r  r   )r   r  r   r   r$  r%  r&  r   r2  r   r  r   )rQ   r   r   r   r	  r   r  r  r   r   r*  r   
fastcpfuncrT   rT   rU   prange_tester  s"   A
zTestPrangeBase.prange_testerN)ri   rL   rj   r  r  rT   rT   rT   rU   r    s    Cr  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      dd }| j |ddd d S )Nc                  S   s,   d} t | }t| D ]}d| ||< q|S )Nr   r  r   r  r   r  rT   rT   rU   r  I  r  z0TestPrangeBasic.test_prange01.<locals>.test_implr   Tr   r   r  r  rT   rT   rU   test_prange01H     
zTestPrangeBasic.test_prange01c                 C   r  )Nc                  S   s6   d} t | d }td| D ]
}d| ||d < q|S )Nr   r   r  r  r  rT   rT   rU   r  S  s
   z0TestPrangeBasic.test_prange02.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange02R  r  zTestPrangeBasic.test_prange02c                 C   r  )Nc                  S   s   d} t dD ]}| d7 } q| S Nr   r   rX  rH  r   rT   rT   rU   r  ]  r  z0TestPrangeBasic.test_prange03.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange03\     
zTestPrangeBasic.test_prange03c                 C   r  )Nc                  S   s   d} t dD ]}| d9 } q| S )Nr   r   r   rX  r!  rT   rT   rU   r  f  r  z3TestPrangeBasic.test_prange03mul.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange03mule  r#  z TestPrangeBasic.test_prange03mulc                 C   r  )Nc                  S   s   d} t dD ]}| d8 } q| S )Nr]  r   r   rX  r!  rT   rT   rU   r  o  r  z3TestPrangeBasic.test_prange03sub.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange03subn  r#  z TestPrangeBasic.test_prange03subc                 C   r  )Nc                  S   s   d} t dD ]}| d } q| S r   rX  r!  rT   rT   rU   r  x  r  z3TestPrangeBasic.test_prange03div.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange03divw  r#  z TestPrangeBasic.test_prange03divc                 C   r  )Nc                  S   s>   d} d}t d}tdD ]}|| kr|||< qd||< q|S )Nr   r   r   r   r   r  r   rw   rx   rU  r   rT   rT   rU   r    s   


z0TestPrangeBasic.test_prange04.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange04  s   

zTestPrangeBasic.test_prange04c                 C   r  )Nc                  S   s>   d} t j| t jd}d}td| d dD ]}||| 7 }q|S Nr   r  r   r   r   r  r)  r   r   rU  rH  r   rT   rT   rU   r    s   z0TestPrangeBasic.test_prange05.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange05     
zTestPrangeBasic.test_prange05c                 C   r  )Nc                  S   s:   d} t j| t jd}d}tdddD ]}||| 7 }q|S r*  r+  r,  rT   rT   rU   r    s   z0TestPrangeBasic.test_prange06.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange06  r.  zTestPrangeBasic.test_prange06c                 C   r  )Nc                  S   s8   d} t j| t jd}d}t| dD ]}||| 7 }q|S r*  r+  r,  rT   rT   rU   r    s   z0TestPrangeBasic.test_prange07.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange07  r.  zTestPrangeBasic.test_prange07c                 C   r  )Nc                  S   sF   d} t | }d}tt|D ]}tt|D ]}||| 7 }qq|S r  r   r  r   r   r   rU  r  r   rT  rT   rT   rU   r    s   
z0TestPrangeBasic.test_prange08.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange08     
zTestPrangeBasic.test_prange08c                 C   r  )Nc                  S   s>   d} t | }d}tdD ]}tdD ]}||| 7 }qq|S r  r   r  r   r2  rT   rT   rU   r    s   
z2TestPrangeBasic.test_prange08_1.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange08_1  r4  zTestPrangeBasic.test_prange08_1c                 C       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   rX  )r   r  r   rT  rT   rT   rU   r    s   
z0TestPrangeBasic.test_prange09.<locals>.test_implr   r   Tr	  r   r   r  r  rT   rT   rU   test_prange09  s
   

zTestPrangeBasic.test_prange09c                 C   r7  )Nc                  S   s<   d} d}t | D ]}d}t | D ]}|d7 }q||7 }q|S r8  rX  )r   acc2rT  acc1r   rT   rT   rU   r    s   

z0TestPrangeBasic.test_prange10.<locals>.test_implr   r   Tr9  r  r  rT   rT   rU   test_prange10  s
   


zTestPrangeBasic.test_prange10z1list append is not thread-safe yet (#2391, #2408)c                 C   r  )Nc                  S   s   d} dd t | D S )Nr   c                 S   r   rT   )r   r  rS  rT   rT   rU   r     r   zDTestPrangeBasic.test_prange11.<locals>.test_impl.<locals>.<listcomp>rX  r   rT   rT   rU   r    s   z0TestPrangeBasic.test_prange11.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange11  s   
zTestPrangeBasic.test_prange11c                 C   r  )Nc                  S   s6   d} d}t |}tt| D ]}| || 7 } q| S r  r1  )r  r   rM  r   rT   rT   rU   r    s   
z0TestPrangeBasic.test_prange12.<locals>.test_implr   Tr  r  r  rT   rT   rU   test_prange12  r.  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 r  rX  r  rT   rT   rU   r    r  z0TestPrangeBasic.test_prange13.<locals>.test_implr   r   Tr  )r  r   r  r  rT   rT   rU   test_prange13  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   )rU  rH  r   rT   rT   rU   r     s   z0TestPrangeBasic.test_prange14.<locals>.test_implr   r   Tr  )r  r   r!  r"  r  rT   rT   rU   test_prange14  s
   
zTestPrangeBasic.test_prange14c                 C      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   r  )rg  r  r   r   rT   rT   rU   r    s
   
z0TestPrangeBasic.test_prange15.<locals>.test_implr-  r   Tr  r  r  rT   rT   rU   test_prange15  s   

zTestPrangeBasic.test_prange15c                 C   rC  )Nc                 S   s"   d}t |  | D ]}|d7 }q|S r  rX  rg  r  r   rT   rT   rU   r       
z0TestPrangeBasic.test_prange16.<locals>.test_implr-  r   Tr  r  r  rT   rT   rU   test_prange16     

zTestPrangeBasic.test_prange16c                 C   rC  )Nc                 S   s0   d}t | }t|  | D ]}||| 7 }q|S r  r5  rg  r  rM  r   rT   rT   rU   r  #  s
   
z0TestPrangeBasic.test_prange17.<locals>.test_implr  r   Tr  r  r  rT   rT   rU   test_prange17"     

zTestPrangeBasic.test_prange17c                 C   rC  )Nc                 S   sL   d}t | }t|  dD ]}||| 7 }td| D ]}||| 7 }qq|S )Nr   rq   r5  )rg  r  rM  r   rT  rT   rT   rU   r  -  s   
z0TestPrangeBasic.test_prange18.<locals>.test_implr  r   Tr  r  r  rT   rT   rU   test_prange18,     

zTestPrangeBasic.test_prange18c                 C   rC  )Nc                 S   sR   d}| d }t | |f}t|  | D ]}t| |D ]
}||||f 7 }qq|S r  r5  )rg  r  MrM  r   rT  rT   rT   rU   r  9  s   z0TestPrangeBasic.test_prange19.<locals>.test_implr  r   Tr  r  r  rT   rT   rU   test_prange198  rN  zTestPrangeBasic.test_prange19c                 C   rC  )Nc                 S   s.   d}t | }td| D ]}||| 7 }q|S )Nr   rG   r5  rI  rT   rT   rU   r  E  s
   
z0TestPrangeBasic.test_prange20.<locals>.test_implr  r   Tr  r  r  rT   rT   rU   test_prange20D  rK  zTestPrangeBasic.test_prange20c                 C   rC  )Nc                 S   s    d}t ddD ]}|d7 }q|S )Nr   r  rG   r   rX  rE  rT   rT   rU   r  O  rw  z0TestPrangeBasic.test_prange21.<locals>.test_implr  r   Tr  r  r  rT   rT   rU   test_prange21N  rH  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 ]}|| kr|||< q|dk r"d||< qd||< q|S )	Nr   r   r   r  r   r   rG   r  r'  r(  rT   rT   rU   r  X  s   



z0TestPrangeBasic.test_prange22.<locals>.test_implr   Tr   r   r  r  r  rT   rT   rU   test_prange22W  s   
zTestPrangeBasic.test_prange22c                 C   4   dd }t dd d d }| j||dddd d S )Nc                 S   s   t t| D ]}|| |< q| S rX   rA  rU  r   rT   rT   rU   r  i  s   
z0TestPrangeBasic.test_prange23.<locals>.test_impl    r   r   TrS  r   r  r  rQ   r  rU  rT   rT   rU   test_prange23g  
   

zTestPrangeBasic.test_prange23c                 C   rU  )Nc                 S   s"   t t|  dD ]}|| |< q| S r  rA  rV  rT   rT   rU   r  s  s   
z0TestPrangeBasic.test_prange24.<locals>.test_implrW  r   r   TrS  rX  rY  rT   rT   rU   test_prange24q  r[  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 rT   )r   
zeros_like)r   rH   r\  rT   rU   r   ~  r   zDTestPrangeBasic.test_prange25.<locals>.test_impl.<locals>.<listcomp>)r   r   )rU  r   r  r   rT   r\  rU   r  |  s
   z0TestPrangeBasic.test_prange25.<locals>.test_implr  r   r   T)r	  r   r   r  r  r   )
r   r  r  r   r   r   r  r  r   r   )rQ   r  rU  r   rs  r  rT   rT   rU   test_prange25{  s   

zTestPrangeBasic.test_prange25c                 C   rU  )Nc                 S   s,   | d d d }t t|D ]}|||< q| S r  rA  )rU  r9  r   rT   rT   rU   r    s   
z0TestPrangeBasic.test_prange26.<locals>.test_implrW  r   r   TrS  rX  rY  rT   rT   rU   test_prange26  s
   

zTestPrangeBasic.test_prange26c              	   C   s6   dd }| j |tdtg d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)rw   rx   r  rT  r   r  rT   rT   rU   r    s
   z0TestPrangeBasic.test_prange27.<locals>.test_implr  )
r   r   r   r   r   r   r   r   r   r   r   r   r   Tr9  )r  r   r  asarrayr  rT   rT   rU   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 ]&}||df }||df }| | }| | }|| }|d |d  }	|	||< q|S r  )r   r  r   r   )
r   r  r
  rw  i0i1Pt1Pt2r  vl2rT   rT   rU   r    s   
z0TestPrangeBasic.test_prange28.<locals>.test_impl      r6  rq  r   r   r   r   r   rq   r   TrS  )r   rd  r  rU  rT   rT   rU   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|S t dD ]}|d8 }q|S )Nr   r   r   rX  )flagr(  r   rT   rT   rU   r    s   

z0TestPrangeBasic.test_prange29.<locals>.test_implTFr  r  rT   rT   rU   test_prange29  s   
zTestPrangeBasic.test_prange29c                 C   s>   dd }t t ddd}t g d}| |||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< q!|S r~  )rc  r   r   r  r)  r   )
r   par
numthreadsn_parn_xr(  chunklenr   rT  rU  rT   rT   rU   r    s   
*z0TestPrangeBasic.test_prange30.<locals>.test_implr   r   r6  ro  r   )r   rd  r  r  )rQ   r  r   rl  rT   rT   rU   test_prange30  s   zTestPrangeBasic.test_prange30N)(ri   rL   rj   r3  r  r  r"  r$  r%  r&  r)  r-  r/  r0  r3  r6  r:  r=  r  skipr>  r?  r@  rB  rD  rG  rJ  rM  rP  rQ  rR  rT  rZ  r\  r^  r_  rb  ri  rk  rq  rT   rT   rT   rU   r  D  sJ    

				
		

	


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d4S )5TestPrangeSpecificz4 Tests specific features/problems found under prangec                 C   r  )Nc                 S   s.   d}t | D ]}|d7 }|dkr|d7 }q|S Nr   r   r   rX  r   r  r   rT   rT   rU   r       zRTestPrangeSpecific.test_prange_two_instances_same_reduction_var.<locals>.test_implr  r  r  rT   rT   rU   ,test_prange_two_instances_same_reduction_var  s   z?TestPrangeSpecific.test_prange_two_instances_same_reduction_varc                 C   Z   dd }|  tj}| |d W d    n1 sw   Y  d}| |t|j d S )Nc                 S   s.   d}t | D ]}|d7 }|dkr|d9 }q|S rt  rX  ru  rT   rT   rU   r    rv  zKTestPrangeSpecific.test_prange_conflicting_reduction_ops.<locals>.test_implr  zBReduction variable c has multiple conflicting reduction operators.)r  r   UnsupportedErrorr  r   r  r  rQ   r  r  r   rT   rT   rU   %test_prange_conflicting_reduction_ops  s   z8TestPrangeSpecific.test_prange_conflicting_reduction_opsc                 C   r  )Nc                  S   sJ   d } }t dD ]}|dkr| d7 } qtd}|d r |d7 }q| |fS )Nr   r   r   r  r  r:  )rU  r9  r   r   rT   rT   rU   r  	  s   

zLTestPrangeSpecific.test_prange_two_conditional_reductions.<locals>.test_implr  r  rT   rT   rU   &test_prange_two_conditional_reductions  s   
z9TestPrangeSpecific.test_prange_two_conditional_reductionsc                 C   r  )Nc                  S   s4   d} t dD ]}t dD ]
}|dkr| d7 } qq| S r  rX  )rU  r   r   rT   rT   rU   r    s   zCTestPrangeSpecific.test_prange_nested_reduction1.<locals>.test_implr  r  rT   rT   rU   test_prange_nested_reduction1  s   z0TestPrangeSpecific.test_prange_nested_reduction1c                 C   s   dd }|  t}|  W d    n1 sw   Y  | |d }| |d}| |d}|  t}|  W d    n1 sBw   Y  | }| |d tj d S )Nc                  S   s,   d} t | }t| D ]}d| ||< q|S )NrW  r   r  r  rT   rT   rU   r  !  r  z<TestPrangeSpecific.test_check_error_model.<locals>.test_implrT   r   )	r  ZeroDivisionErrorr  r   r   r   r   r   r  )rQ   r  r  r  pcrespfcresr(  rT   rT   rU   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	|	v rQ||	v rQ| |	d
d  nq<q4d S )Nc                 S   s*   t t| D ]}| | }d|d d < q| S r  rA  )rU  r   r9  rT   rT   rU   r  :  s   z?TestPrangeSpecific.test_check_alias_analysis.<locals>.test_implrW  r   r  r   TrS  definenoaliasr   )r   r  r   r  r  r   r   r   r   r  r/  r  r   r+  )
rQ   r  rU  r  r   r   r0  r   r  r/  rT   rT   rU   test_check_alias_analysis8  s    

z,TestPrangeSpecific.test_check_alias_analysisc                 C   rx  )Nc                 S   s"   d}t d| dD ]}|d7 }q|S r  rX  rE  rT   rT   rU   r  Q  rF  zJTestPrangeSpecific.test_prange_raises_invalid_step_size.<locals>.test_implr-  z4Only constant step size of 1 is supported for prange)r  r   r  r  r   r  r  rz  rT   rT   rU   $test_prange_raises_invalid_step_sizeP  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 ]$\}	}
|
 }t|D ]\}}|	|rO nqD| 
|	||d
   q8d S )Nc                  S   s&   d} d}t | D ]}||d 7 }q|S )NrN  r   r  rX  r  rT   rT   rU   r  `  s
   zFTestPrangeSpecific.test_prange_fastmath_check_works.<locals>.test_implr   Tr  rT   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  r  r-  r'  )rQ   r  r  r   r   _id
recipr_strreciprocal_inst	fadd_instr   kernelr  r   r   rT   rT   rU    test_prange_fastmath_check_works\  s*   

z3TestPrangeSpecific.test_prange_fastmath_check_worksc                 C   r  )Nc                 S   s8   t | | f}|d }t| D ]}|d ||< q| S r  r   r  r   rR  )r   rx   rw   rT  rT   rT   rU   r  {  s
   z8TestPrangeSpecific.test_parfor_alias1.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_alias1z  s   z%TestPrangeSpecific.test_parfor_alias1c                 C   r  )Nc                 S   sF   t | | f}t| D ]}|| }t| D ]}|| ||< qq| S rX   r  )r   rx   r   rw   rT  rT   rT   rU   r    s   z8TestPrangeSpecific.test_parfor_alias2.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_alias2  s   z%TestPrangeSpecific.test_parfor_alias2c                 C   r  )Nc                 S   sb   t | | | f}t| D ] }|| }t| D ]}|| }t| D ]
}|| | ||< q qq| S rX   r  )r   rx   r   rw   rT  r  r   rT   rT   rU   r    s   z8TestPrangeSpecific.test_parfor_alias3.<locals>.test_implr   r  r  rT   rT   rU   test_parfor_alias3  r2  z%TestPrangeSpecific.test_parfor_alias3c                 C   s8   dd }|  |dd}|d }d}| |t|j d S )Nc                 S   s   t |D ]}| }q|S rX   rX  )r   r  rT  r   rT   rT   rU   r    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  r!  )rQ   r  r*  warning_objexpected_msgrT   rT   rU   test_parfor_race_1  s
   z%TestPrangeSpecific.test_parfor_race_1c                 C   r9  )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   r6  r   )r   negativer   r  )r9  rh  r   this_mattersrT   rT   rU   r    s   zGTestPrangeSpecific.test_nested_parfor_push_call_vars.<locals>.test_implNr  r  rT   rT   rU   !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|D ]}|t | ||f 7 }qt|D ]}|t | ||f 7 }q.q||fS r  )r   r  r   r   r8  )zztclhlcr   ntrK  rT   rT   rU   r    s   zATestPrangeSpecific.test_copy_global_for_parfor.<locals>.test_implr   r  r   )r	  N)r   r  r"  r  )rQ   r  r  r  r  rT   rT   rU   test_copy_global_for_parfor  s
   z.TestPrangeSpecific.test_copy_global_for_parforc                 C   r  )Nc                 S   s0   d}t j}tdD ]}|d}||| 7 }q	|S )Nr   r   r6  )r   r  r   )r   r9  rh  r   r  rT   rT   rU   r    s   zGTestPrangeSpecific.test_multiple_call_getattr_object.<locals>.test_implr6  r  r  rT   rT   rU   !test_multiple_call_getattr_object  r*  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   rT   rT   rU   r    s   zHTestPrangeSpecific.test_argument_alias_recarray_field.<locals>.test_implr   r   r  r  Tr  )	r   r  rA  r  viewrecarrayr   r   r   )rQ   r  X1X2X3r  r  v3
python_resnjit_respa_funcpa_resrT   rT   rU   "test_argument_alias_recarray_field  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   )rM  retrw   rT   rT   rU   
list_check  s   
z>TestPrangeSpecific.test_mutable_list_param.<locals>.list_checkc                    s    t | D ]	}dg} |}q|S r  r  )r   r   rM  rw   r  rT   rU   r    s   
z=TestPrangeSpecific.test_mutable_list_param.<locals>.test_implr   Tr  Nr   r   )rQ   r  r  r  r  r  rT   r  rU   test_mutable_list_param  s   
	z*TestPrangeSpecific.test_mutable_list_paramc                 C   s<   dd }t jg d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 rT   )r   r   r  rT   rU   r     s    zXTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl.<locals>.<listcomp>)r   rd  r   r   r  rT   r  rU   r        zDTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl)r   r   r   r  r   r   )r   rd  r  r  r>  rT   rT   rU   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r#d}|||g||< q|S )Nr   g     o@)r   r  rc  r   )imagerw   rx   r  r   r  hrT   rT   rU   r    s   z>TestPrangeSpecific.test_ssa_false_reduction.<locals>.test_implrb  r  r   )r   r  r  r  )rQ   r  r  rT   rT   rU   test_ssa_false_reduction  s   z+TestPrangeSpecific.test_ssa_false_reductionc                 C   r  )Nc                  S   s@   d} t j| t jd}tdD ]}dg}d|d< |d ||< q|S )Nrq   r  r   r   )r   r  r%  r   )r   rw   r   rM  rT   rT   rU   r  +  s   z@TestPrangeSpecific.test_list_setitem_hoisting.<locals>.test_implr  r  rT   rT   rU   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 )	Nrh  c                 S   s   t dD ]}d| | d< qd S )Nr   rh  rX  )statesr   rT   rT   rU   r  :  s   z?TestPrangeSpecific.test_record_array_setitem.<locals>.test_implc                 S   s    | d d |d d ksJ d S )Nr   rh  rT   rv   rT   rT   rU   r  >  r  z>TestPrangeSpecific.test_record_array_setitem.<locals>.comparerr   )rc  r  r  )r   r  r  r  r  )rQ   state_dtyper  r  rT   rT   rU   test_record_array_setitem6  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   rT   rT   rU   r  H  s   zKTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.test_implr   r  c                 S   r  rX   r  rv   rT   rT   rU   r  P  r   zJTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.comparerr  )r   r  r&  r  r  )rQ   r  r  r  r  rT   rT   rU   %test_record_array_setitem_yield_arrayE  s   
z8TestPrangeSpecific.test_record_array_setitem_yield_arrayc                 C   s   dd }|  |dd d S )Nc                 S   s`   t | f}|dkrt| D ]
}||  d7  < q|d S t| D ]
}||  d7  < q!|d S )Nr   r   r   r  )r_  caser(  r   rT   rT   rU   r  X  s   z4TestPrangeSpecific.test_issue7501.<locals>.test_implr   r   r  r  rT   rT   rU   test_issue7501W  s   
z!TestPrangeSpecific.test_issue7501c                 C   s(   dd }d}t j|}| || d S )Nc           
      S   s   d}t g d}|jd }| jd }d}t|D ]0}| | }|| d  d|d   }t |}	||	t ||  t t t ||	  7 }q|S )Nr5  )rh  r  r  r   r   )r   rd  rc  r   r=  r7  rR  r8  )
rM  rx   pointsrg  r   expsr   pr   r  rT   rT   rU   r  e  s   


2z6TestPrangeSpecific.test_kde_example.<locals>.test_implrN  )r   r!  r"  r  r  rT   rT   rU   test_kde_exampled  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_errorrW  )rK   stderrzTEST PASSED)subpcheck_outputsys
executableSTDOUTr   decode)rQ   r
  rT   rT   rU   test_issue_due_to_max_labelw  s   
z.TestPrangeSpecific.test_issue_due_to_max_labelN)ri   rL   rj   r3  rw  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  rT   rT   rT   rU   rs    s:    

	
rs  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      t d d S r  r   rZ   rT   rT   rU   setUp  r\   zTestParforChunksizing.setUpc                 C   r  r  r  rZ   rT   rT   rU   tearDown  r\   zTestParforChunksizing.tearDownc                 C   s>   |  t d td |  t d td |  t d d S Nr   r  )r   r   r   rZ   rT   rT   rU   $test_python_parallel_chunksize_basic  s
   z:TestParforChunksizing.test_python_parallel_chunksize_basicc                 C   sV   |  t d td |  t d W d    n1 sw   Y  |  t d d S r  )r   r   r   rZ   rT   rT   rU   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 rX   )r   rT   rT   rT   rU   get_cs  s   zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.get_csc                 S   s   t | S rX   r  r  rT   rT   rU   set_cs  r  zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.set_csr   r  r  )rQ   r  r  rT   rT   rU   "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   sD   t  }td t  }W d    n1 sw   Y  t  }|||fS )Nr  )r   r   )r   cs1cs2cs3rT   rT   rU   r    s   

zATestParforChunksizing.test_njit_with_chunksize.<locals>.test_implr  r   r  )rQ   r  r  r  r  rT   rT   rU   test_njit_with_chunksize  s   
z.TestParforChunksizing.test_njit_with_chunksizec                 C   sh   t dddd }dD ]&}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. Tr  c                 S   sr   t |}t |d}t|  t|D ]}t ||< d||< qW d    ||fS 1 s0w   Y  ||fS )Nir   )r   r  r  r   r   r   r   )csr   r7  inner_csr   rT   rT   rU   r    s   


zLTestParforChunksizing.test_all_iterations_reset_chunksize.<locals>.test_impl)i  i  i  i  rd  r   r   r   N)r   r   r'  r   all)rQ   r  rT  r   r7  r  rT   rT   rU   #test_all_iterations_reset_chunksize  s   
z9TestParforChunksizing.test_all_iterations_reset_chunksizec                 C   sV   |  t}tdd }|  W d    n1 sw   Y  d}| |t|j d S )Nc                   S   r  )NrG   r  rT   rT   rT   rU   neg_test  r  zMTestParforChunksizing.test_njit_parallel_chunksize_negative.<locals>.neg_test/chunksize must be greater than or equal to zero)r  r   r   r   r  r  )rQ   r  r  r   rT   rT   rU   %test_njit_parallel_chunksize_negative  s   
z;TestParforChunksizing.test_njit_parallel_chunksize_negativec                 C   L   |  t}td W d    n1 sw   Y  d}| |t|j d S )NrG   r  )r  r   r   r   r  r  rQ   r  r   rT   rT   rU   'test_python_parallel_chunksize_negative  s
   
z=TestParforChunksizing.test_python_parallel_chunksize_negativec                 C   sX   |  tj}tdd }|  W d    n1 sw   Y  d}| |t|j d S )Nc                   S   r  )Ninvalid_typer  rT   rT   rT   rU   r     r  zMTestParforChunksizing.test_njit_parallel_chunksize_invalid_type.<locals>.impl)The parallel chunksize must be an integer)r  r   TypingErrorr   r   r  r  )rQ   r  r   r   rT   rT   rU   )test_njit_parallel_chunksize_invalid_type  s   
z?TestParforChunksizing.test_njit_parallel_chunksize_invalid_typec                 C   r  )Nr  r  )r  	TypeErrorr   r   r  r  r  rT   rT   rU   +test_python_parallel_chunksize_invalid_type  s
   
zATestParforChunksizing.test_python_parallel_chunksize_invalid_typeN)ri   rL   rj   r3  rk   r  r  r  r  r  r  r  r  r  r  r  rT   rT   rT   rU   r    s    r  c                   @   sF   e Zd ZdZdd Ze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|| q#|
d
 p |
d [ tdd |D }| |d }|dkrT| ||}n| ||}| |}|rt	
d}||j }| t|d | |d
 | | |i  |W  d    W  d    S 1 sw   Y  W d    d S 1 sw   Y  d S )Nr   Fcpu_namezskylake-avx512
assertionsTcpu_featuresz-prefer-256-bit)NUMBA_CPU_NAMENUMBA_CPU_FEATURESr   r   c                 S   r   rT   r   r   rT   rT   rU   r     r   z8TestParforsVectorizer.get_gufunc_asm.<locals>.<listcomp>z%call\s+\w+\*\s+@do_scheduling_(\w+)\()r   r/  r   r9   r   r  r   r   r  r  r  findallr   r   r   r   r   assertNotEqual)rQ   r   schedule_typer   r   r   r  r  r  env_opts	overridesr   r  r   pfunc_vectorizabler   asmschedtymatchesrT   rT   rU   get_gufunc_asm  s2   

Rz$TestParforsVectorizer.get_gufunc_asmz
\s+vsqrtpd\s+.*zmm.*
c                 C   s   dd }t d}| j|d|dd}| j|d|dd}| D ]$}| d|v  | d	|v  | d
|v  | t| j|dk q| D ]%}| d|v | d	|v | d|v  | d|v  | d
|v qHd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 r  r   r   r   r   )rU  r   r  r   rT   rT   rU   will_vectorize9  s
   zJTestParforsVectorizer.test_vectorizer_fastmath_asm.<locals>.will_vectorizer   r   Tr   Fvaddpdvsqrtpdzmmr   vsqrtsdvaddsdN)r   r  r  r  r'  r   match_vsqrtpd_on_zmmr  )rQ   r  rR  fast_asmslow_asmr  rT   rT   rU   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 d   n1 s/w   Y  | D ]}| d|v | d|v  | d|v q8| D ]$}| d|v  | d|v  | d|v  | t| j|dk qTdS )r  c                 S   s0   t | }t| dD ]}t| | | |< q
| S r  r  rU  r   r   rT   rT   rU   will_not_vectorizea  s   zTTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_not_vectorizec                 S   s,   t | }t|D ]}t| | | |< q| S rX   r  r  rT   rT   rU   r  g  s   zPTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_vectorizer   NUMBA_BOUNDSCHECK0r   Tr  r   Nr  r  r  vmovupdr   )	r   r  r9   r  r  r'  r   r  r  )rQ   r  r  rR  	novec_asmvec_asmr  rT   rT   rU   "test_unsigned_refusal_to_vectorizeZ  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 d   n1 s(w   Y  dd }| D ]\}}||} | D ]\}}||}	 ddlm}
 | t|t|	 t||	D ].\}}||kriq`|
dd ||}| }|D ]}|d dkr| ||d |d  d qwq`d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   rq  r   rX  r  rT   rT   rU   signed_variant  s
   
zMTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.signed_variantc                  S   s"   d} d}t | D ]}||7 }q|S )Nr
  rq  rX  r  rT   rT   rU   unsigned_variant  s
   
zOTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.unsigned_variantr  r  r   Tr  r   Nc                 S   s`   g }|   D ]'}| }|dkr-|ds-|ds-|ds-d|v s-|tdd| q|S )N rF   rH   "r  z[	])r  strip
startswithr   r  sub)r  r  r   spdrT   rT   rU   strip_instrs  s   zKTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.strip_instrsr   )SequenceMatcherc                 S   s   | dkS )N	rT   r  rT   rT   rU   rb    r  zGTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.<lambda>insertr  rG   r  )	r9   r  r/  difflibr  r   r   r   get_opcodes)rQ   r  r  
signed_asmunsigned_asmr  r   r  signed_instrunsigned_instrsmrw   rx   rH  r)  r,  rT   rT   rU   test_signed_vs_unsigned_vec_asm  s<   	z5TestParforsVectorizer.test_signed_vs_unsigned_vec_asmN)ri   rL   rj   rk   r  r  r  r  r:   r  r	  r  rT   rT   rT   rU   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                    P   t j}d|  |d tdd fdd}|}|}| || d S )Nr   r   Tr  c                    s@   d}t |  t D ]}d|  }t | t }||7 }q
|S r  r   r   r   nthreadsr  r   
local_maskgntrO  maskrT   rU   udt     
z6TestParforReductionSetNumThreads.test_add.<locals>.udtr   NUMBA_NUM_THREADSr   r  r}  rQ   rg  r(  expectr  rT   r&  rU   test_add     

z)TestParforReductionSetNumThreads.test_addc                    sV   t dtj}d|  |d tdd fdd}|}|}| || d S )Nr   r   r   Tr  c                    s@   d}t |  t D ]}d|  }t | t }||9 }q
|S r  r!  r"  r&  rT   rU   r(    r)  z6TestParforReductionSetNumThreads.test_mul.<locals>.udt)r=  r   r+  r   r  r}  r,  rT   r&  rU   test_mul  s   

z)TestParforReductionSetNumThreads.test_mulc                    r   )Nr   r   Tr  c                    sB   d}t |  t D ]}d|  }t | t }t||}q
|S r  )r   r   r   r>  r"  r&  rT   rU   r(    s   z6TestParforReductionSetNumThreads.test_max.<locals>.udtr*  r,  rT   r&  rU   r    r/  z)TestParforReductionSetNumThreads.test_maxN)ri   rL   rj   r3  r.  r0  r  rT   rT   rT   rU   r    s
    r  __main__rX   )mathr   r  r  r   osrl   r  
subprocessr   r  r$  	functoolsr   r  r   numpy.randomr   r  collectionsr   r   r   	itertoolsr	   r
   r  numba.parfors.parforr   r   r   r   r   r   r   r   r   
numba.corer   r   r   r   r   r   r   r   r   r   numba.extendingr   r   r    r!   r"   r#   numba.core.registryr$   numba.core.annotationsr%   numba.core.ir_utilsr&   r'   r(   r)   r*   r+   r,   numba.np.unsafe.ndarrayr-   r  numba.core.bytecoder.   numba.core.compilerr/   r0   r1   r2   numba.core.compiler_machineryr3   r4   numba.core.typed_passesr5   numba.tests.supportr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   numba.core.extendingrC   r  r  rD   r  rm   x86_onlyr  r  rr   ry   rz   rI  rP  ri  r  r   r  r  r  r  r  r  r  r  rs  rw  r  r   r4  r  r  r  r  r  r  r  r  r  r  rs  r  r  r  ri   mainrT   rT   rT   rU   <module>   s   (4 $<=
	  "8	
" ,*            +%=   @ 0 %   '   z L
B