o
    iӈ                    @   sx  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ	d dl
Z
d dlmZ d dlZd dlmZ d dlZd dlmZmZ d dlZd dlmZmZ d dlZd dlZd dlmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$mZm%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-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lFmGZGmHZH d dlImJZJmKZK d dlLmMZM d dlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ d dl]m^Z^ d dl_m`Z` d dl$maZa d dlbZbd dlcZceUG dd deOZdeceef dvdZgdZhdZieddZjdd Zke[G dd  d eOZld!d" Zmd#d$ Znd%d& Zod'd( Zpd)d* Zqd+d, Zrd-d. Zsd/d0 Ztd1d2 Zud3d4 Zvd5d6 Zwddd7d8Zxd9d: ZyG d;d< d<ezZ{eUG d=d> d>elZ|eUG d?d@ d@elZ}eUG dAdB dBelZ~G dCdD dDeOZeUG dEdF dFelZeUG dGdH dHeQelZeUG dIdJ dJelZeUG dKdL dLelZeUG dMdN dNelZeUG dOdP dPelZeUG dQdR dRelZG dSdT dTelZeUG dUdV dVeZe^dWdX ZeUG dYdZ dZeZeUG d[d\ d\eOZeUegG d]d^ d^eZeUG d_d` d`eOZeUG dadb dbeOZedckr:ec  dS dS )e    Nreducerandn)defaultdict
namedtuple)cyclechain)njitprangeparallel_chunksizeget_parallel_chunksizeset_parallel_chunksizeset_num_threadsget_num_threadstypeof)	typeserrorsirrewritestyped_passesinline_closurecallconfigcompilercpu)DictList)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)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skip_ppc64le_invalid_ctr_loop)register_jitable)_fix_LOAD_GLOBAL_arg)utilsc                   @   s   e Zd ZdZe dkrdndZ	 dd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"TestParforsRunnerFaarch64i  i  c                 C   s8   | j }|  dd dd }| j||| jd d S )N._)test_module
test_classtimeout)
__module__idsplitsubprocess_test_runner_TIMEOUT)selfthemodtest_clazz_name rS   U/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/numba/tests/test_parfors.pyrunnerQ   s   
zTestParforsRunner.runnerc                 C      |    d S NrU   rP   rS   rS   rT   test_TestParforBasicY      z&TestParforsRunner.test_TestParforBasicc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforNumericalMisc\   r[   z.TestParforsRunner.test_TestParforNumericalMiscc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforNumPy_   r[   z&TestParforsRunner.test_TestParforNumPyc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsb   r[   z"TestParforsRunner.test_TestParforsc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsBitMaske   r[   z)TestParforsRunner.test_TestParforsBitMaskc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsDiagnosticsh   r[   z-TestParforsRunner.test_TestParforsDiagnosticsc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsLeaksk   r[   z'TestParforsRunner.test_TestParforsLeaksc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsMiscn   r[   z&TestParforsRunner.test_TestParforsMiscc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsOptionsq   r[   z)TestParforsRunner.test_TestParforsOptionsc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsSlicet   r[   z'TestParforsRunner.test_TestParforsSlicec                 C   rV   rW   rX   rY   rS   rS   rT   test_TestParforsVectorizerw   r[   z,TestParforsRunner.test_TestParforsVectorizerc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestPrangeBasicz   r[   z&TestParforsRunner.test_TestPrangeBasicc                 C   rV   rW   rX   rY   rS   rS   rT   test_TestPrangeSpecific}   r[   z)TestParforsRunner.test_TestPrangeSpecificN)__name__rK   __qualname___numba_parallel_test_platformmachinerO   rU   rZ   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rS   rS   rS   rT   rC   C   s$    rC   )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.
    NrS   abrS   rS   rT   null_comparer   s   rx   c                   @   s   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d Zd(ddZd(ddZd d! Zd"d# Zd$d% Zd&d' Zd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                 K   s   t |fi ||j| S rW   )r
   	overloads)rP   funcsigflagsrS   rS   rT   _compile_this   s   zTestParforsBase._compile_thisc                 C   s   | j ||ddS )NTparallelr~   rP   r{   r|   rS   rS   rT   compile_parallel      z TestParforsBase.compile_parallelc                 C   s   | j ||dddS )NT)r   fastmathr   r   rS   rS   rT   compile_parallel_fastmath      z)TestParforsBase.compile_parallel_fastmathc                 C   s   |  ||S rW   r   r   rS   rS   rT   compile_njit   r[   zTestParforsBase.compile_njitc                 O   s2   t dd |D }| ||}| ||}||fS )Nc                 S      g | ]}t |qS rS   numbar   .0xrS   rS   rT   
<listcomp>       z/TestParforsBase.compile_all.<locals>.<listcomp>)tupler   r   )rP   pyfuncargskwargsr|   cpfunccfuncrS   rS   rT   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 ]q}t|tjr||d q	t|tjr(||  q	t|tjr4|| q	|d u r>|| q	t|t rL|t	| q	t|t
r[||d d   q	t|tri|t| q	t|trw|t| q	tdt |S )Nkz%Unsupported argument type encountered)r   
isinstancenpndarrayappendcopynumbernumbersNumberdeepcopylistr   r   
ValueError)r   new_argsr   rS   rS   rT   	copy_args   s,   



z:TestParforsBase.check_parfors_vs_others.<locals>.copy_args)
popentry_pointr   testingassert_almost_equalassertEqualtypelenzipr   )rP   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_outputrS   rS   rT   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   rP   r   r   r   r   r   rS   rS   rT   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   )rP   implarg_genr   r   rS   rS   rT   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)rP   r   r   r   r   argtysrS   rS   rT   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unsignedrG   z$Unknown scheduler_type specified: %s)r   assertInlibraryget_llvm_str)rP   cresr   scheduler_strmsgrS   rS   rT   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   linspacerS   nrS   rT   gen9  s   z)TestParforsBase.gen_linspace.<locals>.genc                    s   g | ]}t  qS rS   )nextr   i)srcrS   rT   r   ?      z0TestParforsBase.gen_linspace.<locals>.<listcomp>)r   range)rP   r   ctr   rS   )r   r   rT   gen_linspace6  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   rS   rS   rT   r   H      z9TestParforsBase.gen_linspace_variants.<locals>.<listcomp>   )r   r   c                 S   r   rS   r   asfortranarrayr   rS   rS   rT   r   L  r   c                 S   r   ))r   r      r   r   rS   rS   rT   r   O  r      c                 S   r   rS   r   r   rS   rS   rT   r   S  r   N)r   )rP   r   arr2dsarr3dsrS   rS   rT   gen_linspace_variantsA  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 rS   namer   magicstrrS   rT   r   W  s    z/TestParforsBase._filter_mod.<locals>.<listcomp>N)str)rP   modr   checkstrfiltr   rS   r   rT   _filter_modU  s
   zTestParforsBase._filter_modc           	      C   sX   dd |j jjjjD }| j|||d}|j  }g }|D ]}|j|v r)|| q|S )z gets the gufunc LLVM Modulesc                 S      g | ]}|qS rS   rS   r   rS   rS   rT   r   _      z7TestParforsBase._get_gufunc_modules.<locals>.<listcomp>)r   )	r   _codegen_engine_ee_modulesr   get_asm_strr   r   )	rP   r   r   r   r  potential_matcheslib_asmretr   rS   rS   rT   _get_gufunc_modules]  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   )rP   r   fnr   gufunc_modsr   r   rS   rS   rT   _get_gufunc_infol  s   z TestParforsBase._get_gufunc_infoc                 C   s   |  |tS )z
        Returns the IR of the gufuncs used as parfor kernels
        as a dict mapping the gufunc name to its IR.

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

        Arguments:
         cres - a CompileResult from `njit(parallel=True, ...)`
        c                    s   t  | S rW   )r   emit_assembly)r   tmrS   rT   emit_asm     z1TestParforsBase._get_gufunc_asm.<locals>.emit_asm)r   r   _tmr  )rP   r   r  rS   r  rT   _get_gufunc_asm  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   mrS   rS   rT   _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fcmpcallr   z fastr   )
assertTrue)instrsopsinstcountopmatchrY   rS   rT   _assert_fast  s   z5TestParforsBase.assert_fastmath.<locals>._assert_fastN)r   r  items)
rP   r   r|   r   _irr  r)  r   guirr%  rS   rY   rT   assert_fastmath  s   
	

zTestParforsBase.assert_fastmathrW   )rh   rK   ri   __doc__rj   r~   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r-  rS   rS   rS   rT   ry      s*    ^




ry   c                 C   s   t | | }d| | }|t | }|| | | | }|| }	dd|  }
dd|	  }|t | |  }|| }| |
 | }|| |  }|S )N      ?      ?)r   logsqrtexp)sptpricestrikerate
volatilitytimevlogtermpowtermdend1d2NofXd1NofXd2futureValuec1r!  putrS   rS   rT   blackscholes_impl  s   rC  c                 C   sF   t |D ]}|tddt|  t||   d |  |8 }q|S Nr0  )r   r   dotr3  )YXw
iterationsr   rS   rS   rT   lr_impl  s   6rJ  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   )mathr2  r   sumr   j)A	centroidsr   rS   rT   r     s    42example_kmeans_test.<locals>.<listcomp>.<listcomp>r   r   )rP  rQ  	numCenterr   rT   r     
    
z'example_kmeans_test.<locals>.<listcomp>c                    s    g | ]} |d d f   qS rW   argminr   )distrS   rT   r     s     c                    s&   g | ]  fd dt D qS )c                    s0   g | ]}t  k|f t k qS rS   r   rM  rN  )rP  r   labelsrS   rT   r     s    (rR  rS  rT  )rP  Dr\  rV  rT   r     rW  )shaper   r   array)rP  rU  numIterinit_centroidsNlrS   )rP  r]  rQ  rZ  r\  rU  rT   example_kmeans_test  s   

rd  c                 K   s$  t j}t j}t| }|rt|}ntd}t||||}|  |  t	j
|jj|dd}|  tjd|j t|jj|jj|jj|jjd \|j_|j_|j_}	tj|jj|jj|jjdd |jj|jjtjd tjj  }
tjjj!|jj|jj|jj|jj|jj||
j"d}|  tjd|j t# }tjjj$|jj|jj|jj|jj|jj|jj|||jj%|
d
}|  tjjj&|jj|jj|jj|jj|jj|jj|||jj%|
d
}|  tjjj'|jj|jj|jj|jj|jj|jj|||jj%|
d
}|  t(|j)|_*||fS )	NT)typedzbefore-inferencerS   )func_irtypemap	calltypesliftedlifted_fromr   return_typehtml_output)swappedzafter-inference)diagnostics)+r#   typing_contexttarget_contextr   run_frontendr   ParallelOptionsTestPipelinerefreshr   InlineClosureCallPassstaterf  runr   rewrite_registryapplyr   type_inference_stage	typingctx	targetctxr   rg  rk  rh  r$   TypeAnnotationr   HTMLr   parforsparforParforDiagnosticsPreParforPassreplaced_fnsFlags
ParforPassmetadataParforFusionPassParforPreLoweringPassr'   blocks_definitions)	test_funcr   kwsr{  r|  test_iroptionstpinline_passrG   rn  preparfor_passr}   parfor_passrS   rS   rT   get_optimized_numba_ir  st   




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%  rS   rS   rT   r     s   r   c                 K   s&   t | |fi |\}}t|j|jjS rW   )r  _count_arrays_innerr  rv  rg  r  r   r  r  r  rS   rS   rT   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%  rS   rS   rT   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  rg  r  arr_setr  r  r   r%  parfor_blocksrS   rS   rT   r  6  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  rS   rS   rT   countArrayAllocsH  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   r!  )emptynumpy)r,   znumba.np.unsafe.ndarrayr   )r  r   r   r  r  r  r  r  r  r  r   r  valueExprr'  r&   r%   )rf  r  r  r%  rw   rS   rS   rT   r  Q  s   
r  c                 K   s(   t | |fi |\}}t||j|jjS rW   )r  &_count_non_parfor_array_accesses_innerr  rv  rg  r  rS   rS   rT   countNonParforArrayAccessesb  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  rg  parfor_indicesr  r  r  stmtr  rS   rS   rT   r  g  sH   






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 rW   r   )r   vrS   rS   rT   	<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varnamesrS   rS   rT   r    s   
r  c                   @      e Zd Zdd ZdS )rs  c                 C   sN   t  | _|| j_|| j_|| j_|| j_d | j_d | j_d | j_	i | j_
d S rW   )r   	StateDictrv  r{  r|  r   rf  rg  rk  rh  r  )rP   r{  r|  r   r  rS   rS   rT   __init__  s   
zTestPipeline.__init__N)rh   rK   ri   r  rS   rS   rS   rT   rs    s    rs  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         @      @)ry   r  r   r   arangeTsimple_args)rP   r   r  rS   rS   rT   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 )NrS   r   onesrS   rS   rS   rT   	test_impl     
z0TestParforBasic.test_simple01.<locals>.test_impl'@do_scheduling' not foundassertRaisesAssertionErrorr   r   r   	exceptionrP   r  raisesrS   rS   rT   test_simple01  
   zTestParforBasic.test_simple01c                 C      dd }|  | d S )Nc                   S   r  )Nr   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple02.<locals>.test_implr   rP   r  rS   rS   rT   test_simple02     zTestParforBasic.test_simple02c                 C   r  )Nc                   S   r  Nr   r   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple03.<locals>.test_implr  r  rS   rS   rT   test_simple03  r  zTestParforBasic.test_simple03c                 C   r  )Nc                   S   r  Nr   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple04.<locals>.test_implr  r  rS   rS   rT   test_simple04  r  zTestParforBasic.test_simple04c                 C   r  )Nc                   S   s   t jdt jdS )Nr  dtyper   r  
complex128rS   rS   rS   rT   r    r   z0TestParforBasic.test_simple07.<locals>.test_implr  r  rS   rS   rT   test_simple07  r  zTestParforBasic.test_simple07c                 C   r  )Nc                   S   s   t dt d S r  r  rS   rS   rS   rT   r       z0TestParforBasic.test_simple08.<locals>.test_implr  r  rS   rS   rT   test_simple08  r  zTestParforBasic.test_simple08c                 C   r  )Nc                   S   r  )Nr   r   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple09.<locals>.test_implr  r  rS   rS   rT   test_simple09  r  zTestParforBasic.test_simple09c                 C   r  )Nc                   S   r  )Nr   r   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple10.<locals>.test_implr  r  rS   rS   rT   test_simple10  r  zTestParforBasic.test_simple10c                 C   r  )Nc                   S   s   t dd S Nr   r   r0  r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple11.<locals>.test_implr  r  rS   rS   rT   test_simple11  r  zTestParforBasic.test_simple11c                 C   r  )Nc                   S   s   t dt d S r  r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple12.<locals>.test_implr  r  rS   rS   rT   test_simple12  r  zTestParforBasic.test_simple12c                 C   r  )Nc                   S   r  rD  )r   r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple13.<locals>.test_implr  r  r  rS   rS   rT   test_simple13  r  zTestParforBasic.test_simple13c                 C   r  )Nc                   S   s   t ddd d S )Nr  r      r  rS   rS   rS   rT   r    r  z0TestParforBasic.test_simple14.<locals>.test_implr  r  rS   rS   rT   test_simple14  r  zTestParforBasic.test_simple14c                 C       dd }| j |g| jR   d S )Nc                 S   s   | |  S rW   rS   v1v2m1m2rS   rS   rT   r       z0TestParforBasic.test_simple15.<locals>.test_implr   r  r  rS   rS   rT   test_simple15     zTestParforBasic.test_simple15c                 C   r  )Nc                 S   s   || S rW   rS   r  rS   rS   rT   r    r  z0TestParforBasic.test_simple16.<locals>.test_implr  r  rS   rS   rT   test_simple16  r  zTestParforBasic.test_simple16c                 C   r  )Nc                 S   s   ||  S rW   rS   r  rS   rS   rT   r    r  z0TestParforBasic.test_simple17.<locals>.test_implr  r  rS   rS   rT   test_simple17  r  zTestParforBasic.test_simple17c                 C   r  )Nc                 S   s   |j tj|d  S r  )r  r   linalgsvdr  rS   rS   rT   r       z0TestParforBasic.test_simple18.<locals>.test_implr  r  rS   rS   rT   test_simple18     zTestParforBasic.test_simple18c                 C   r  )Nc                 S   s   t ||S rW   r   rE  r  rS   rS   rT   r    r[   z0TestParforBasic.test_simple19.<locals>.test_implr  r  rS   rS   rT   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 rW   r  r  rS   rS   rT   r  
  r[   z0TestParforBasic.test_simple20.<locals>.test_implr  )r  r  r   r  r   r   r  r  rS   rS   rT   test_simple20  s
   zTestParforBasic.test_simple20c                 C   r  )Nc                 S      t | | S rW   r  r  rS   rS   rT   r    r[   z0TestParforBasic.test_simple21.<locals>.test_implr  r  rS   rS   rT   test_simple21  r  zTestParforBasic.test_simple21c                 C   r  )Nc                 S   s   t | |  S rW   r[  r  rS   rS   rT   r    r  z0TestParforBasic.test_simple22.<locals>.test_implr  r  rS   rS   rT   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   yrS   rS   rT   r    s   "z0TestParforBasic.test_simple23.<locals>.test_implr  r  rS   rS   rT   test_simple23     zTestParforBasic.test_simple23c                 C   r  )Nc                  S   s2   d} t | | f}t | }t |d d |f S )Nr  )r   r  r  rM  )r   rP  rw   rS   rS   rT   r  $  s   
z0TestParforBasic.test_simple24.<locals>.test_implr  r  rS   rS   rT   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
  rW   operatorr  r  rS   rS   rT   r  .  r[   z:TestParforBasic.test_simple_operator_15.<locals>.test_implNr  r  rS   rS   rT   test_simple_operator_15+  s   z'TestParforBasic.test_simple_operator_15c                 C   r  )Nc                 S   s   t ||S rW   r  r  rS   rS   rT   r  5  r[   z:TestParforBasic.test_simple_operator_16.<locals>.test_implr  r  rS   rS   rT   test_simple_operator_163     z'TestParforBasic.test_simple_operator_16c                 C   r  )Nc                 S   s   t || S rW   r  r  rS   rS   rT   r  <  r[   z:TestParforBasic.test_simple_operator_17.<locals>.test_implr  r  rS   rS   rT   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   rS   rv   rS   rS   rT   r  C  s   z5TestParforBasic.test_inplace_alias.<locals>.test_implc                 S      t j| | d S rW   r   r   assert_equalru   rS   rS   rT   comparerG  r   z4TestParforBasic.test_inplace_alias.<locals>.comparerr   r   r   r  r   )rP   r  r  r   rS   rS   rT   test_inplace_aliasA  s   
z"TestParforBasic.test_inplace_aliasN)"rh   rK   ri   r.  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r;   r  r:   r  r	  r  r  r  r  r<   r  r  r  r  rS   rS   rS   rT   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ranfrM  )r   r   r  rS   rS   rT   r  S  s   "z2TestParforNumericalMisc.test_pi.<locals>.test_impli r   decimalr   )r   r   r   r   int64r  intpr  rS   rS   rT   test_piR  s   zTestParforNumericalMisc.test_pic                 C   s*   t jd d  fd }| tt|d d S Nrp   r   )r   float64r   r   rC  rP   r   rS   rS   rT   test_blackscholes\  s   z)TestParforNumericalMisc.test_blackscholesc                 C   s\   t jd d  t jd d d d f t jd d  t jf}| tt|d | tt|d d S Nr   r   )r   r(  r$  r   r   rJ  r  r)  rS   rS   rT   test_logistic_regressiona  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   rd  r   Arrayr(  r%  r   r  )rP   rb  r]  centersrP  ra  arg_typsrS   rS   rT   test_kmeansh  s   
z#TestParforNumericalMisc.test_kmeansN)	rh   rK   ri   r.  r&  r*  r:   r,  r3  rS   rS   rS   rT   r  N  s    

r  c                   @   s   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestParforNumPyz'Tests NumPy functionality under parforsc                 C   s>   dd }t ddddd}t ddd}| ||| d S )Nc                 S      t | |S rW   r  rv   r  rS   rS   rT   r    r[   z-TestParforNumPy.test_mvdot.<locals>.test_implr   r   r  r   r   )r   r   r   r   )rP   r  rP  r  rS   rS   rT   
test_mvdot}  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 rW   r   r  rM  )r   rP  r.  Br'  rS   rT   r    s   
zBTestParforNumPy.test_fuse_argmin_argmax_max_min.<locals>.test_impl   r   r   )r   rY  argmaxminmaxr   r   r   r   r$  r  r%  r  rS   r:  rT   test_fuse_argmin_argmax_max_min  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   rP  rS   rS   rT   r       zDTestParforNumPy.test_np_random_func_direct_import.<locals>.test_implr   r   r   r   r$  r  rS   rS   rT   !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 rW   r   r  r   rS   rS   rT   
test_impl1  r  z/TestParforNumPy.test_arange.<locals>.test_impl1c                 S   r5  rW   rF  sr   rS   rS   rT   
test_impl2  r[   z/TestParforNumPy.test_arange.<locals>.test_impl2c                 S      t | ||S rW   rF  rI  r   trS   rS   rT   
test_impl3  r  z/TestParforNumPy.test_arange.<locals>.test_impl3            >@r   rp   r   complexr   rP   rG  rJ  rN  argrS   rS   rT   test_arange  s   zTestParforNumPy.test_arangec                 C   sP   dd }dd }dd }dD ]}|  || |  |d| |  |d|d qd S )	Nc                 S   s   t j| t jdS Nr  r   r  float32r   rS   rS   rT   rG    r   z5TestParforNumPy.test_arange_dtype.<locals>.test_impl1c                 S   s   t j| |t jdS rW  rX  rH  rS   rS   rT   rJ    r   z5TestParforNumPy.test_arange_dtype.<locals>.test_impl2c                 S   s   t j| ||t jdS rW  rX  rL  rS   rS   rT   rN    r  z5TestParforNumPy.test_arange_dtype.<locals>.test_impl3)rO  rP  rQ  r   r  rT  rS   rS   rT   test_arange_dtype  s   z!TestParforNumPy.test_arange_dtypec                 C   sR   dd }dd }dddt dd	t d	dfD ]}| |d
| | |d
|d qd S )Nc                 S   r5  rW   r   )startstoprS   rS   rT   rG    r[   z1TestParforNumPy.test_linspace.<locals>.test_impl1c                 S   rK  rW   r   )r[  r\  numrS   rS   rT   rJ    r  z1TestParforNumPy.test_linspace.<locals>.test_impl2rO  rP  rQ  r   rp   r      rR  )rP   rG  rJ  rU  rS   rS   rT   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 rW   meanrP  rS   rS   rT   r    r  z,TestParforNumPy.test_mean.<locals>.test_impld   r   r   sizer   r.  r   c                      
     dS r  r   rS   rY   rS   rT   <lambda>     
 z+TestParforNumPy.test_mean.<locals>.<lambda>r   r   r!  randintr   r   r   r   r0  r(  r   r   )rP   r  rb  rP  r9  data_genrS   rY   rT   	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   r`  rW   )varrc  rS   rS   rT   r    r  z+TestParforNumPy.test_var.<locals>.test_implrd  r   r   re                ?r   r.  r   c                      rg  r  rh  rS   rY   rS   rT   ri    rj  z*TestParforNumPy.test_var.<locals>.<lambda>rk  )rP   r  rb  rP  r9  r.  rm  rS   rY   rT   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   r`  rW   )stdrc  rS   rS   rT   r    r  z+TestParforNumPy.test_std.<locals>.test_implrd  r   r   re  rp  r   r.  r   c                      rg  r  rh  rS   rY   rS   rT   ri    rj  z*TestParforNumPy.test_std.<locals>.<lambda>)r   r   r!  rl  r   r   r0  r(  r   r   r   r   )rP   r  rb  rP  r9  r.  argtyrm  rS   rY   rT   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 rW   )r   r   r!  rA  rS   rS   rT   r       z5TestParforNumPy.test_random_parfor.<locals>.test_implr   NrC  r  rS   rS   rT   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 Nre          r0  r   r   )highrf  r   )	r   r   standard_normalr   normal	chisquarerl  
triangularrM  r   rP  r9  r.  r]  EFrS   rS   rT   r    s   z/TestParforNumPy.test_randoms.<locals>.test_implrP  g?)rtolr   )r   r   r   r   r   r   assert_allcloser   r   r   r$  rP   r  r   r   r   	py_outputrS   rS   rT   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 rw  )r   r   rz  r   r{  r|  rl  r}  r~  rS   rS   rT   r    s   z4TestParforNumPy.test_dead_randoms.<locals>.test_implrP  r   )r   r   r   r   r   r   r   r$  r  rS   rS   rT   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   r`  rW   r=  rc  rS   rS   rT   rG  '  r  z,TestParforNumPy.test_min.<locals>.test_impl1c                 S   rE  rW   )r   r=  rc  rS   rS   rT   rJ  *  r  z,TestParforNumPy.test_min.<locals>.test_impl2   r   re  zDzero-size array to reduction operation minimum which has no identityr  c                      rg  r  rh  rS   rY   rS   rT   ri  E  rj  z*TestParforNumPy.test_min.<locals>.<lambda>r   r   r!  rl  astypeint32r_  infr   r   r   r$  r  r   r   r   r   r  r   r   rP   rG  rJ  r   rP  r9  r.  r]  r   r   pcfuncerm  rS   rY   rT   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   r`  rW   )r>  rc  rS   rS   rT   rG  L  r  z,TestParforNumPy.test_max.<locals>.test_impl1c                 S   rE  rW   )r   r>  rc  rS   rS   rT   rJ  O  r  z,TestParforNumPy.test_max.<locals>.test_impl2r  r   re  zDzero-size array to reduction operation maximum which has no identityr  c                      rg  r  rh  rS   rY   rS   rT   ri  j  rj  z*TestParforNumPy.test_max.<locals>.<lambda>r  r  rS   rY   rT   test_maxK  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   r`  rW   )r<  rc  rS   rS   rT   rG  q  r  z/TestParforNumPy.test_argmax.<locals>.test_impl1c                 S   rE  rW   )r   r<  rc  rS   rS   rT   rJ  t  r  z/TestParforNumPy.test_argmax.<locals>.test_impl2r  )r0  rx  r         @r  r   re  r0  rx  r  r  z*attempt to get argmax of an empty sequencer  c                      rg  r  rh  rS   rY   rS   rT   ri    rj  z-TestParforNumPy.test_argmax.<locals>.<lambda>r   r_  r   rl  r  r  r!  nanr   r   r   r$  r  r   r   r   r   r  r   r   r  rS   rY   rT   test_argmaxp  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   r`  rW   rX  rc  rS   rS   rT   rG    r  z/TestParforNumPy.test_argmin.<locals>.test_impl1c                 S   rE  rW   )r   rY  rc  rS   rS   rT   rJ    r  z/TestParforNumPy.test_argmin.<locals>.test_impl2r  )r0  rx  r  rx  r  r   re  r0  rx  r  z*attempt to get argmin of an empty sequencer  c                      rg  r  rh  rS   rY   rS   rT   ri    rj  z-TestParforNumPy.test_argmin.<locals>.<lambda>r  r  rS   rY   rT   test_argmin  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   rS   rS   rT   r       
z4TestParforNumPy.test_ndarray_fill.<locals>.test_implr   r   r.  r   zerosr   r   r0  r(  r   r   rP   r  r   rs  rS   rS   rT   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  rS   rS   rT   r    r  z6TestParforNumPy.test_ndarray_fill2d.<locals>.test_implr   r   r   r.  r   r  r  rS   rS   rT   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   rF   r   r  r(  rf  r   rv   rw   result_matrixsub_azresult_datarS   rS   rT   r       z<TestParforNumPy.test_reshape_with_neg_one.<locals>.test_implr0  r  r  r        @      @r  g       @g      "@      $@g      &@r  r   r   r_  r   rP   r  rv   rw   rS   rS   rT   test_reshape_with_neg_one     
z)TestParforNumPy.test_reshape_with_neg_onec                 C   r  )Nc                 S   r  )Nr   r  r   ir  r  rS   rS   rT   r    r  z>TestParforNumPy.test_reshape_with_large_neg.<locals>.test_implr  r   r  r  rS   rS   rT   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 )NTr   c                 S   s^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S r  r  )rv   rw   rmr  r  r  rS   rS   rT   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   r_  r   r   r  )rP   raisedr  rv   rw   r   rS   rS   rT   "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 rW   )r   rM  prodr=  r>  ro  r   rS   rS   rT   r    s   2z0TestParforNumPy.test_0d_array.<locals>.test_impl   Fr   )r   r   r_  r  rS   rS   rT   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 rK  )r   rM  realimag)r  rS   rS   rT   r    s   z6TestParforNumPy.test_real_imag_attr.<locals>.test_implrp   y      ?      ?r   )r   r  r   r   r   r   r  )rP   r  r  rS   rS   rT   test_real_imag_attr	  s   $z#TestParforNumPy.test_real_imag_attrN)rh   rK   ri   r.  r:   r7  r?  rD  rV  rZ  r_  rn  rq  rt  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  rS   rS   rS   rT   r4  y  s4    
	
%%$$		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  rW   r  r6  rS   rS   rT   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  )rP   r  r  rP  r  r   rS   rS   rT   #test_unsupported_combination_raises  s   
	z:TestParforsUnsupported.test_unsupported_combination_raisesN)	rh   rK   ri   r.  unittestskipIfr9   r:   r  rS   rS   rS   rT   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 ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPeQeRdd ZSdS )TestParforsz6 Tests cpython, reduction and various parfors featuresc                    s    dd }  | fdd d S )Nc                 S   s   | | | S rW   rS   )rv   r   r  rS   rS   rT   r  .  r[   z,TestParfors.test_arraymap.<locals>.test_implc                      rg  Nr   rh  rS   rY   rS   rT   ri  1  rj  z+TestParfors.test_arraymap.<locals>.<lambda>)r   r  rS   rY   rT   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   r_  r  rM  rG  rF  rS   rS   rT   r  4     

z0TestParfors.test_0d_broadcast.<locals>.test_implrS   r   r   r   r   r  rS   rS   rT   test_0d_broadcast3     
zTestParfors.test_0d_broadcastc                 C   r  )Nc                  S   s"   t d} t d}t | | S Nr  )r   r  r  rM  r  rS   rS   rT   r  <  r  z-TestParfors.test_2d_parfor.<locals>.test_implrS   r   r  r  rS   rS   rT   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  rS   rS   rT   case1D  s   

z)TestParfors.test_nd_parfor.<locals>.case1c                      s   t   dS rK  )r	   r   rS   r  rP   rS   rT   ri  I  s    z,TestParfors.test_nd_parfor.<locals>.<lambda>c                 S   s   t | | S rW   r[  r  rS   rS   rT   r  K  r  z-TestParfors.test_nd_parfor.<locals>.test_impl)r   r   )rP   rm  r  rS   r  rT   test_nd_parforC  s
   zTestParfors.test_nd_parforc                    s,   ddl m   fdd}d}| || d S )Nr   r  c                    s    | }|d S r  rS   rA  r  rS   rT   r  S  rB  z9TestParfors.test_np_func_direct_import.<locals>.test_implo   )r  r  r   rP   r  r   rS   r  rT   test_np_func_direct_importQ  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 rW   r8  )r  r   rP  r9  rS   rS   rT   r  Z  r  z2TestParfors.test_size_assertion.<locals>.test_implr   Tr   	   zSizes of A, B do not match)r   r  r  r
   r   r   r  )rP   r  r  r   r   rS   rS   rT   test_size_assertionY  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_positiverb  r   rO  rS   rS   rT   r  h  s   "z'TestParfors.test_cfg.<locals>.test_implrd  )r   r   randr  r   )rP   r  rb  r   r  rS   rS   rT   test_cfgf  s
   	
zTestParfors.test_cfgc                 C   sB  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d }| || | 	t
|tjd d  fd d S )Nc                 S   s   d}t dd | |S )Nr   c                 S   s
   t | |S rW   r  ru   rS   rS   rT   ri  y  rj  <TestParfors.test_reduce.<locals>.test_impl.<locals>.<lambda>r   )rP  init_valrS   rS   rT   r  w  s   z*TestParfors.test_reduce.<locals>.test_implr  r   re  c                  S   s   dd } t | tg ddS )Nc                 S   s   | d S rK  rS   r  rS   rS   rT   ri        r  r   r   r   r   rp   r   )r   r   r_  )grS   rS   rT   r    s      c                 S   s   t | | dk S r  r[  rc  rS   rS   rT   r    r   c                 S   s&   | d d df }t | |dkdf S )Nr   r   r   r[  rP  r9  rS   rS   rT   r    s   )   r   c                 S   s*   | d d df }t | |dkddf S )Nr   r   r   r   r[  r  rS   rS   rT   r    s   r   c                 S   s   t | }| | S rW   )r   amin)rP  min_valrS   rS   rT   r       
)r   r   r!  r   rl  r  r  assertTypingErrorr   r   r   r   r(  rP   r  r   rP  rS   rS   rT   test_reducev  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   cmathr2  accr   rS   rS   rT   r    s   z9TestParfors.test_use_of_reduction_var1.<locals>.test_implCUse of reduction variable acc in an unsupported reduction function.rS   r  r   r   r   r   r  rP   r  r   r  r  rS   rS   rT   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 Nrd  r   r   r  rS   rS   rT   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.rS   )r  r   NumbaValueErrorr   r   r   r  r  rS   rS   rT   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  rS   rS   rT   r    s   z4TestParfors.test_unsupported_xor1.<locals>.test_implr  rS   r  r  rS   rS   rT   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 rW   r8  rA  rS   rS   rT   r    r  z8TestParfors.test_parfor_array_access1.<locals>.test_implr  r   )r   r   r  r   r%  r  rS   rS   rT   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   rP  r  r   rS   rS   rT   r    s   
z8TestParfors.test_parfor_array_access2.<locals>.test_implr  r   r   r   r  r   r%  r  rS   rS   rT   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  rS   rS   rT   r    s   z8TestParfors.test_parfor_array_access3.<locals>.test_implr  z Overwrite of parallel loop index)r  r   r  r   r   r   r  )rP   r  r   r  rS   rS   rT   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  rW   r  )rP  rw   rS   rS   rT   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*  )rP   r  r   drP  rw   r  r  r  parfor_foundr  r  build_tuple_foundblrS   rS   rT   test_parfor_array_access4  sB   



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   )rv   r   rS   rS   rT   r  &  s   z5TestParfors.test_parfor_dtype_type.<locals>.test_implr   r  )rP   r  rv   rS   rS   rT   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   rM  r   rG  r  r   rS   rS   rT   r  0  s
   z8TestParfors.test_parfor_array_access5.<locals>.test_implr  r   r  r  rS   rS   rT   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   rS   rS   rT   r  >  s   z8TestParfors.test_parfor_hoist_setitem.<locals>.test_implr   r  )rP   r  r  rS   rS   rT   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   rE  )rb  r]  rH  rG  rF  r   r9  rS   rS   rT   r  I  s   

z8TestParfors.test_parfor_generate_fuse.<locals>.test_implr  r   r   )r   r   r  r   r%  r   )rP   r  r   r	  rS   rS   rT   test_parfor_generate_fuseF  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  rW   )r   bitwise_andr  rS   rS   rT   r  Z  r[   z.TestParfors.test_ufunc_expr.<locals>.test_implr   r   r   )r   r  uint8r   )rP   r  rP  r9  rS   rS   rT   test_ufunc_exprX  s
   zTestParfors.test_ufunc_exprc                 C   r@  )Nc                 S   s(   t | f}t| D ]}|d ||< q	|S )Nr  )unsafe_emptyr   r   rP  r   rS   rS   rT   r  c  s   
z;TestParfors.test_find_callname_intrinsic.<locals>.test_implr   )r   r  r   r%  r  rS   rS   rT   test_find_callname_intrinsicb  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   rS   rS   rT   r  o  s   

z7TestParfors.test_reduction_var_reuse.<locals>.test_implr  r  r  rS   rS   rT   test_reduction_var_reusem  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   r^  )rP  condrI  r   rS   rS   rT   r  |  s   z8TestParfors.test_non_identity_initial.<locals>.test_implr   boolr   r   r  r  r  rS   rS   rT   test_non_identity_initialz  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!  )rP  r"  rI  rM  r   rS   rS   rT   r    s   

z9TestParfors.test_if_not_else_reduction.<locals>.test_implr   r#  r$  r  rS   rS   rT   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   ro   r   r   r   r  int_r  r   r   r   r   shprf  result1tmpr   rS   rS   rT   r    s   

z?TestParfors.test_two_d_array_reduction_reuse.<locals>.test_implrd  r  r  rS   rS   rT    test_two_d_array_reduction_reuse  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   r_  )r   resultr   rS   rS   rT   r    s   z9TestParfors.test_one_d_array_reduction.<locals>.test_implrd  r  r  rS   rS   rT   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,  rS   rS   rT   r    s   
z9TestParfors.test_two_d_array_reduction.<locals>.test_implrd  r  r  rS   rS   rT   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   )r0  r  r  r  r  r  )r   r  rY  r_  r   r   r   r   r-  r.  r/  r   rS   rS   rT   r    s   
zJTestParfors.test_two_d_array_reduction_with_float_sizes.<locals>.test_implrd  r  r  rS   rS   rT   +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   r5  rS   rS   rT   r    s   
z>TestParfors.test_two_d_array_reduction_prod.<locals>.test_implrd  r  r  rS   rS   rT   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   rS   rS   rT   r    s
   z;TestParfors.test_three_d_array_reduction.<locals>.test_implrd  r  r  rS   rS   rT   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  )argsortrc  rS   rS   rT   r    r[   z>TestParfors.test_preparfor_canonicalize_kws.<locals>.test_implr  r   r  r   r  rS   rS   rT   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 rW   r  rc  rS   rS   rT   r    s   z8TestParfors.test_preparfor_datetime64.<locals>.test_implr   zdatetime64[ns])r   r  r  r   r   r   r   r   )rP   r  rP  r   rS   rS   rT   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   )r^  r   r  )rG  r   r  r   Rr/  r   rS   rS   rT   r    s   



zITestParfors.test_no_hoisting_with_member_function_call.<locals>.test_implrP  )r   r   r   r!  r  rS   rS   rT   *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+  rG  rS   rS   rT   r    s   z8TestParfors.test_array_compare_scalar.<locals>.test_implNr  r  rS   rS   rT   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   rM  )r   halfrf  parrrS   rS   rT   r    s
   z?TestParfors.test_array_analysis_optional_def.<locals>.test_implr  TFr  r  rP   r  r   rS   rS   rT    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 rW  )r   r  r   r(  r   r   )rv   rw   datarf  r   rS   rS   rT   r    s   z7TestParfors.test_prange_side_effects.<locals>.test_implrd  r  r   r.  )	r   r  floatr   r   r   r   r0  r(  )rP   r  r   r  rS   rS   rT   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   rv   atuprw   r   rS   rS   rT   r  0  s
   "z*TestParfors.test_tuple1.<locals>.test_implr   r<  rF  rS   rS   rT   test_tuple1/     
zTestParfors.test_tuple1c                 C   r  )Nc                 S   s:   | j }d}tt| D ]}| |  |d | 7  < q| S )Nr  r   )r^  r   r   r   rK  rS   rS   rT   r  ;  s
   z*TestParfors.test_tuple2.<locals>.test_implr   r<  rF  rS   rS   rT   test_tuple2:  rN  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   rp   r   )r   r  r   r   r   rK  rS   rS   rT   r  F  s
   &z*TestParfors.test_tuple3.<locals>.test_implr   r<  rF  rS   rS   rT   test_tuple3E  rN  zTestParfors.test_tuple3c                 C   r  )Nc                 S   sD   t ddd}d}tt| D ]}| |  |j|j | 7  < q| S Nr   r   rr   r  )rq   r   r   r   rs   rt   rv   antuprw   r   rS   rS   rT   r  Q  
   z/TestParfors.test_namedtuple1.<locals>.test_implr   r<  rF  rS   rS   rT   test_namedtuple1P  rN  zTestParfors.test_namedtuple1c                    s0   t dd  fdd}td}| || d S )NTestNamedTuple2rr   c                    sD    ddd}d}t t| D ]}| |  |j|j | 7  < q| S rQ  )r   r   r   rs   rt   rR  rV  rS   rT   r  ]  rT  z/TestParfors.test_namedtuple2.<locals>.test_implr   )r   r   r  r   rF  rS   rW  rT   test_namedtuple2[  s   

zTestParfors.test_namedtuple2c                 C   sB   t ddg}dd }dd }|tdd}| j|||gd	 d S )
NTestNamedTuple3r  c                 S   s   d| j d d < d S )Nrp   r  r  rS   rS   rT   r  l  r   z/TestParfors.test_namedtuple3.<locals>.test_implc                 S   s   t j| j|j d S rW   )r   r   r   r  ru   rS   rS   rT   r  o  r  z.TestParfors.test_namedtuple3.<locals>.comparerr   rZ  r  )r   r   r  r   )rP   rY  r  r  r   rS   rS   rT   test_namedtuple3g  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 rW   rS   ru   rS   rS   rT   r  v     z1TestParfors.test_inplace_binop.<locals>.test_implr   rd  r   r.  )r   r  r   r   r   r   r0  r(  rP   r  rG  rF  rS   rS   rT   test_inplace_binopu  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  rv   r   array_shapeindicesk_listr   r  rS   rS   rT   r    s   z0TestParfors.test_tuple_concat.<locals>.test_implr   r  rF  rS   rS   rT   test_tuple_concat  s   
zTestParfors.test_tuple_concatc                 C   r_  )Nc                 S   sb   t | }||f}tjd| d d d tjd}|dd d f }t| D ]
\}}||||f< q$|S )Nr  rF   r  r   r`  rb  rS   rS   rT   r    s   zCTestParfors.test_tuple_concat_with_reverse_slice.<locals>.test_implr   r  rF  rS   rS   rT   $test_tuple_concat_with_reverse_slice  s   z0TestParfors.test_tuple_concat_with_reverse_slicec                 C   r  )Nc                 S   s   | f| | f }|d   S r  rM  )rv   SrS   rS   rT   r    s   z6TestParfors.test_array_tuple_concat.<locals>.test_implr   r   r  rF  rS   rS   rT   test_array_tuple_concat  s   
z#TestParfors.test_array_tuple_concatc                 C   r  )Nc                 S   s   | d S )Nr  rS   r  rS   rS   rT   r    r  z3TestParfors.test_high_dimension1.<locals>.test_impl)r   r   r   r   r      r  rF  rS   rS   rT   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   rS   rS   rT   r       
z-TestParfors.test_tuple_arg.<locals>.test_implr   rp   )r   r   r  rP   r  rs  rS   rS   rT   test_tuple_arg     zTestParfors.test_tuple_argc                 C   $   dd }d}|  |t|d d S )Nc                 S   ro  r  rp  rr  rS   rS   rT   r    rt  z=TestParfors.test_tuple_arg_not_whole_array.<locals>.test_implru  r   r   r   r   r  rv  rS   rS   rT   test_tuple_arg_not_whole_array  rx  z*TestParfors.test_tuple_arg_not_whole_arrayc                 C   "   dd }d}|  |t| d S )Nc                 S       d}t |D ]}d| |< q| S )Nru  r   rp  rr  rS   rS   rT   r       
z6TestParfors.test_tuple_for_pndindex.<locals>.test_implru  r{  rv  rS   rS   rT   test_tuple_for_pndindex     z#TestParfors.test_tuple_for_pndindexc                 C   ry  )Nc                 S   s$   |df}t |D ]}d| |< q	| S r'  rp  )r   firstrs  r   rS   rS   rT   r    s   
z5TestParfors.test_tuple_arg_literal.<locals>.test_implru  r   r{  rv  rS   rS   rT   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   ro  r  rp  rr  rS   rS   rT   r    rt  z?TestParfors.test_tuple_of_literal_nonliteral.<locals>.test_implc                 S   s
   || dS )Nrz  rS   )r   r	  rS   rS   rT   r!    r  z:TestParfors.test_tuple_of_literal_nonliteral.<locals>.callc                   S   r  )Nr  r   r  rS   rS   rS   rT   ri    rj  z>TestParfors.test_tuple_of_literal_nonliteral.<locals>.<lambda>c                    s,   | }t  }| |}| d S rW   )r
   assertPreciseEqual)decf1f2gotr!  expected	get_inputrP   r  rS   rT   r     s   z;TestParfors.test_tuple_of_literal_nonliteral.<locals>.checkTr   r
   )rP   r   r	  rS   r  rT    test_tuple_of_literal_nonliteral  s   
z,TestParfors.test_tuple_of_literal_nonliteralc                 C   rn  )Nc                 S   ro  r  rp  rr  rS   rS   rT   r    rt  z0TestParfors.test_tuple_arg_1d.<locals>.test_implr   r{  rv  rS   rS   rT   test_tuple_arg_1d  rx  zTestParfors.test_tuple_arg_1dc                 C   r}  )Nc                 S   r~  Nr  r   rp  rr  rS   rS   rT   r    r  z8TestParfors.test_tuple_arg_1d_literal.<locals>.test_implr  r{  rv  rS   rS   rT   test_tuple_arg_1d_literal  r  z%TestParfors.test_tuple_arg_1d_literalc                 C       dd }|  |tdd d S )Nc                 S   ro  r  rp  rr  rS   rS   rT   r    rt  z4TestParfors.test_int_arg_pndindex.<locals>.test_implr  r   r{  r  rS   rS   rT   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   rS  )ur   evenrf  rO  rS   rS   rT   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  rf  r   r  rS   rT   r  
  s
   z8TestParfors.test_prange_unknown_call1.<locals>.test_implr   r   r   )
r@   r   r  r   r(  r   r$  r   r   r   rP   r  rf  r  cptypesrS   r  rT   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  rf  r   rO  rS   rS   rT   r    s    z6TestParfors.test_prange_index_calc1.<locals>.test_implr   r   r   	r   r  r   r(  r   r$  r   r   r   r  rS   rS   rT   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  )rv   rw   rf  r   rO  rS   rS   rT   r  ,  s   z9TestParfors.test_prange_reverse_order1.<locals>.test_implr   r   r   r  rP   r  rf  rv   rw   r  rS   rS   rT   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   rp   r  )rv   rf  rw   r   rS   rS   rT   r  ?  s   
z@TestParfors.test_prange_parfor_index_then_not.<locals>.test_implr   r   r  )rP   r  rf  rv   r  rS   rS   rT   !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  )rv   tuprf  r  r   rS   rS   rT   r  P  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  rS   rS   rT   +test_prange_parfor_index_const_tuple_fusionM  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 )Nrp   r   r  )rv   rw   rf  r   rS   rS   rT   r  d  s   
zITestParfors.test_prange_non_parfor_index_then_opposite.<locals>.test_implr   r   r  r  rS   rS   rT   *test_prange_non_parfor_index_then_oppositea  s   	

 z6TestParfors.test_prange_non_parfor_index_then_oppositec                 C   sF   ddd}t d}| j||d t jjdd gd | | d d S )	Nc                 S   s"   t dD ]
}|d urd| |< qd S )Nr   rx  r  )arrpredr   rS   rS   rT   r  u  s
   z3TestParfors.test_prange_optional.<locals>.test_implr   c                 S   s   | |kS rW   rS   r   r  rS   rS   rT   ri  }  r  z2TestParfors.test_prange_optional.<locals>.<lambda>r  r  rW   )r   r  r   r   r   r   rM  rP   r  r  rS   rS   rT   test_prange_optionalt  s   


z TestParfors.test_prange_optionalc                 C   r  )Nc                  S   s   d} | d S )Ng333333?g?r   rS   r  rS   rS   rT   r    s   z8TestParfors.test_untraced_value_tuple.<locals>.test_implr  r  r  rS   rS   rT   test_untraced_value_tuple  
   z%TestParfors.test_untraced_value_tuplec                 C   r  )Nc                  S   s   d} | d d S )N)r  r   rS   r  rS   rS   rT   r    s   zBTestParfors.test_recursive_untraced_value_tuple.<locals>.test_implr  r  r  rS   rS   rT   #test_recursive_untraced_value_tuple  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   rx  r   r   r  r(  r   )r  rv   n1arr2r   n2arr3rO  totaln3r   rS   rS   rT   r    s   z9TestParfors.test_untraced_value_parfor.<locals>.test_implr   r.  r   r  )r   r0  r$  r   r   r   r  r   )rP   r  rU  r  rS   rS   rT   test_untraced_value_parfor  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   r^  )r   r&  r   rS   rS   rT   r    s   
z;TestParfors.test_setitem_2d_one_replaced.<locals>.test_impl)r   r   r{  r  rS   rS   rT   test_setitem_2d_one_replaced  s   
z(TestParfors.test_setitem_2d_one_replacedc                 C   sF   dd }t d}| ||dd | ||dd | ||dd d S )Nc                 S   s@   t | j}|r|t jS |r|| }n||d  }|| j S r  )r   r  rf  r  r(  )r  flag1flag2invr  rS   rS   rT   r    s   

z7TestParfors.test_1array_control_flow.<locals>.test_implrd  TFr<  r  rS   rS   rT   test_1array_control_flow  s
   

z$TestParfors.test_1array_control_flowc                 C   6   dd }t d}| ||dd | ||dd d S )Nc                 S   sF   t | j}t || j| }|r|| }|| S ||d  }|| S r  r   r  rf  )r  rc  flaginv1inv2r  rS   rS   rT   r    s   z9TestParfors.test_2array_1_control_flow.<locals>.test_implrd  r   TFr<  r  rS   rS   rT   test_2array_1_control_flow  s   
	z&TestParfors.test_2array_1_control_flowc                 C   r  )Nc                 S   sZ   t | j}t || j| }|r|| }|| }|| S ||d  }||d  }|| S r  r  )r  rc  r  r  r  ret1ret2rS   rS   rT   r    s   z9TestParfors.test_2array_2_control_flow.<locals>.test_implrd  r   TFr<  r  rS   rS   rT   test_2array_2_control_flow  s   
z&TestParfors.test_2array_2_control_flowc                 C   s.   dd }|  |d | t|tjfd d S )Nc                 S   s   t j| t jd}t j| t jd}t| D ]}t|D ]
}||  d7  < qqt| D ]}|dkr1q*|| ||d   ||< q*|dd  S )Nr  r   r   )r   r  r%  r   r   )r   rcr   rO  rS   rS   rT   r    s   z-TestParfors.test_issue8515.<locals>.test_implrl  r   )r   r   r   r   r$  r  rS   rS   rT   test_issue8515  s   zTestParfors.test_issue8515c                 C      dd }|  |dd d S )Nc                 S   s   d}d}t ||f}t|D ]/}t|D ](}t |}|d }t |}	t| |D ]}
d|	|
< q*|	d }|| |||f< qq|S )Nr^  r   r   r   )r   r  r   r  r   )i1i2rb  ri  rv   r  r   r  r  p2r   rO  rS   rS   rT   r  	  s   



z-TestParfors.test_issue9029.<locals>.test_implr   r   r  r  rS   rS   rT   test_issue9029  s   zTestParfors.test_issue9029c                 C   s4   dd }|  |dd | t|tjtjfd d S )Nc                 S   s8   t d}t|}t d}tt| |}|| | S Nrd  )r   r  rL  ceilintr>  )rv   rw   rG  rF  r  rS   rS   rT   r  	  s
   


z:TestParfors.test_fusion_no_side_effects.<locals>.test_implg@g333333@r   )r   r   r   r   r(  r  rS   rS   rT   test_fusion_no_side_effects	  s   z'TestParfors.test_fusion_no_side_effectsc                 C   s,   t dddd }| |d|d d S )NTr   c                 S   s"   d}t d t| D ]}|}q
|S r  r   r   )r   r  r   rS   rS   rT   def_in_loop%	  s
   zCTestParfors.test_issue9256_lower_sroa_conflict.<locals>.def_in_loopr   r
   r   py_func)rP   r  rS   rS   rT   "test_issue9256_lower_sroa_conflict$	  s   
z.TestParfors.test_issue9256_lower_sroa_conflictc                 C   H   dd }|d}|  |tdd|d |  |tdd|d d S )Nc                 S   s2   | }t d t| D ]}|r| d }q
||dkfS Nr   r   r   r  )r   r  _ir	  rS   rS   rT   r  0	  s   zLTestParfors.test_issue9256_lower_sroa_conflict_variant1.<locals>.def_in_loopr   Fr   Tr   r
   rP   r  r  rS   rS   rT   +test_issue9256_lower_sroa_conflict_variant1/	  s   z7TestParfors.test_issue9256_lower_sroa_conflict_variant1c                 C   r  )Nc                 S   s@   | }t d t| D ]}|rt| D ]}| d }qq
||dkfS r  )r   r   r   )r   r  r  _jr	  rS   rS   rT   r  =	  s   
zLTestParfors.test_issue9256_lower_sroa_conflict_variant2.<locals>.def_in_loopr   Fr   Tr  r  rS   rS   rT   +test_issue9256_lower_sroa_conflict_variant2<	  s   	z7TestParfors.test_issue9256_lower_sroa_conflict_variant2c              
   C   s|   t jddg}i tjddd}ztj||tjdd W d S  tjy= } zd|j }| j	|d W Y d }~d S d }~ww )	Nz-mz"numba.tests.parfor_iss9490_usecase1)PYTHONHASHSEEDNUMBA_NUM_THREADSzutf-8)envstderrencodingzsubprocess failed with output:
)r   )
sys
executableosenvironsubpcheck_outputSTDOUTCalledProcessErroroutputfail)rP   cmdenvsr  r   rS   rS   rT   "test_issue9490_non_det_ssa_problemJ	  s(   z.TestParfors.test_issue9490_non_det_ssa_problemN)Trh   rK   ri   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  r2  r4  r6  r8  r9  r=  r>  r@  rC  rG  rJ  rM  rO  rP  rU  rX  r[  r^  rf  rg  rk  rm  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  r  r;   r?   r  rS   rS   rS   rT   r  )  s    0
&





						


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 rW   r   r   rS   rS   rT   r   g	      zTestParforsLeaks.checkc                 C   *   dd }t dt j}| || d S )Nc                 S   r`  rW   rh  )r  rS   rS   rT   r  m	  r  z2TestParforsLeaks.test_reduction.<locals>.test_implr   r   r  r  r(  r   r  rS   rS   rT   test_reductionk	  s   zTestParforsLeaks.test_reductionc                 C   r  )Nc                 S   s@   d}d}t | jD ]}|| | 7 }|d| | d  7 }q	|| S )Nrx  r0  r   )r   rf  )r  rv   rw   r   rS   rS   rT   r  u	  s   z@TestParforsLeaks.test_multiple_reduction_vars.<locals>.test_implr   r  r  rS   rS   rT   test_multiple_reduction_varss	  s   z-TestParforsLeaks.test_multiple_reduction_varsN)rh   rK   ri   r   r  r  rS   rS   rS   rT   r  e	  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   r^  rv   r   rw   rS   rS   rT   r  	      z6TestParforsSlice.test_parfor_slice1.<locals>.test_implr   r   r   r  r  rS   rS   rT   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  rv   r  r   rw   rS   rS   rT   r  	  s   z6TestParforsSlice.test_parfor_slice2.<locals>.test_implr   r  Tr   do not match	r   r   r  r  r  r
   r   r   r  r  rS   rS   rT   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  rS   rS   rT   r  	  s   
0z6TestParforsSlice.test_parfor_slice3.<locals>.test_implr   r   r   r  rS   rS   rT   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  rS   rS   rT   r  	     
,z6TestParforsSlice.test_parfor_slice4.<locals>.test_implr  r   r  rS   rS   rT   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  rS   rS   rT   r  	  r	  z6TestParforsSlice.test_parfor_slice5.<locals>.test_implr  r   r  rS   rS   rT   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rv   rw   r  rS   rS   rT   r  	  r  z6TestParforsSlice.test_parfor_slice6.<locals>.test_implr  r   r  rS   rS   rT   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  rS   rS   rT   r  	  r  z6TestParforsSlice.test_parfor_slice7.<locals>.test_implrj  Tr   r  r  r  r  rS   rS   rT   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  r^  r  r  rS   rS   rT   r  	     
$z6TestParforsSlice.test_parfor_slice8.<locals>.test_implr  rj  r   r   r  r   r  rS   rS   rT   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  rS   rS   rT   r  	  r  z6TestParforsSlice.test_parfor_slice9.<locals>.test_implr  r  r  r  rS   rS   rT   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  rS   rS   rT   r  	     
z7TestParforsSlice.test_parfor_slice10.<locals>.test_implr  rj  r  r  rS   rS   rT   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+  r^  r   )rv   r  r   rc  rw   rS   rS   rT   r  	  s   (z7TestParforsSlice.test_parfor_slice11.<locals>.test_impl   )r   r   r   r  r  rS   rS   rT   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   rF   r  r  rS   rS   rT   r  	  r  z7TestParforsSlice.test_parfor_slice12.<locals>.test_implr  r  r  r  rS   rS   rT   test_parfor_slice12	  r  z$TestParforsSlice.test_parfor_slice12c                 C   r  )Nc                 S   s<   | j \}}|  }d}| d| |d f |dd|f< |S )NrF   r   r   r  )rv   r  r   rw   r  rS   rS   rT   r  	  s
   
"z7TestParforsSlice.test_parfor_slice13.<locals>.test_implr  r  r  r  rS   rS   rT   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   rF   r  r  rS   rS   rT   r   
  r  z7TestParforsSlice.test_parfor_slice14.<locals>.test_implr  r  r  r  rS   rS   rT   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  rS   rS   rT   r  	
  s   
"z7TestParforsSlice.test_parfor_slice15.<locals>.test_implr  r  r  r  rS   rS   rT   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  )rv   rw   r   rS   rS   rT   r  
  s   z7TestParforsSlice.test_parfor_slice16.<locals>.test_implr      Nr   )	r   r   r  r  r   r(  r$  r   r   rP   r  r   rS   rS   rT   test_parfor_slice16
  s    z$TestParforsSlice.test_parfor_slice16c                 C   s    dd }|  |dtd d S )Nc                 S   s$   t | }t|}||| d < |S rW   r   r  r   )r  rP  r9  r   rS   rS   rT   r  "
  s   
z7TestParforsSlice.test_parfor_slice17.<locals>.test_implr   r   r  rS   rS   rT   test_parfor_slice17!
  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  )rv   r  rS   rS   rT   r  ,
  s   
z7TestParforsSlice.test_parfor_slice18.<locals>.test_implr  r  rS   rS   rT   test_parfor_slice18*
  s   z$TestParforsSlice.test_parfor_slice18c                 C   r  )Nc                 S   s   | d d  d7  < | S r  rS   rB  rS   rS   rT   r  6
     z7TestParforsSlice.test_parfor_slice19.<locals>.test_implr   r   r  rS   rS   rT   test_parfor_slice194
     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   )rv   r  rI  rS   rS   rT   r  >
  s   
z7TestParforsSlice.test_parfor_slice20.<locals>.test_implFr  r  r  rS   rS   rT   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   rF   )r   rf  )x1x2rS   rS   rT   r  G
  s   z7TestParforsSlice.test_parfor_slice21.<locals>.test_implrp   r   )r   r   r  r   rP   r  r/  r0  rS   rS   rT   test_parfor_slice21F
  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/  r0  rw   r   rS   rS   rT   r  Q
  s   
z7TestParforsSlice.test_parfor_slice22.<locals>.test_impl)r   r  r   )r   r  r_  r   r1  rS   rS   rT   test_parfor_slice22P
  s   

z$TestParforsSlice.test_parfor_slice22c                 C   r  )Nc                 S   s   d| d d< | S )Nr   r   rS   r  rS   rS   rT   r  ]
     z7TestParforsSlice.test_parfor_slice23.<locals>.test_implr   r   r  rS   rS   rT   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 rW   r(  r  rP  r   r9  r.  rS   rS   rT   r  d
     
z7TestParforsSlice.test_parfor_slice24.<locals>.test_implrl  r   r   r   r   r  rP   r  r   rS   rS   rT   test_parfor_slice24c
     z$TestParforsSlice.test_parfor_slice24c                 C   r6  )Nc                 S   s*   t | }|d | }|d t| }|S rW   r(  r7  rS   rS   rT   r  n
  r8  z7TestParforsSlice.test_parfor_slice25.<locals>.test_implr9  rl  r   r:  r;  rS   rS   rT   test_parfor_slice25m
  r=  z$TestParforsSlice.test_parfor_slice25c                 C   r  )Nc                 S   s.   | j \}|  }| dd ||d  d < |S )Nr!  r   r   r  r  rS   rS   rT   r  x
  s   z7TestParforsSlice.test_parfor_slice26.<locals>.test_implr   r   r   r  r  rS   rS   rT   test_parfor_slice26w
  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!  )rv   n_valid_valsr   unusedrS   rS   rT   r  
  s   z7TestParforsSlice.test_parfor_slice27.<locals>.test_implr   r?  r  rS   rS   rT   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   rF   r  c                    sD   t | d | df}d}t| D ]}||| f  7 }q|S Nr   r   )r   r  r   r   r   rM  r  tsrS   rT   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   r^  rM  )rG  r  r   rE  rS   rT   r  
  s   )slicer   r   r  r   rP   r  r   rG  rS   rE  rT   $test_parfor_array_access_lower_slice
  s   z5TestParforsSlice.test_parfor_array_access_lower_sliceN) rh   rK   ri   r  r  r  r
  r  r  r  r<   r  r  r  r  r  r   r"  r#  r'  r)  r*  r,  r.  r2  r3  r5  r<  r>  r@  rC  rI  rS   rS   rS   rT   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   rS   rS   r   rS   rS   rT   r   
  r   zMTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<listcomp>c                 S   s   | | S rW   rS   r  rS   rS   rT   ri  
  r  zKTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<lambda>)r^  r   r  r_  r   r   r   )rv   r   rw   r  r   rS   rS   rT   r  
  s   

z9TestParforsOptions.test_parfor_options.<locals>.test_implr   r   F)fusionr   )rK  comprehensionrp   )rK  rL  setitemr   )rK  rL  rM  r   r   )rK  rL  rM  r   	reductionr   )rK  rL  rM  r   rN  r  r   )r   r   r  r   r(  r   r   r&  rS   rS   rT   test_parfor_options
  s@   	z&TestParforsOptions.test_parfor_optionsN)rh   rK   ri   rO  rS   rS   rS   rT   rJ  
  s    rJ  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  rS   r  rS   rS   rT   r  
  s   z:TestParforsBitMask.test_parfor_bitmask1.<locals>.test_implr   rp   r?  r  rS   rS   rT   test_parfor_bitmask1
  s   z'TestParforsBitMask.test_parfor_bitmask1c                 C   ,   dd }t d}|dk}| ||| d S )Nc                 S   s   d| |< | S r  rS   ru   rS   rS   rT   r  
  r\  z:TestParforsBitMask.test_parfor_bitmask2.<locals>.test_implr   rp   r<  r  rS   rS   rT   test_parfor_bitmask2
     
z'TestParforsBitMask.test_parfor_bitmask2c                 C   rR  )Nc                 S   s   | | | |< | S rW   rS   ru   rS   rS   rT   r  
  r4  z:TestParforsBitMask.test_parfor_bitmask3.<locals>.test_implr   rp   r<  r  rS   rS   rT   test_parfor_bitmask3
  rT  z'TestParforsBitMask.test_parfor_bitmask3c                 C   rR  )Nc                 S   s   d|  | | |< | S rK  rS   ru   rS   rS   rT   r  
  ru  z:TestParforsBitMask.test_parfor_bitmask4.<locals>.test_implr   rp   r<  r  rS   rS   rT   test_parfor_bitmask4
  rT  z'TestParforsBitMask.test_parfor_bitmask4c                 C   rR  )Nc                 S   s   | | | |  | |< | S rW   rS   ru   rS   rS   rT   r  
  r+  z:TestParforsBitMask.test_parfor_bitmask5.<locals>.test_implr   rp   r<  r  rS   rS   rT   test_parfor_bitmask5
  rT  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 rW   rS   r  rS   rS   rT   r     r\  z:TestParforsBitMask.test_parfor_bitmask6.<locals>.test_implr   rp   r  )
r   r  r  rM  r  r  r   r   r   r  )rP   r  rv   rw   r  r  rS   rS   rT   test_parfor_bitmask6
  s   
z'TestParforsBitMask.test_parfor_bitmask6N)	rh   rK   ri   rQ  rS  rU  rV  rW  rX  rS   rS   rS   rT   rP  
  s    				rP  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d0d1 Zd2d3 Zd4d5 Zd6S )7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 r  )r   r  r   rf  )r  r   rS   rS   rT   r     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categoryra  r   c                 S   s   g | ]}|j jqS rS   )r   has_dynamic_globals)r   r   rS   rS   rT   r   +  s    z=TestParforsMisc.test_no_warn_if_cache_set.<locals>.<listcomp>F)r
   warningscatch_warningssimplefilterfilterwarningsr   r   NumbaWarningr   r   rz   r  )rP   r   r   raised_warningsrd  rS   rS   rT   test_no_warn_if_cache_set  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  rS   rS   rT   r   0  s
   
zITestParforsMisc.test_statement_reordering_respects_aliasing.<locals>.implrS   z	a[3]: 2.0)r   r3   r   getvaluer  r   )rP   r   r   stdoutlinerS   rS   rT   +test_statement_reordering_respects_aliasing/  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  rW   )r   isinfrc  rS   rS   rT   r  >  r  z;TestParforsMisc.test_parfor_ufunc_typing.<locals>.test_implrx  Tr   )
r   r_  r  r
   r   r  r  sequential_parfor_loweringr   assert_array_equal)rP   r  rP  r   old_seq_flagrS   rS   rT   test_parfor_ufunc_typing=  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  rp   r   )r   r  r  init_pranger   )resr  dummyr   rS   rS   rT   r  N  s   z6TestParforsMisc.test_init_block_dce.<locals>.test_implrS   r   )r   r  r  rS   rS   rT   test_init_block_dceL  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  rG   rH  rS   rS   rT   r  Z  s
   
zBTestParforsMisc.test_alias_analysis_for_parfor1.<locals>.test_implr  r  rS   rS   rT   test_alias_analysis_for_parfor1Y  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 rW   )r0   r  rY   rS   rS   rT   r  o  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  rW   )r   LoweringError)rP   otherr|  rS   rT   
difference~  r  zzTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Broken.differenceN)rh   rK   ri   r  rS   r  rS   rT   Broken|      r  T)rf  r  r  r  r   r   r  r  r  r   races)rP   rv  blkr  r  r  rS   rT   run_passr  s   
z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_passN)rh   rK   ri   _namer  r  rS   r  rS   rT   BreakParforsk  s    r  c                       r  )z^TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompilerc                    s&   t | j}| t |  |gS rW   )r.   define_nopython_pipelinerv  add_pass_afterr1   finalize)rP   pmr  rS   rT   define_pipelines  s   zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompiler.define_pipelinesN)rh   rK   ri   r  rS   r  rS   rT   BreakParforsCompiler  r  r  )r   pipeline_classc                  S   s   d} t dD ]}| d7 } q| S r  r  )r   rG   rS   rS   rT   foo  s   
zMTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.foo)r/   r0   r-   r
   assertFalser   r  r  rr  r  r   r  r   r   r  )rP   r  r  r  rS   )r|  r  rT   0test_no_state_change_in_gufunc_lowering_on_errord  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rh   rK   ri   rS   rS   rS   rT   	DummyType      r  my_dummyc                   @   r  )z.TestParforsMisc.test_issue_5098.<locals>.DummyNr  rS   rS   rS   rT   Dummy  r  r  c                    s    S rW   rS   )valr  )
dummy_typerS   rT   typeof_Dummy     z5TestParforsMisc.test_issue_5098.<locals>.typeof_Dummyc                 S   s   t |j S rW   )r!   contextget_dummy_value)typobjr  rS   rS   rT   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 rW   )r   r   r  rq  )rv   fr  rS   rS   rT   baz  s   zPTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foo.<locals>.bazr  r   r  )r  r  r{   r  length
output_arrr   rS   rS   rT   _foo  s   zCTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foorS   )r  r  r{   r  rS   rS   rT   _get_method1  s   z5TestParforsMisc.test_issue_5098.<locals>._get_method1c                 S   r`  rW   ra  )r  rS   rS   rT   bar     z,TestParforsMisc.test_issue_5098.<locals>.barc                    s   |  tg dg dg S )Nr0  r  r  )r  r  r  )r  r   r_  )r	  )r  rS   rT   test1  s   z.TestParforsMisc.test_issue_5098.<locals>.test1)r   Opaquer   r"   OpaqueModelobjectr   registerr    r   r
   r   r  r  rr  r  )rP   r  r  r  r  r  r  
save_staterS   )r  r  rT   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   rS   rS   rT   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
   r5   r  r   r  r   r  r   )rP   r  r  errstrrS   rS   rT   %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   fullr^  r  r   )img_nirimg_red	fillvalueout_imgdimsr  r   rS   rS   rT   	ndvi_njit  s   z1TestParforsMisc.test_issue5167.<locals>.ndvi_njit)r   r   r0  g     @)lowry  rf  )r   r   uniformr   )rP   r  
tile_shapearray1array2rS   rS   rT   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  r^  rY  r   r   )rv   rZ  	dist_argsr1  r   rO  r	  rS   rS   rT   
reproducer  s    z2TestParforsMisc.test_issue5065.<locals>.reproducerc                 S   s:   d}t | jd D ]}|| | ||  d 7 }q	t|S )Nrx  r   r   )r   r^  r   r2  )r   r  r1  r   rS   rS   rT   	euclidean  s   
z1TestParforsMisc.test_issue5065.<locals>.euclidean)rp   r   re  Tr   rS   )r
   r   r   r   r   r  )rP   r  r  rv   r  r  rS   rS   rT   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   )myarrayr1  r   rS   rS   rT   test_numba_parallel  s   z;TestParforsMisc.test_issue5001.<locals>.test_numba_parallelrd  2   )r   r  r   )rP   r  r  rS   rS   rT   test_issue5001  s   zTestParforsMisc.test_issue5001c                    s6   t dd  t dd fdd}|dgfd  d S )	Nc                 S      d S rW   rS   )gridsrS   rS   rT   r    r  z+TestParforsMisc.test_issue3169.<locals>.fooTr   c                    s   t dD ]} |  qd S r  r  )r  r   r  rS   rT   r  "  s   
z+TestParforsMisc.test_issue3169.<locals>.barr   r   r  )rP   r  rS   r  rT   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mytyperu   c                    s   t dD ]} ||  q| jS r  )r   rv   )mydatar   innerrS   rT   outer/  s   z-TestParforsMisc.test_issue4846.<locals>.outerT)nogilc                 S   s   | |j f}| |jf}d S rW   ru   )r   r  r  r  rS   rS   rT   r  4  s   
z-TestParforsMisc.test_issue4846.<locals>.innerrv   rw   )r   r
   r   )rP   r  r  r  rS   r  rT   test_issue4846*  s   

zTestParforsMisc.test_issue4846c                 C   r  )Nc                  S   s*   d} d}t t| D ]}|| | 7 }q
|S )Nr  r   r   r   )r   rv   r   rS   rS   rT   test1b?  s
   z.TestParforsMisc.test_issue3748.<locals>.test1br  )rP   r  rS   rS   rT   test_issue3748=  s   zTestParforsMisc.test_issue3748c                 C   s,   dd }d}t j|td}| ||| d S )Nc                 S   s<   t | d D ]}t | d D ]}|d | || |< qq|S )Nr   r   g      @r  )rf  r  r   r  rS   rS   rT   parallel_testJ  s
   z5TestParforsMisc.test_issue5277.<locals>.parallel_testr  r  )r   r  r  r   )rP   r  rf  r  rS   rS   rT   test_issue5277H  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   rO  rS   rS   rT   r  V  s   z5TestParforsMisc.test_issue5570_ssa_races.<locals>.foo)rp   rp   9   r  )r
   r   r  r  r  )rP   r  r   r  r  rS   rS   rT   test_issue5570_ssa_racesU  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_stackrS   rS   rT   find_maxima_3D_jiti  s   
zDTestParforsMisc.test_issue6095_numpy_max.<locals>.find_maxima_3D_jitr   )r   r   r   )r
   r   r   r/  r  r  )rP   r  r   rS   rS   rT   test_issue6095_numpy_maxh  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  )r^  r   )gggg_nextgsr	  i_ggrS   rS   rT   r  z  s   z3TestParforsMisc.test_issue5942_1.<locals>.test_implr   r   r  )r   r  r  r   )rP   r  r	  r   r  r  rS   rS   rT   test_issue5942_1w  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   rS   rS   rT   r    s   z3TestParforsMisc.test_issue5942_2.<locals>.test_implr   r   r  )rP   r  r	  r   rS   rS   rT   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   rF   )r   r^  r   r  r_  rY  r  norm)r  r   rZ  trr   dist_trS   rS   rT   r    s   z)TestParforsMisc.test_issue6102.<locals>.f)rx  rx  rx  )rx  rx  r0  )r
   r   r_  r  r  )rP   r  r  rS   rS   rT   test_issue6102  s   
zTestParforsMisc.test_issue6102c                 C   r  )Nc                  S   sP   d} t | f}t | d f}tt|D ]}t |||d  ||< q|S r'  )r   r  r  r   r   rM  )r   na_maskr1  r   rS   rS   rT   r    s   z1TestParforsMisc.test_issue6774.<locals>.test_implr  r  rS   rS   rT   test_issue6774  s   zTestParforsMisc.test_issue6774c                 C   r  )Nc                  S   s   t ttf} | S rW   )r   r  _GLOBAL_INT_FOR_TESTING1_GLOBAL_INT_FOR_TESTING2bufrS   rS   rT   r       z9TestParforsMisc.test_issue4963_globals.<locals>.test_implr  r  rS   rS   rT   test_issue4963_globals  s   z&TestParforsMisc.test_issue4963_globalsc                    s$   d d fdd}|  | d S )Nro   rp   c                     s   t  f} | S rW   r  r  _FREEVAR_INT_FOR_TESTING1_FREEVAR_INT_FOR_TESTING2rS   rT   r    r  z:TestParforsMisc.test_issue4963_freevars.<locals>.test_implr  r  rS   r  rT   test_issue4963_freevars  s   z'TestParforsMisc.test_issue4963_freevarsc                    sd   ddl m}m}m} tjdd  tjddd fdd	}|||||||g||f d S )
Nr   )ListTypeTupler%  c                 S   r  rW   rS   r  rS   rS   rT   _sink  r  z>TestParforsMisc.test_issue_9182_recursion_error.<locals>._sinkFT)rZ  r   c                    s   t t|D ];}| D ]6}|d }|d }|dkr|d }nt|dkr-|d |d }}nt|dkr4	 |dkr@ |  | q
qd S )Nr   r   r   r   r  )clausesnodespiterclauseclause_typeclause_variablesclause_var_1clause_var_2r  rS   rT   _ground_node_rule  s$   
zJTestParforsMisc.test_issue_9182_recursion_error.<locals>._ground_node_rule)numba.typesr  r  r%  r   r
   compile)rP   r  r  r%  r  rS   r  rT   test_issue_9182_recursion_error  s   
z/TestParforsMisc.test_issue_9182_recursion_errorc                 C   s(   t dddd }| | |  d S )NTr   c                  S   s:   d} t dD ]}tdD ]}tdD ]}| d7 } qqq| S r  r  )r  r   r   rO  rS   rS   rT   r    s   
z8TestParforsMisc.test_lookup_cycle_detection.<locals>.foor  )rP   r  rS   rS   rT   test_lookup_cycle_detection  s   

z+TestParforsMisc.test_lookup_cycle_detectionc                 C   sD   dd }d}t jdd|}t jdd|}| |||| d S )Nc                 S   sT   d}t | D ] }t |}|di}tdD ]
}||  d7  < q||| 7 }q|S )Nr   rx  rp   r   )r   r   r$  r   )	num_nodesr  
inode_uintinodeprG   rS   rS   rT   
issue_9678  s   
z=TestParforsMisc.test_issue_9678_build_map.<locals>.issue_9678r  Fr   T)r   jitr   )rP   r  r  issue_9678_serialissue_9678_parallelrS   rS   rT   test_issue_9678_build_map  s   

z)TestParforsMisc.test_issue_9678_build_mapN) rh   rK   ri   r.  rk  rp  ru  ry  r{  r  r  r  r  r  r  r  r<   r  r  r  r  r  r  r  r=   r  r  r  r  r  r  r  rS   rS   rS   rT   rY    s<    <5

'rY  c                   @   s|   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d ZdS )TestParforsDiagnosticsc                 O   r  rW   r   r   rS   rS   rT   r     r  zTestParforsDiagnostics.checkc                 C   s$   |  |}|  |}| || d S rW   )_fusion_equivalentr   )rP   r  r  rv   rw   rS   rS   rT   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 rS   rS   r   min_keyrS   rT   r   +  r   z=TestParforsDiagnostics._fusion_equivalent.<locals>.<listcomp>)r   r   r=  keyssorted)rP   thingnewr   rS   r   rT   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   rp   )r   count_parforsr  fusion_infonested_fusion_infor  r  r  hoisted_allocationsr   r3   r   dump)rP   rn  parfors_countr'  r(  r  r)  replr   replacedr   hoisted_allocsrS   rS   rT   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   rv   rw   rS   rS   rT   r  L  s   

z9TestParforsDiagnostics.test_array_expr.<locals>.test_implrS   parfor_diagnosticsr   r   r   rp   )r+  r'  r   r   r  r/  rP   r  r   rn  rS   rS   rT   test_array_exprK  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 r0  r   r  r   )r   rv   r   rS   rS   rT   r  Y  
   
z5TestParforsDiagnostics.test_prange.<locals>.test_implrS   r2  r   r+  r3  r4  rS   rS   rT   test_prangeX  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   rv   rw   r  r   rO  rS   rS   rT   r  h  s   

z;TestParforsDiagnostics.test_user_varname.<locals>.test_implrS   r2  c                 s   s    | ]}d |j v V  qdS )zslice(0, n, 1)N)rb  )r   r  rS   rS   rT   r  y  s    z;TestParforsDiagnostics.test_user_varname.<locals>.<genexpr>N)r   r   r  r"  anyfusion_reportsr4  rS   rS   rT   test_user_varnamee  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 r0  r7  )r   rv   r   rO  rS   rS   rT   r  |  s   z<TestParforsDiagnostics.test_nested_prange.<locals>.test_implrS   r2  r   r   )r+  r(  r3  r4  rS   rS   rT   test_nested_prange{  s   


z)TestParforsDiagnostics.test_nested_prangec                 C   sF   dd }|  | | |d}|jd }| j|dddgidgd	 d S )
Nc                  S   s   d} t | }t |}|S r0  )r   r  rY  r1  rS   rS   rT   r    s   

zCTestParforsDiagnostics.test_function_replacement.<locals>.test_implrS   r2  r   r   r   )rY  r  )r+  r'  r  r3  r4  rS   rS   rT   test_function_replacement  s   


z0TestParforsDiagnostics.test_function_replacementc                 C   r6  )Nc                  S   s4   d} t | d }d}t| D ]}||| 7 }q|S r$  r   r  r   r   rv   r  r   rS   rS   rT   r       z8TestParforsDiagnostics.test_reduction.<locals>.test_implrS   r2  r   r9  r3  r4  rS   rS   rT   r    
   

z%TestParforsDiagnostics.test_reductionc                 C   r6  )Nc                  S   s4   d} t | d }d}t| D ]}|||  }q|S r$  rB  rC  rS   rS   rT   r    rD  z>TestParforsDiagnostics.test_reduction_binop.<locals>.test_implrS   r2  r   r9  r3  r4  rS   rS   rT   test_reduction_binop  rE  z+TestParforsDiagnostics.test_reduction_binopc                 C   r6  )Nc                  S   s   d} t | }d|d d < |S )Nr   r  r  )r   rv   rS   rS   rT   r    s   
z6TestParforsDiagnostics.test_setitem.<locals>.test_implrS   r2  r   r9  r3  r4  rS   rS   rT   test_setitem  s
   

z#TestParforsDiagnostics.test_setitemc                 C   r6  )Nc                  S   sL   d} d}d}t | D ]}t|f}t|D ]}|||< q||d 7 }q
|S )Nr   rp   r   rF   )r   r   r  r   )r   r  r  r   temprO  rS   rS   rT   r    s   
zBTestParforsDiagnostics.test_allocation_hoisting.<locals>.test_implrS   r2  r   )r)  r3  r4  rS   rS   rT   test_allocation_hoisting  s
   

z/TestParforsDiagnostics.test_allocation_hoisting)NNNNN)rh   rK   ri   r   r  r  r/  r5  r:  r?  r@  rA  r  rF  rG  rI  rS   rS   rS   rT   r    s"    
r  c                   @   s   e Zd Zdd Zdd ZdS )TestPrangeBasec                 C   s:  |j }t|j}|du r#d|jv sJ tdd |jD }t|j}nj|jd}g }t|D ]}|j	dkrFt
|j|krF||jd  q0|d t|}t|d }	tjdv rbd|	d>  }	ntjd	v rhnttjt|j}t|t|ks|J |D ]
}
||
 }|	||< q~t|}|j||d
}t|t }|S )z
        This function does the actual code augmentation to enable the explicit
        testing of `prange` calls in place of `range`.
        Nr   c                 S   s   g | ]
}|d kr
|ndqS )r   r   rS   r   rS   rS   rT   r     s    z7TestPrangeBase.generate_prange_func.<locals>.<listcomp>LOAD_GLOBALr   r   ))r   rO  )r   r  )r   r)  ))r   r   )co_codeco_names)__code__r   rM  r   bytesrL  r  disBytecodeopnamerA   rU  r   offsetr   rB   	PYVERSIONNotImplementedError	bytearrayreplacepytypesFunctionTypeglobals)rP   r   patch_instancepyfunc_codeprange_namesnew_code	range_idxrange_locationsinstr
prange_idxr   r  prange_codepfuncrS   rS   rT   generate_prange_func  sD   







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   rS   r   r   rS   rS   rT   r   S  r   z0TestPrangeBase.prange_tester.<locals>.<listcomp>Tr[  r]  r   )r   re  r   r   re  rf  rg  r   r-  r   r  r   )rP   r   r   r   r[  r   rf  rd  r|   r   rj  r   
fastcpfuncrS   rS   rT   prange_tester
  s"   A
zTestPrangeBase.prange_testerN)rh   rK   ri   re  rh  rS   rS   rS   rT   rJ    s    6rJ  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  rS   rS   rT   r  n  r8  z0TestPrangeBasic.test_prange01.<locals>.test_implr   Tr   r   rh  r  rS   rS   rT   test_prange01m     
zTestPrangeBasic.test_prange01c                 C   rj  )Nc                  S   s6   d} t | d }td| D ]
}d| ||d < q|S )Nr   r   r  rk  r  rS   rS   rT   r  x  s
   z0TestPrangeBasic.test_prange02.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange02w  ro  zTestPrangeBasic.test_prange02c                 C   rj  )Nc                  S   s   d} t dD ]}| d7 } q| S Nr   r   rS  rI  r   rS   rS   rT   r    r  z0TestPrangeBasic.test_prange03.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange03     
zTestPrangeBasic.test_prange03c                 C   rj  )Nc                  S   s   d} t dD ]}| d9 } q| S )Nr   r   r   rS  rr  rS   rS   rT   r    r  z3TestPrangeBasic.test_prange03mul.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange03mul  rt  z TestPrangeBasic.test_prange03mulc                 C   rj  )Nc                  S   s   d} t dD ]}| d8 } q| S )Nrd  r   r   rS  rr  rS   rS   rT   r    r  z3TestPrangeBasic.test_prange03sub.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange03sub  rt  z TestPrangeBasic.test_prange03subc                 C   rj  )Nc                  S   s   d} t dD ]}| d } q| S rq  rS  rr  rS   rS   rT   r    r  z3TestPrangeBasic.test_prange03div.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange03div  rt  z TestPrangeBasic.test_prange03divc                 C   rj  )Nc                  S   s>   d} d}t d}tdD ]}|| kr|||< qd||< q|S )Nr   r   r   r   r   r  r   rv   rw   rP  r   rS   rS   rT   r    s   


z0TestPrangeBasic.test_prange04.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange04  s   

zTestPrangeBasic.test_prange04c                 C   rj  )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   rP  rI  r   rS   rS   rT   r    s   z0TestPrangeBasic.test_prange05.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange05     
zTestPrangeBasic.test_prange05c                 C   rj  )Nc                  S   s:   d} t j| t jd}d}tdddD ]}||| 7 }q|S r{  r|  r}  rS   rS   rT   r    s   z0TestPrangeBasic.test_prange06.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange06  r  zTestPrangeBasic.test_prange06c                 C   rj  )Nc                  S   s8   d} t j| t jd}d}t| dD ]}||| 7 }q|S r{  r|  r}  rS   rS   rT   r    s   z0TestPrangeBasic.test_prange07.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange07  r  zTestPrangeBasic.test_prange07c                 C   rj  )Nc                  S   sF   d} t | }d}tt|D ]}tt|D ]}||| 7 }qq|S rD  r   r  r   r   r   rP  r  r   rO  rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange08.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange08     
zTestPrangeBasic.test_prange08c                 C   rj  )Nc                  S   s>   d} t | }d}tdD ]}tdD ]}||| 7 }qq|S rD  r   r  r   r  rS   rS   rT   r    s   
z2TestPrangeBasic.test_prange08_1.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange08_1  r  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   rS  )r   r  r   rO  rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange09.<locals>.test_implr   r   Tr[  r   r   rm  r  rS   rS   rT   test_prange09  s
   

zTestPrangeBasic.test_prange09c                 C   r  )Nc                  S   s<   d} d}t | D ]}d}t | D ]}|d7 }q||7 }q|S r  rS  )r   acc2rO  acc1r   rS   rS   rT   r    s   

z0TestPrangeBasic.test_prange10.<locals>.test_implr   r   Tr  rm  r  rS   rS   rT   test_prange10  s
   


zTestPrangeBasic.test_prange10z1list append is not thread-safe yet (#2391, #2408)c                 C   rj  )Nc                  S   s   d} dd t | D S )Nr   c                 S   r   rS   )r   r;  rN  rS   rS   rT   r     r   zDTestPrangeBasic.test_prange11.<locals>.test_impl.<locals>.<listcomp>rS  r   rS   rS   rT   r  
  s   z0TestPrangeBasic.test_prange11.<locals>.test_implr   Trl  rm  r  rS   rS   rT   test_prange11  s   
zTestPrangeBasic.test_prange11c                 C   rj  )Nc                  S   s6   d} d}t |}tt| D ]}| || 7 } q| S r  r  )r  r   rG  r   rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange12.<locals>.test_implr   Trl  rm  r  rS   rS   rT   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  rS  r  rS   rS   rT   r    r  z0TestPrangeBasic.test_prange13.<locals>.test_implr   r   Trl  )rh  r   r  r  rS   rS   rT   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   )rP  rI  r   rS   rS   rT   r  %  s   z0TestPrangeBasic.test_prange14.<locals>.test_implr   r   Trl  )rh  r   r   r!  r  rS   rS   rT   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  )rb  r  r   r   rS   rS   rT   r  4  s
   
z0TestPrangeBasic.test_prange15.<locals>.test_implr-  r   Trl  rm  r  rS   rS   rT   test_prange151  s   

zTestPrangeBasic.test_prange15c                 C   r  )Nc                 S   s"   d}t |  | D ]}|d7 }q|S r  rS  rb  r  r   rS   rS   rT   r  ?     
z0TestPrangeBasic.test_prange16.<locals>.test_implr-  r   Trl  rm  r  rS   rS   rT   test_prange16>     

zTestPrangeBasic.test_prange16c                 C   r  )Nc                 S   s0   d}t | }t|  | D ]}||| 7 }q|S r  r  rb  r  rG  r   rS   rS   rT   r  H  s
   
z0TestPrangeBasic.test_prange17.<locals>.test_implr  r   Trl  rm  r  rS   rS   rT   test_prange17G     

zTestPrangeBasic.test_prange17c                 C   r  )Nc                 S   sL   d}t | }t|  dD ]}||| 7 }td| D ]}||| 7 }qq|S )Nr   rp   r  )rb  r  rG  r   rO  rS   rS   rT   r  R  s   
z0TestPrangeBasic.test_prange18.<locals>.test_implr  r   Trl  rm  r  rS   rS   rT   test_prange18Q     

zTestPrangeBasic.test_prange18c                 C   r  )Nc                 S   sR   d}| d }t | |f}t|  | D ]}t| |D ]
}||||f 7 }qq|S r  r  )rb  r  MrG  r   rO  rS   rS   rT   r  ^  s   z0TestPrangeBasic.test_prange19.<locals>.test_implr  r   Trl  rm  r  rS   rS   rT   test_prange19]  r  zTestPrangeBasic.test_prange19c                 C   r  )Nc                 S   s.   d}t | }td| D ]}||| 7 }q|S )Nr   rF   r  r  rS   rS   rT   r  j  s
   
z0TestPrangeBasic.test_prange20.<locals>.test_implr  r   Trl  rm  r  rS   rS   rT   test_prange20i  r  zTestPrangeBasic.test_prange20c                 C   r  )Nc                 S   s    d}t ddD ]}|d7 }q|S )Nr   r!  rF   r   rS  r  rS   rS   rT   r  t  r  z0TestPrangeBasic.test_prange21.<locals>.test_implr  r   Trl  rm  r  rS   rS   rT   test_prange21s  r  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   rF   r  rx  ry  rS   rS   rT   r  }  s   



z0TestPrangeBasic.test_prange22.<locals>.test_implr   Tr   r   rf  rm  r  rS   rS   rT   test_prange22|  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 rW   r  rP  r   rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange23.<locals>.test_impl    r   r   Tr  r   r  rh  rP   r  rP  rS   rS   rT   test_prange23  
   

zTestPrangeBasic.test_prange23c                 C   r  )Nc                 S   s"   t t|  dD ]}|| |< q| S r  r  r  rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange24.<locals>.test_implr  r   r   Tr  r  r  rS   rS   rT   test_prange24  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 rS   )r   
zeros_liker   rG   rc  rS   rT   r     r   zDTestPrangeBasic.test_prange25.<locals>.test_impl.<locals>.<listcomp>)r   r   )rP  r   r  r   rS   rc  rT   r    s
   z0TestPrangeBasic.test_prange25.<locals>.test_implr  r   r   T)r[  r   r   rf  r2  r   )
r   r  rh  r   r   r   r  r)  r   r   )rP   r  rP  r   rn  r.  rS   rS   rT   test_prange25  s   

zTestPrangeBasic.test_prange25c                 C   r  )Nc                 S   s,   | d d d }t t|D ]}|||< q| S r  r  )rP  r9  r   rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange26.<locals>.test_implr  r   r   Tr  r  r  rS   rS   rT   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)rv   rw   r  rO  r   r  rS   rS   rT   r    s
   z0TestPrangeBasic.test_prange27.<locals>.test_implr  )
r   r   r   r   r   r   r   r   r   r   r   r   r   Tr  )rh  r   r  asarrayr  rS   rS   rT   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  r  i0r  Pt1Pt2r  vl2rS   rS   rT   r    s   
z0TestPrangeBasic.test_prange28.<locals>.test_impl      r0  rx  r   r   r   r   r   rp   r   Tr  )r   r_  rh  r]  rS   rS   rT   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   rS  )r  r1  r   rS   rS   rT   r    s   

z0TestPrangeBasic.test_prange29.<locals>.test_implTFrm  r  rS   rS   rT   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  )r^  r   r   r  r(  r   )
r   par
numthreadsn_parn_xr1  chunklenr   r[  r\  rS   rS   rT   r    s   
*z0TestPrangeBasic.test_prange30.<locals>.test_implr   r   r0  r  r   )r   r_  r  rh  )rP   r  r   r  rS   rS   rT   test_prange30  s   zTestPrangeBasic.test_prange30N)(rh   rK   ri   r.  rn  rp  rs  ru  rv  rw  rz  r~  r  r  r  r  r  r  r  skipr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rS   rS   rS   rT   ri  i  sJ    

				
		

	


ri  c                 C   s   | |fS rW   rS   ru   rS   rS   rT   test_call_hoisting_outcall  r  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d2d3 Zd4d5 Zed6d7 Z d8S )9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   rS  r   r  r   rS   rS   rT   r       zRTestPrangeSpecific.test_prange_two_instances_same_reduction_var.<locals>.test_implr  rm  r  rS   rS   rT   ,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 r  rS  r  rS   rS   rT   r  #  r  zKTestPrangeSpecific.test_prange_conflicting_reduction_ops.<locals>.test_implr  zBReduction variable c has multiple conflicting reduction operators.)r  r   UnsupportedErrorrh  r   r   r  rP   r  r  r   rS   rS   rT   %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  rz  )rP  r9  r   r   rS   rS   rT   r  3  s   

zLTestPrangeSpecific.test_prange_two_conditional_reductions.<locals>.test_implrm  r  rS   rS   rT   &test_prange_two_conditional_reductions1  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  rS  )rP  r   r   rS   rS   rT   r  @  s   zCTestPrangeSpecific.test_prange_nested_reduction1.<locals>.test_implrm  r  rS   rS   rT   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 )Nr  r   rk  r  rS   rS   rT   r  K  r8  z<TestPrangeSpecific.test_check_error_model.<locals>.test_implrS   r   )	r  ZeroDivisionErrorre  r   r   r   r   r   r  )rP   r  r  rd  pcrespfcresr1  rS   rS   rT   test_check_error_modelI  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  r  )rP  r   r9  rS   rS   rT   r  d  s   z?TestPrangeSpecific.test_check_alias_analysis.<locals>.test_implr  r   r%  r   Tr  definenoaliasr   )r   r  r   rh  re  r   r   r   r   r  r*  r  r   r&  )
rP   r  rP  rd  r|   r   r+  r   r  ro  rS   rS   rT   test_check_alias_analysisb  s    

z,TestPrangeSpecific.test_check_alias_analysisc                 C   r  )Nc                 S   s"   d}t d| dD ]}|d7 }q|S r  rS  r  rS   rS   rT   r  {  r  zJTestPrangeSpecific.test_prange_raises_invalid_step_size.<locals>.test_implr-  z4Only constant step size of 1 is supported for prange)r  r   r  rh  r   r   r  r  rS   rS   rT   $test_prange_raises_invalid_step_sizez  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
}	| D ]-\}
}|
|j v rg|	 }t
|D ]\}}||rf| |||d   d}	 nqMq:| |	d d S )Nc                  S   s&   d} d}t | D ]}||d 7 }q|S )NrP  r   r  rS  r  rS   rS   rT   r    s
   zFTestPrangeSpecific.test_prange_fastmath_check_works.<locals>.test_implr   Trl  rS   z%[A-Z_0-9]?(.[0-9]+)+[.]?[i]?z)\s+%s = fmul fast double %s, 5.000000e-01z\s+%s = fadd fast double %s, %sFr   z'fast instruction pattern was not found.)rh  re  r   r  r  r  r*  r   r   r  r  r(  r"  )rP   r  rd  r   r   _id
recipr_strreciprocal_inst	fadd_instfoundr   kernelr  r   r   rS   rS   rT    test_prange_fastmath_check_works  s2   

z3TestPrangeSpecific.test_prange_fastmath_check_worksc                 C   r  )Nc                 S   s8   t | | f}|d }t| D ]}|d ||< q| S r  r   r  r   rM  )r   rw   rv   rO  rS   rS   rT   r    s
   z8TestPrangeSpecific.test_parfor_alias1.<locals>.test_implr   rm  r  rS   rS   rT   test_parfor_alias1  s   z%TestPrangeSpecific.test_parfor_alias1c                 C   r  )Nc                 S   sF   t | | f}t| D ]}|| }t| D ]}|| ||< qq| S rW   r  )r   rw   r   rv   rO  rS   rS   rT   r    s   z8TestPrangeSpecific.test_parfor_alias2.<locals>.test_implr   rm  r  rS   rS   rT   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 rW   r  )r   rw   r   rv   rO  r  r   rS   rS   rT   r    s   z8TestPrangeSpecific.test_parfor_alias3.<locals>.test_implr   rm  r  rS   rS   rT   test_parfor_alias3  r:  z%TestPrangeSpecific.test_parfor_alias3c                 C   s8   dd }|  |dd}|d }d}| |t|j d S )Nc                 S   s   t |D ]}| }q|S rW   rS  )r   r  rO  r   rS   rS   rT   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.)rh  r   r   rb  )rP   r  rj  warning_objexpected_msgrS   rS   rT   test_parfor_race_1  s
   z%TestPrangeSpecific.test_parfor_race_1c                 C   rA  )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   r0  r   )r   negativer   r  )r9  r  r   this_mattersrS   rS   rT   r    s   zGTestPrangeSpecific.test_nested_parfor_push_call_vars.<locals>.test_implNrm  r  rS   rS   rT   !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   r3  )zztclhlcr   ntrM  rS   rS   rT   r    s   zATestPrangeSpecific.test_copy_global_for_parfor.<locals>.test_implr   r  r   r[  N)r   r  r+  rh  )rP   r  r  r  r  rS   rS   rT   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   r0  )r   r  r   )r   r9  r  r   r  rS   rS   rT   r    s   zGTestPrangeSpecific.test_multiple_call_getattr_object.<locals>.test_implr0  rm  r  rS   rS   rT   !test_multiple_call_getattr_object  r3  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   rS   rS   rT   r    s   zHTestPrangeSpecific.test_argument_alias_recarray_field.<locals>.test_implr   r   r  r  Tr   )	r   r  rI  r  viewrecarrayr   r
   r   )rP   r  X1X2X3r  r  v3
python_resnjit_respa_funcpa_resrS   rS   rT   "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.
            rF   r   )r   )rG  r  rv   rS   rS   rT   
list_check'  s   
z>TestPrangeSpecific.test_mutable_list_param.<locals>.list_checkc                    s    t | D ]	}dg} |}q|S r  r  )r   r   rG  rv   r  rS   rT   r  1  s   
z=TestPrangeSpecific.test_mutable_list_param.<locals>.test_implr   Tr   Nr
   r   )rP   r  r  r  r  r  rS   r  rT   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 rS   )r   r   r  rS   rT   r   @  s    zXTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl.<locals>.<listcomp>)r   r_  r   r   r  rS   r  rT   r  ?      zDTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl)r   r   r   r  r   r   )r   r_  r  rh  rF  rS   rS   rT   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  r^  r   )imagerv   rw   r  r   r  hrS   rS   rT   r  J  s   z>TestPrangeSpecific.test_ssa_false_reduction.<locals>.test_implrj  r  r   )r   r  r  rh  )rP   r  r  rS   rS   rT   test_ssa_false_reductionD  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 )Nrp   r  r   r   )r   r  r$  r   )r   rv   r   rG  rS   rS   rT   r  [  s   z@TestPrangeSpecific.test_list_setitem_hoisting.<locals>.test_implrm  r  rS   rS   rT   test_list_setitem_hoistingX  s   	z-TestPrangeSpecific.test_list_setitem_hoistingc                 C   6   dd }t jd }| j|dd t|D dgd d S )Nc                 S   sb   dd t t| D }t t| D ]}| | }td}||d< | | |f||< q|d d d S )Nc                 S   (   g | ]}t jtjtjd tdfqS key_type
value_typer   r   r  r   r$  r(  r   r  r  rS   rS   rT   r   i     ( zMTestPrangeSpecific.test_tuple_hoisting.<locals>.test_impl.<locals>.<listcomp>r   r   )r   r   r   r  inputsoutputsr   r  r  rS   rS   rT   r  h  s   
z9TestPrangeSpecific.test_tuple_hoisting.<locals>.test_implr   c                 S      g | ]}t jtjtjd qS r  r   r  r   r$  r(  r   rS   rS   rT   r   r      z:TestPrangeSpecific.test_tuple_hoisting.<locals>.<listcomp>r  r   r  rh  r   rP   r  rb  rS   rS   rT   test_tuple_hoistingf     
	$z&TestPrangeSpecific.test_tuple_hoistingc                 C   r  )Nc                 S   sd   dd t t| D }t t| D ]}| | }td}||d< t| | |||< q|d d d S )Nc                 S   r  r  r  r  rS   rS   rT   r   w  r  zLTestPrangeSpecific.test_call_hoisting.<locals>.test_impl.<locals>.<listcomp>r   r   )r   r   r   r  r  r  rS   rS   rT   r  v  s   
z8TestPrangeSpecific.test_call_hoisting.<locals>.test_implr   c                 S   r  r  r  r   rS   rS   rT   r     r  z9TestPrangeSpecific.test_call_hoisting.<locals>.<listcomp>r  r  r  rS   rS   rT   test_call_hoistingt  r  z%TestPrangeSpecific.test_call_hoistingc                 C   sB   t dt jfg}dd }dd }| j|t jd|d|gd d S )	Nro  c                 S   s   t dD ]}d| | d< qd S )Nr   ro  rS  )statesr   rS   rS   rT   r    s   z?TestPrangeSpecific.test_record_array_setitem.<locals>.test_implc                 S   s    | d d |d d ksJ d S )Nr   ro  rS   ru   rS   rS   rT   r    r  z>TestPrangeSpecific.test_record_array_setitem.<locals>.comparerr   )r^  r  r  )r   r  r  rh  r  )rP   state_dtyper  r  rS   rS   rT   test_record_array_setitem  s   
z,TestPrangeSpecific.test_record_array_setitemc                 C   sF   t dt jfg}dd }t jd|d}dd }| j|||gd d S )	Nr   c                 S   s*   | j }t| j D ]
}d| | d |< q| S )Nr  r   )rf  r   )r  r   r   rS   rS   rT   r    s   zKTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.test_implr   r  c                 S   r  rW   r  ru   rS   rS   rT   r    r   zJTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.comparerr  )r   r  r%  r  rh  )rP   r  r  r  r  rS   rS   rT   %test_record_array_setitem_yield_array  s   
z8TestPrangeSpecific.test_record_array_setitem_yield_arrayc                 C   r  )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   rk  )rf  caser1  r   rS   rS   rT   r    s   z4TestPrangeSpecific.test_issue7501.<locals>.test_implr   r   rm  r  rS   rS   rT   test_issue7501  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 )Nr/  )r  r  r  r   r   )r   r_  r^  r   r=  r1  rM  r3  )
rG  rw   pointsrb  r   expsr   r  r	  r  rS   rS   rT   r    s   


2z6TestPrangeSpecific.test_kde_example.<locals>.test_implrP  )r   r   r!  rh  rH  rS   rS   rT   test_kde_example  s   z#TestPrangeSpecific.test_kde_examplec                 C   r  )Nc                 S   s6   t | }t | }tt| D ]}| ||< q|S rW   )r   r  r<  r   r   rM  )r   rP  r/  r   rS   rS   rT   r    s
   

z4TestPrangeSpecific.test_issue7578.<locals>.test_implr  )r   r  rh  rF  rS   rS   rT   test_issue7578  s   
	z!TestPrangeSpecific.test_issue7578N)!rh   rK   ri   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!  r8   r"  rS   rS   rS   rT   r    s>    

$	
r  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   rY   rS   rS   rT   setUp  r[   zTestParforChunksizing.setUpc                 C   r$  r  r%  rY   rS   rS   rT   tearDown  r[   zTestParforChunksizing.tearDownc                 C   s>   |  t d td |  t d td |  t d d S Nr   r%  )r   r   r   rY   rS   rS   rT   $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   rY   rS   rS   rT   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 rW   )r   rS   rS   rS   rT   get_cs  s   zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.get_csc                 S   s   t | S rW   r%  r  rS   rS   rT   set_cs  r  zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.set_csr   r%  r  )rP   r+  r,  rS   rS   rT   "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cs3rS   rS   rT   r    s   

zATestParforChunksizing.test_njit_with_chunksize.<locals>.test_implr%  r   r  )rP   r  r.  r/  r0  rS   rS   rT   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   rw  inner_csr   rS   rS   rT   r    s   


zLTestParforChunksizing.test_all_iterations_reset_chunksize.<locals>.test_impl)i  i  i  i  rl  r   r)  r   N)r
   r   r"  r   all)rP   r  rO  r   rw  r3  rS   rS   rT   #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$  )NrF   r%  rS   rS   rS   rT   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  )rP   r  r6  r   rS   rS   rT   %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 )NrF   r7  )r  r   r   r   r   r  rP   r  r   rS   rS   rT   'test_python_parallel_chunksize_negative1  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%  rS   rS   rS   rT   r   ;  r  zMTestParforChunksizing.test_njit_parallel_chunksize_invalid_type.<locals>.impl)The parallel chunksize must be an integer)r  r   TypingErrorr
   r   r   r  )rP   r  r   r   rS   rS   rT   )test_njit_parallel_chunksize_invalid_type9  s   
z?TestParforChunksizing.test_njit_parallel_chunksize_invalid_typec                 C   r9  )Nr<  r=  )r  	TypeErrorr   r   r   r  r:  rS   rS   rT   +test_python_parallel_chunksize_invalid_typeD  s
   
zATestParforChunksizing.test_python_parallel_chunksize_invalid_typeN)rh   rK   ri   r.  rj   r&  r'  r)  r*  r-  r1  r5  r8  r;  r?  rA  rS   rS   rS   rT   r#    s    r#  c                   @   sb   e Zd ZdZdd Zeejdd Zeejddidd	d
 Z	eejddid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   rS   r   r   rS   rS   rT   r   e  r   z8TestParforsVectorizer.get_gufunc_asm.<locals>.<listcomp>z%call\s+\w+\*\s+@do_scheduling_(\w+)\()r   r*  r   r5   r   re  r   r   r  r  r  findallr   r   r   r   r   assertNotEqual)rP   r{   schedule_typer   r   r   rC  rD  rE  env_opts	overridesr   r  r|   pfunc_vectorizabler   asmschedtymatchesrS   rS   rT   get_gufunc_asmS  s2   

Rz$TestParforsVectorizer.get_gufunc_asmc                 C   s   dd }t d}| j|d|dd}| j|d|dd}| D ]}| d|v  | d	|v p1d
|v  | d|v  q| D ])}| d|v | d	|v | d|v oXd
|v | d|v  | d|v q?dS ) This checks that if fastmath is set and the underlying hardware
        is suitable, and the function supplied is amenable to fastmath based
        vectorization, that the vectorizer actually runs.
        c                 S   s,   t | }d}t|D ]	}|t|7 }q
|S r  r   r   r   r2  )rP  r   r  r   rS   rS   rT   will_vectorize  s
   zJTestParforsVectorizer.test_vectorizer_fastmath_asm.<locals>.will_vectorizer   r   Tr   Fvaddpdvsqrtpd__svml_sqrtzmmvsqrtsdvaddsdN)r   r  rQ  r  r"  )rP   rT  rU  fast_asmslow_asmr  rS   rS   rT   test_vectorizer_fastmath_asmx  s&   


z2TestParforsVectorizer.test_vectorizer_fastmath_asmNUMBA_BOUNDSCHECK0)envvarsc                 C   s   dd }dd }t d}| tj | j|d|dd}| j|d	|dd}| D ]}| d
|v | d|v  | d|v q)| D ]}| d
|v pPd|v  | d|v  | d|v  qEdS )rR  c                 S   s0   t | }t| dD ]}t| | | |< q
| S r  rS  rP  r   r   rS   rS   rT   will_not_vectorize  s   zTTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_not_vectorizec                 S   s,   t | }t|D ]}t| | | |< q| S rW   rS  rb  rS   rS   rT   rT    s   zPTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_vectorizer   r   TrU  r   rW  rZ  rY  rX  vmovupdN)r   r  r  r   BOUNDSCHECKrQ  r  r"  )rP   rc  rT  rU  	novec_asmvec_asmr  rS   rS   rT   "test_unsigned_refusal_to_vectorize  s&   


z8TestParforsVectorizer.test_unsigned_refusal_to_vectorizec                 C   s  dd }dd }|  tj | j|ddd}| j|ddd}d	d
 }| D ]\}}||} | D ]\}}||}	 ddlm}
 | t|t|	 t	||	D ].\}}||krZqQ|
dd ||}|
 }|D ]}|d dkr~| ||d |d  d qhqQd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   rx  r   rS  r  rS   rS   rT   signed_variant  s
   
zMTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.signed_variantc                  S   s"   d} d}t | D ]}||7 }q|S )Nri  rx  rS  r  rS   rS   rT   unsigned_variant  s
   
zOTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.unsigned_variantr   TrU  r   c                 S   s`   g }|   D ]'}| }|dkr-|ds-|ds-|ds-d|v s-|tdd| q|S )N rE   rG   "r  z[	])r  strip
startswithr   r  sub)rN  r  r   spdrS   rS   rT   strip_instrs  s   zKTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.strip_instrsr   )SequenceMatcherc                 S   s   | dkS )N	rS   r  rS   rS   rT   ri    r  zGTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.<lambda>insertr  rF   r  N)r  r   re  rQ  r*  difflibrs  r   r   r   get_opcodes)rP   rj  rk  
signed_asmunsigned_asmrr  r   r  signed_instrunsigned_instrsmrv   rw   rI  r$  r'  rS   rS   rT   test_signed_vs_unsigned_vec_asm  s:   
z5TestParforsVectorizer.test_signed_vs_unsigned_vec_asmN)rh   rK   ri   rj   rQ  r6   r2   run_test_in_subprocessr^  rh  r}  rS   rS   rS   rT   rB  L  s    %'+rB  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r  maskrS   rT   udt     
z6TestParforReductionSetNumThreads.test_add.<locals>.udtr   r  r
   r  r  rP   rb  r  expectr  rS   r  rT   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  rS   rT   r  1  r  z6TestParforReductionSetNumThreads.test_mul.<locals>.udt)r=  r   r  r
   r  r  r  rS   r  rT   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  rS   rT   r  E  s   z6TestParforReductionSetNumThreads.test_max.<locals>.udtr  r  rS   r  rT   r  @  r  z)TestParforReductionSetNumThreads.test_maxN)rh   rK   ri   r.  r  r  r  rS   rS   rS   rT   r    s
    r  c                   @   s   e Zd Ze dd ZdS )TestDiagnosticEnvVarc                 C   s`   dt jd< t }tdddd }|  W d    n1 sw   Y  | }| d| d S )N4NUMBA_PARALLEL_DIAGNOSTICSTr   c                  S   s.   d} t j| t jd}t| D ]}d||< q|S )Nrd  r  r   )r   r  r(  r   )r   rw   r   rS   rS   rT   r   [  s
   
z<TestDiagnosticEnvVar.test_diagnostics_env_var1.<locals>.implzParallel Accelerator Optimizing)r  r  r3   r
   rm  r   )rP   rn  r   
the_outputrS   rS   rT   test_diagnostics_env_var1W  s   


z.TestDiagnosticEnvVar.test_diagnostics_env_var1N)rh   rK   ri   r2   r~  r  rS   rS   rS   rT   r  U  s    r  __main__rW   )rL  r  r  rP  r   rk   r  
subprocessr   rX  re  	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   numba.typedr   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.compilerr-   r.   numba.core.compiler_machineryr/   r0   numba.core.typed_passesr1   numba.tests.supportr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   numba.core.extendingr@   numba.core.bytecoderA   rB   r  r  rC   r  rl   x86_onlyr  r  rq   rx   ry   rC  rJ  rd  r  r   r  r  r  r  r  r  r  r  r  rs  r  r  r4  r  r  r  r  rJ  rP  rY  r  rJ  ri  r  r  r#  rB  r  r  rh   mainrS   rS   rS   rT   <module>   s   (, $@=
	  #A	
" ,*           C  +%=    	 >    '
   @z EB
