o
    i6l                    @   sp  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ	d dl
Z
d dlmZ d dlZd dlmZ d dlZd dlmZmZ d dlZd dlmZmZ d dlZd dlZd dlmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$mZm%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d d	l5m6Z6 d d
l7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZC d dlDmEZE d dlFmGZGmHZHmIZImJZJ d dlKmLZLmMZM d dlNmOZO d dlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] d dl^m_Z_ d dlDm`Z` d dl$maZa d dlbZbd dlcZceWG dd deQZdeceef dvdZgdZhdZieddZjdd Zke]G dd  d eQZld!d" Zmd#d$ Znd%d& Zod'd( Zpd)d* Zqd+d, Zrd-d. Zsd/d0 Ztd1d2 Zud3d4 Zvd5d6 Zwdbd7d8Zxd9d: ZyG d;d< d<ezZ{eWG d=d> d>elZ|eWG d?d@ d@elZ}eWG dAdB dBelZ~G dCdD dDeQZeWG dEdF dFelZeWG dGdH dHeSelZeWG dIdJ dJelZeWG dKdL dLelZeWG dMdN dNelZeWG dOdP dPelZeWG dQdR dRelZG dSdT dTelZeWG dUdV dVeZeWG dWdX dXeZeWG dYdZ dZeQZeWegG d[d\ d\eZeWG d]d^ d^eQZeWG d_d` d`eQZedakr6ec  dS dS )c    Nreducerandn)defaultdict
namedtuple)cyclechain)njitprangeparallel_chunksizeget_parallel_chunksizeset_parallel_chunksizeset_num_threadsget_num_threadstypeof)
typestypingerrorsirrewritestyped_passesinline_closurecallconfigcompilercpu)overload_methodregister_modeltypeof_implunboxNativeValuemodels)
cpu_target)type_annotations)find_callnameguardbuild_definitionsget_definition
is_getitem
is_setitemindex_var_of_get_setitem)empty_inferred)ByteCodeIter)compile_isolatedFlagsCompilerBaseDefaultPassBuilder)register_passAnalysisPass)IRLegalization)TestCasecaptured_stdoutMemoryLeakMixinoverride_env_config
linux_onlytagskip_parfors_unsupported_32bit
needs_blasneeds_lapackdisabled_testskip_unless_scipyneeds_subprocess)register_jitable)_fix_LOAD_GLOBAL_arg)utilsc                   @   s   e Zd ZdZe dkrdndZ	 dd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"TestParforsRunnerFaarch64i  i  c                 C   s8   | j }|  dd dd }| j||| jd d S )N._)Ztest_moduleZ
test_classtimeout)
__module__idsplitZsubprocess_test_runner_TIMEOUT)selfZthemodZtest_clazz_name rO   g/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_parfors.pyrunnerP   s   
zTestParforsRunner.runnerc                 C      |    d S NrQ   rN   rO   rO   rP   test_TestParforBasicX      z&TestParforsRunner.test_TestParforBasicc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforNumericalMisc[   rW   z.TestParforsRunner.test_TestParforNumericalMiscc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforNumPy^   rW   z&TestParforsRunner.test_TestParforNumPyc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsa   rW   z"TestParforsRunner.test_TestParforsc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsBitMaskd   rW   z)TestParforsRunner.test_TestParforsBitMaskc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsDiagnosticsg   rW   z-TestParforsRunner.test_TestParforsDiagnosticsc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsLeaksj   rW   z'TestParforsRunner.test_TestParforsLeaksc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsMiscm   rW   z&TestParforsRunner.test_TestParforsMiscc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsOptionsp   rW   z)TestParforsRunner.test_TestParforsOptionsc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsSlices   rW   z'TestParforsRunner.test_TestParforsSlicec                 C   rR   rS   rT   rU   rO   rO   rP   test_TestParforsVectorizerv   rW   z,TestParforsRunner.test_TestParforsVectorizerc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestPrangeBasicy   rW   z&TestParforsRunner.test_TestPrangeBasicc                 C   rR   rS   rT   rU   rO   rO   rP   test_TestPrangeSpecific|   rW   z)TestParforsRunner.test_TestPrangeSpecificN)__name__rJ   __qualname___numba_parallel_test_platformmachinerM   rQ   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rO   rO   rO   rP   rD   B   s$    rD   )i386x86_64zx86 only test      TestNamedTuplepart0part1c                 C   s   dS )z
    Used with check_arq_equality to indicate that we do not care
    whether the value of the parameter at the end of the function
    has a particular value.
    NrO   abrO   rO   rP   null_comparer   s   rt   c                       s   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd*ddZd*d d!Zd"d# Zd$d% Zd&d' Zd(d) Z  ZS )+TestParforsBasez
    Base class for testing parfors.
    Provides functions for compilation and three way comparison between
    python functions, njit'd functions and parfor njit'd functions.
    Fc                    sn   t  | _d| j_t  | _td| j_d| j_t  | _td| j_d| j_td| j_	t
t| j|  d S )NT)r.   cflagsZnrtpflagsr   ParallelOptionsZauto_parallelfast_pflagsZFastMathOptionsfastmathsuperru   __init__rN   args	__class__rO   rP   r|      s   zTestParforsBase.__init__c                 C   s   t |||dS N)flags)r-   )rN   funcsigr   rO   rO   rP   _compile_this      zTestParforsBase._compile_thisc                 C      | j ||| jdS r   )r   rw   rN   r   r   rO   rO   rP   compile_parallel      z TestParforsBase.compile_parallelc                 C   r   r   )r   ry   r   rO   rO   rP   compile_parallel_fastmath   r   z)TestParforsBase.compile_parallel_fastmathc                 C   r   r   )r   rv   r   rO   rO   rP   compile_njit   r   zTestParforsBase.compile_njitc                 O   s2   t dd |D }| ||}| ||}||fS )Nc                 S      g | ]}t |qS rO   numbar   .0xrO   rO   rP   
<listcomp>       z/TestParforsBase.compile_all.<locals>.<listcomp>)tupler   r   )rN   pyfuncr~   kwargsr   cpfunccfuncrO   rO   rP   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 ]U}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dt |S )Nkz%Unsupported argument type encountered)r   
isinstancenpZndarrayappendcopynumbernumbersNumberdeepcopylist
ValueError)r~   new_argsr   rO   rO   rP   	copy_args   s$   

z:TestParforsBase.check_parfors_vs_others.<locals>.copy_args)
popentry_pointr   testingassert_almost_equalassertEqualtypelenzipr   )rN   r   r   r   r~   r   r   r   r   r   Zcheck_args_for_equalityr   Zpy_argsZpy_expectedZ	njit_argsZnjit_outputZparfor_argsparfor_outputZpyargZnjitargZ	parforargZargcompZparfor_fastmath_outputrO   rO   rP   check_parfors_vs_others   s<   


z'TestParforsBase.check_parfors_vs_othersc                 O   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   rN   r   r~   r   r   r   rO   rO   rP   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   )rN   implarg_genr   r~   rO   rO   rP   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)rN   r   r   r   r~   ZargtysrO   rO   rP   count_parfors_variants*  s   
z&TestParforsBase.count_parfors_variantsc                 C   sH   d}|d ur|dv r|d| 7 }nd}t || | ||j  d S )Nz@do_scheduling)signedunsignedrH   z$Unknown scheduler_type specified: %s)r   assertInlibraryget_llvm_str)rN   cresr   Zscheduler_strmsgrO   rO   rP   r   4  s   z TestParforsBase.check_schedulingc                    s,    fdd}t | fddt|D S )zFMake *ct* sample 1D arrays of length *n* using np.linspace().
        c                   3   s6    t dd V  t dd V  t dd V  d S Nr   r      r   linspacerO   nrO   rP   genC  s   z)TestParforsBase.gen_linspace.<locals>.genc                    s   g | ]}t  qS rO   )nextr   i)srcrO   rP   r   I      z0TestParforsBase.gen_linspace.<locals>.<listcomp>)r   range)rN   r   ctr   rO   )r   r   rP   gen_linspace@  s   
zTestParforsBase.gen_linspacec                 c   sr    | j d|dV  dd | j d|dD }|V  dd |D V  dd | j d	|dD }|V  d
d |D V  dS )z?Make 1D, 2D, 3D variants of the data in C and F orders
        
   )r   c                 S      g | ]}| d qS )r      reshaper   rO   rO   rP   r   R      z9TestParforsBase.gen_linspace_variants.<locals>.<listcomp>   )r   r   c                 S   r   rO   r   Zasfortranarrayr   rO   rO   rP   r   V  r   c                 S   r   ))r   r      r   r   rO   rO   rP   r   Y  r      c                 S   r   rO   r   r   rO   rO   rP   r   ]  r   N)r   )rN   r   Zarr2dsZarr3dsrO   rO   rP   gen_linspace_variantsK  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 rO   namer   magicstrrO   rP   r   a  s    z/TestParforsBase._filter_mod.<locals>.<listcomp>N)str)rN   modr   checkstrZfiltr   rO   r   rP   _filter_mod_  s
   zTestParforsBase._filter_modc                 C   s(   dd |j jjjjD }| j|||dS )z gets the gufunc LLVM Modulesc                 S      g | ]}|qS rO   rO   r   rO   rO   rP   r   i      z7TestParforsBase._get_gufunc_modules.<locals>.<listcomp>)r   )r   _codegenZ_engineZ_ee_modulesr   )rN   r   r   r   r   rO   rO   rP   _get_gufunc_modulesg  s   z#TestParforsBase._get_gufunc_modulesc                 C   s2   d}|  ||}t }|D ]	}||||j< q|S )z$ helper for gufunc IR/asm generation__numba_parfor_gufunc)r   dictr   )rN   r   fnr   Zgufunc_modsr   r   rO   rO   rP   _get_gufunc_infol  s   z TestParforsBase._get_gufunc_infoc                 C   s   |  |tS )z
        Returns the IR of the gufuncs used as parfor kernels
        as a dict mapping the gufunc name to its IR.

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

        Arguments:
         cres - a CompileResult from `njit(parallel=True, ...)`
        c                    s   t  | S rS   )r   Zemit_assembly)r   tmrO   rP   emit_asm  r   z1TestParforsBase._get_gufunc_asm.<locals>.emit_asm)r   r   Z_tmr   )rN   r   r   rO   r   rP   _get_gufunc_asm  s   
zTestParforsBase._get_gufunc_asmc           
         sP     ||} |}dd } fdd}| D ]\}}||}	||	 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   splittedZ	fast_instr   mrO   rO   rP   _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)ZfaddZfsubZfmulZfdivZfremZfcmpcallr   z fastr   )
assertTrue)ZinstrsopsinstcountopmatchrU   rO   rP   _assert_fast  s   z5TestParforsBase.assert_fastmath.<locals>._assert_fastN)r   r   items)
rN   r   r   r   _irr   r  r   Zguirr  rO   rU   rP   assert_fastmath  s   
	

zTestParforsBase.assert_fastmathrS   )rd   rJ   re   __doc__rf   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  __classcell__rO   rO   r   rP   ru      s,    Z




ru   c                 C   s   t | | }d| | }|t | }|| | | | }|| }	dd|  }
dd|	  }|t | |  }|| }| |
 | }|| |  }|S )N      ?      ?)r   logsqrtexp)ZsptpricestrikeZrateZ
volatilityZtimevZlogtermZpowtermZdenZd1Zd2ZNofXd1ZNofXd2ZfutureValuec1r  putrO   rO   rP   blackscholes_impl  s   r  c                 C   sF   t |D ]}|tddt|  t||   d |  |8 }q|S Nr  )r   r   dotr  )YXwZ
iterationsr   rO   rO   rP   lr_impl  s   6r  c                    s|   | j \}t|D ]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   )mathr  r   sumr   j)A	centroidsr   rO   rP   r     s    42example_kmeans_test.<locals>.<listcomp>.<listcomp>r   r   )r"  r#  	numCenterr   rP   r     
    
z'example_kmeans_test.<locals>.<listcomp>c                    s    g | ]} |d d f   qS rS   argminr   )distrO   rP   r     s     c                    s&   g | ]  fd dt D qS )c                    s0   g | ]}t  k|f t k qS rO   r   r  r   )r"  r   labelsrO   rP   r     s    (r$  r%  r&  )r"  Dr.  r(  rP   r     r)  )shaper   r   array)r"  r'  ZnumIterinit_centroidsNlrO   )r"  r/  r#  r,  r.  r'  rP   example_kmeans_test  s   

r5  c                 K   s`  t  }t|d}t| }|rt|}ntd}t||||}t	|| |
  |
  tj|jj|dd}|  tjd|j t|jj|jj|jj|jjd \|j_|j_|j_}	tj|jj|jj|jjdd |jj|jjtjd tj j!" }
tj j!j#|jj|jj|jj|jj|jj||
j$d}|  tjd|j t% }tj j!j&|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  tj j!j(|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  tj j!j)|jj|jj|jj|jj|jj|jj|||jj'|
d	
}|  t*|j+|_,W d    ||fS 1 s'w   Y  ||fS )
Nr   T)typedzbefore-inferencerO   )func_irtypemap	calltypesZliftedZlifted_fromr~   return_typeZhtml_output)Zswappedzafter-inference)diagnostics)-r   Contextr   Z
CPUContextr   Zrun_frontendrx   TestPipeliner"   Znested_contextrefreshr   ZInlineClosureCallPassstater7  runr   Zrewrite_registryapplyr   Ztype_inference_stage	typingctx	targetctxr~   r8  r:  r9  r#   ZTypeAnnotationr   HTMLr   parforsparforZParforDiagnosticsZPreParforPassreplaced_fnsr.   Z
ParforPassmetadataZParforFusionPassZParforPreLoweringPassr&   blocksZ_definitions)	test_funcr~   kwsrB  rC  test_iroptionstpZinline_passrH   r;  Zpreparfor_passr   Zparfor_passrO   rO   rP   get_optimized_numba_ir  s|   





55rO  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   )
rO  rI  r	  	enumeratebodyr   r   rE  rF  Parfor)
rJ  r~   rK  rL  rN  	ret_countlabelblockr   r  rO   rO   rP   r     s   r   c                 K   s&   t | |fi |\}}t|j|jjS rS   )rO  _count_arrays_innerrI  r?  r8  rJ  r~   rK  rL  rN  rO   rO   rP   countArrays&  s   rY  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   )rO  rI  r	  rQ  rR  r   r   rE  rF  rS  r   
init_block)rJ  r~   rK  rL  rN  rI  rT  rU  rV  r   r  rO   rO   rP   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 rZ  )setr	  rQ  rR  r   r   rE  rF  rS  	loop_bodyr   r[  rW  r   Assigntargetr   r   ArrayCompatibleaddr   )	rI  r8  rT  Zarr_setrU  rV  r   r  parfor_blocksrO   rO   rP   rW  7  s$   


rW  c                 K   s<   t | |fi |\}}d}|j D ]	}|t||7 }q|S rZ  )rO  rI  values_count_array_allocs_inner)rJ  r~   rK  rL  rN  rT  rV  rO   rO   rP   countArrayAllocsI  s
   rf  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   )rR  r   r   rE  rF  rS  re  r[  r^  rd  r   r_  valueExprr  r%   r$   )r7  rV  rT  r  rs   rO   rO   rP   re  R  s   
re  c                 K   s(   t | |fi |\}}t||j|jjS rS   )rO  &_count_non_parfor_array_accesses_innerrI  r?  r8  rX  rO   rO   rP   countNonParforArrayAccessesc  s   rl  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 rP  )r]  r	  rR  r   r   rE  rF  rS  rb  	index_varr   r^  r   r[  rk  r(   ri  r   ra  _uses_indicesr*   r)   r`  r   r_  ZVar)	f_irrI  r8  Zparfor_indicesrT  rU  rV  stmtrc  rO   rO   rP   rk  h  sH   






rk  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 rS   r   )r   vrO   rO   rP   	<genexpr>  s    z _uses_indices.<locals>.<genexpr>r   F)
r   r%   r'   r   r   rj  r  r]  r	  r   )ro  indexZ	index_setZind_defvarnamesrO   rO   rP   rn    s   
rn  c                   @      e Zd Zdd ZdS )r=  c                 C   sN   t  | _|| j_|| j_|| j_|| j_d | j_d | j_d | j_	i | j_
d S rS   )r   Z	StateDictr?  rB  rC  r~   r7  r8  r:  r9  rH  )rN   rB  rC  r~   rL  rO   rO   rP   r|     s   
zTestPipeline.__init__N)rd   rJ   re   r|   rO   rO   rO   rP   r=    s    r=  c                   @   s  e Zd ZdZdd Zdd Zdd Zd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         @      @)ru   r|   r   r   arangeTsimple_args)rN   r~   r   rO   rO   rP   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 )NrO   r   onesrO   rO   rO   rP   	test_impl     
z0TestParforBasic.test_simple01.<locals>.test_impl'@do_scheduling' not foundassertRaisesAssertionErrorr   r   r   	exceptionrN   r  raisesrO   rO   rP   test_simple01  
   zTestParforBasic.test_simple01c                 C      dd }|  | d S )Nc                   S   r  )Nr   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple02.<locals>.test_implr   rN   r  rO   rO   rP   test_simple02     zTestParforBasic.test_simple02c                 C   r  )Nc                   S   r  Nr   r   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple03.<locals>.test_implr  r  rO   rO   rP   test_simple03  r  zTestParforBasic.test_simple03c                 C   r  )Nc                   S   r  Nr   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple04.<locals>.test_implr  r  rO   rO   rP   test_simple04  r  zTestParforBasic.test_simple04c                 C   r  )Nc                   S   s   t jdt jdS )Nr  dtyper   r  
complex128rO   rO   rO   rP   r       z0TestParforBasic.test_simple07.<locals>.test_implr  r  rO   rO   rP   test_simple07  r  zTestParforBasic.test_simple07c                 C   r  )Nc                   S   s   t dt d S r  r  rO   rO   rO   rP   r       z0TestParforBasic.test_simple08.<locals>.test_implr  r  rO   rO   rP   test_simple08  r  zTestParforBasic.test_simple08c                 C   r  )Nc                   S   r  )Nr   r   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple09.<locals>.test_implr  r  rO   rO   rP   test_simple09  r  zTestParforBasic.test_simple09c                 C   r  )Nc                   S   r  )Nr   r   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple10.<locals>.test_implr  r  rO   rO   rP   test_simple10  r  zTestParforBasic.test_simple10c                 C   r  )Nc                   S   s   t dd S Nr   r   r  r  rO   rO   rO   rP   r    r   z0TestParforBasic.test_simple11.<locals>.test_implr  r  rO   rO   rP   test_simple11  r  zTestParforBasic.test_simple11c                 C   r  )Nc                   S   s   t dt d S r  r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple12.<locals>.test_implr  r  rO   rO   rP   test_simple12  r  zTestParforBasic.test_simple12c                 C   r  )Nc                   S   r  r  )r   r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple13.<locals>.test_implr  r  r  rO   rO   rP   test_simple13  r  zTestParforBasic.test_simple13c                 C   r  )Nc                   S   s   t ddd d S )Nr  r      r  rO   rO   rO   rP   r    r  z0TestParforBasic.test_simple14.<locals>.test_implr  r  rO   rO   rP   test_simple14  r  zTestParforBasic.test_simple14c                 C       dd }| j |g| jR   d S )Nc                 S   s   | |  S rS   rO   v1v2m1m2rO   rO   rP   r       z0TestParforBasic.test_simple15.<locals>.test_implr   r~  r  rO   rO   rP   test_simple15     zTestParforBasic.test_simple15c                 C   r  )Nc                 S   s   || S rS   rO   r  rO   rO   rP   r    r  z0TestParforBasic.test_simple16.<locals>.test_implr  r  rO   rO   rP   test_simple16  r  zTestParforBasic.test_simple16c                 C   r  )Nc                 S   s   ||  S rS   rO   r  rO   rO   rP   r    r  z0TestParforBasic.test_simple17.<locals>.test_implr  r  rO   rO   rP   test_simple17  r  zTestParforBasic.test_simple17c                 C   r  )Nc                 S   s   |j tj|d  S r  )r}  r   linalgZsvdr  rO   rO   rP   r       z0TestParforBasic.test_simple18.<locals>.test_implr  r  rO   rO   rP   test_simple18     zTestParforBasic.test_simple18c                 C   r  )Nc                 S   s   t ||S rS   r   r  r  rO   rO   rP   r    rW   z0TestParforBasic.test_simple19.<locals>.test_implr  r  rO   rO   rP   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 rS   r  r  rO   rO   rP   r    rW   z0TestParforBasic.test_simple20.<locals>.test_implr  )r  r  r   r~  r   r   r  r  rO   rO   rP   test_simple20	  s
   zTestParforBasic.test_simple20c                 C   r  )Nc                 S      t | | S rS   r  r  rO   rO   rP   r    rW   z0TestParforBasic.test_simple21.<locals>.test_implr  r  rO   rO   rP   test_simple21  r  zTestParforBasic.test_simple21c                 C   r  )Nc                 S   s   t | |  S rS   r-  r  rO   rO   rP   r    r   z0TestParforBasic.test_simple22.<locals>.test_implr  r  rO   rO   rP   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   yrO   rO   rP   r    s   "z0TestParforBasic.test_simple23.<locals>.test_implr  r  rO   rO   rP   test_simple23     zTestParforBasic.test_simple23c                 C   r  )Nc                  S   s2   d} t | | f}t | }t |d d |f S )Nr  )r   r  r|  r  )r   r"  rs   rO   rO   rP   r  %  s   
z0TestParforBasic.test_simple24.<locals>.test_implr  r  rO   rO   rP   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  rS   operatorrb  r  rO   rO   rP   r  /  rW   z:TestParforBasic.test_simple_operator_15.<locals>.test_implNr  r  rO   rO   rP   test_simple_operator_15,  s   z'TestParforBasic.test_simple_operator_15c                 C   r  )Nc                 S   s   t ||S rS   r  r  rO   rO   rP   r  6  rW   z:TestParforBasic.test_simple_operator_16.<locals>.test_implr  r  rO   rO   rP   test_simple_operator_164     z'TestParforBasic.test_simple_operator_16c                 C   r  )Nc                 S   s   t || S rS   r  r  rO   rO   rP   r  =  rW   z:TestParforBasic.test_simple_operator_17.<locals>.test_implr  r  rO   rO   rP   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   rO   rr   rO   rO   rP   r  D  s   z5TestParforBasic.test_inplace_alias.<locals>.test_implc                 S      t j| | d S rS   r   r   Zassert_equalrq   rO   rO   rP   comparerH  r   z4TestParforBasic.test_inplace_alias.<locals>.comparerr   r   r   r  r   )rN   r  r  r   rO   rO   rP   test_inplace_aliasB  s   
z"TestParforBasic.test_inplace_aliasN)"rd   rJ   re   r  r|   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r=   r  r<   r  r  r  r  r  r  r>   r  r  r  r  rO   rO   rO   rP   rw    sH    






rw  c                   @   s4   e Zd ZdZdd Zdd Zedd Zdd	 Zd
S )TestParforNumericalMiscz+ Miscellaneous 'classical' numerical tests c                 C   sH   dd }| j |ddd | t|tjfd | t|tjfd d S )Nc                 S   sJ   dt j|  d }dt j|  d }dt |d |d  dk  |  S )Nr   r   r   )r   randomranfr  )r   r   r  rO   rO   rP   r  T  s   "z2TestParforNumericalMisc.test_pi.<locals>.test_impli r   decimalr   )r   r   r   r   int64rY  intpr  rO   rO   rP   test_piS  s   zTestParforNumericalMisc.test_pic                 C   s*   t jd d  fd }| tt|d d S Nrl   r   )r   float64r   r   r  r}   rO   rO   rP   test_blackscholes]  s   z)TestParforNumericalMisc.test_blackscholesc                 C   s\   t jd d  t jd d d d f t jd d  t jf}| tt|d | tt|d d S Nr   r   )r   r  r  r   r   r  rf  r}   rO   rO   rP   test_logistic_regressionb  s
   ,z0TestParforNumericalMisc.test_logistic_regressionc                 C   s   t jd d}d}d}t j||f}t j||f}| jt||d|dd ttjddtj	tj	ttjddf}| 
tt|d d S )	Nr      r   r   r   r  r   C)r   r  seedr  r   r5  r   Arrayr  r  r   rl  )rN   r3  r/  Zcentersr"  r2  Zarg_typsrO   rO   rP   test_kmeansi  s   
z#TestParforNumericalMisc.test_kmeansN)	rd   rJ   re   r  r  r  r<   r  r  rO   rO   rO   rP   r  O  s    

r  c                   @   s   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestParforNumPyz'Tests NumPy functionality under parforsc                 C   s>   dd }t ddddd}t ddd}| ||| d S )Nc                 S      t | |S rS   r  rr   rr  rO   rO   rP   r    rW   z-TestParforNumPy.test_mvdot.<locals>.test_implr   r   r  r   r   )r   r   r   r   )rN   r  r"  rr  rO   rO   rP   
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 rS   r   r  r  )r   r"  r  Br  rO   rP   r    s   
zBTestParforNumPy.test_fuse_argmin_argmax_max_min.<locals>.test_impl   r   r   )r   r+  argmaxminmaxr   r   r   r   r  rY  r  r  rO   r  rP   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 rZ  r   r   r"  rO   rO   rP   r       zDTestParforNumPy.test_np_random_func_direct_import.<locals>.test_implr   r   r   r   r  r  rO   rO   rP   !test_np_random_func_direct_import  s   z1TestParforNumPy.test_np_random_func_direct_importc                 C   sf   dd }dd }dd }ddd	t d
dt dd
fD ]}| || | |d| | |d|d qd S )Nc                 S   
   t | S rS   r   r|  r   rO   rO   rP   
test_impl1  r  z/TestParforNumPy.test_arange.<locals>.test_impl1c                 S   r  rS   r  sr   rO   rO   rP   
test_impl2  rW   z/TestParforNumPy.test_arange.<locals>.test_impl2c                 S      t | ||S rS   r  r  r   trO   rO   rP   
test_impl3  r   z/TestParforNumPy.test_arange.<locals>.test_impl3            >@r   rl   r   complexr   rN   r  r  r  argrO   rO   rP   test_arange  s   zTestParforNumPy.test_arangec                 C   sP   dd }dd }dd }dD ]}|  || |  |d| |  |d|d qd S )	Nc                 S   s   t j| t jdS Nr  r   r|  float32r   rO   rO   rP   r    r  z5TestParforNumPy.test_arange_dtype.<locals>.test_impl1c                 S   s   t j| |t jdS r  r	  r  rO   rO   rP   r    r   z5TestParforNumPy.test_arange_dtype.<locals>.test_impl2c                 S   s   t j| ||t jdS r  r	  r  rO   rO   rP   r    r  z5TestParforNumPy.test_arange_dtype.<locals>.test_impl3)r   r  r  r   r  r  rO   rO   rP   test_arange_dtype  s   z!TestParforNumPy.test_arange_dtypec                 C   sR   dd }dd }dddt dd	t d	dfD ]}| |d
| | |d
|d qd S )Nc                 S   r  rS   r   )startstoprO   rO   rP   r    rW   z1TestParforNumPy.test_linspace.<locals>.test_impl1c                 S   r  rS   r   )r  r  numrO   rO   rP   r    r   z1TestParforNumPy.test_linspace.<locals>.test_impl2r   r  r  r   rl   r      r  )rN   r  r  r  rO   rO   rP   test_linspace  s   zTestParforNumPy.test_linspacec              	      s   dd }d}t j|}t jjd|dfd} ||  ||  t|ttj	ddfd  t|ttj	d	dfd  fd
d} 
||  || d S )Nc                 S      |   S rS   meanr"  rO   rO   rP   r    r  z,TestParforNumPy.test_mean.<locals>.test_impld   r   r   sizer   r  r   c                      
     dS r  r   rO   rU   rO   rP   <lambda>     
 z+TestParforNumPy.test_mean.<locals>.<lambda>r   r  r  randintr   r   r   r   r  r  r   r   )rN   r  r3  r"  r  data_genrO   rU   rP   	test_mean  s     zTestParforNumPy.test_meanc              	      s   dd }d}t j|}t jjd|dfd}|d|  } ||  ||  ||  t|ttj	dd	fd
  t|ttj	d
d	fd
  fdd} 
||  || d S )Nc                 S   r  rS   )varr  rO   rO   rP   r    r  z+TestParforNumPy.test_var.<locals>.test_implr  r   r   r                ?r   r  r   c                      r  r  r  rO   rU   rO   rP   r    r  z*TestParforNumPy.test_var.<locals>.<lambda>r  )rN   r  r3  r"  r  r  r  rO   rU   rP   test_var  s     zTestParforNumPy.test_varc                    s   dd }d}t j|}t jjd|dfd}|d|  } ||  ||  || ttjdd	f} t	||d
  t	||d
  fdd} 
||  || d S )Nc                 S   r  rS   )Zstdr  rO   rO   rP   r    r  z+TestParforNumPy.test_std.<locals>.test_implr  r   r   r  r!  r   r  r   c                      r  r  r  rO   rU   rO   rP   r    r  z*TestParforNumPy.test_std.<locals>.<lambda>)r   r  r  r  r   r   r  r  r   r   r   r   )rN   r  r3  r"  r  r  argtyr  rO   rU   rP   test_std  s   zTestParforNumPy.test_stdc                 C   s"   dd }|  t|tjfd dS )z
        Test function with only a random call to make sure a random function
        like ranf is actually translated to a parfor.
        c                 S   s   t j| | f}|S rS   )r   r  r  r  rO   rO   rP   r       z5TestParforNumPy.test_random_parfor.<locals>.test_implr   Nr  r  rO   rO   rP   test_random_parfor  s   z"TestParforNumPy.test_random_parforc                 C   s^   dd }d}|  |t|f}||}||}tjj||dd | t|t	j
fd d S )Nc                 S   s   t jj| | fd}t j| | }t jdd| | f}t jd| | f}t jjdd| | fd}t jddd| | f}t || | | | | S Nr          r  r   r   )highr  r   )	r   r  standard_normalr   normal	chisquarer  
triangularr  r   r"  r  r  r/  EFrO   rO   rP   r    s   z/TestParforNumPy.test_randoms.<locals>.test_implr  g?)Zrtolr   )r   r   r   r   r   r   assert_allcloser   r   r   r  rN   r  r   r   r   Z	py_outputrO   rO   rP   test_randoms  s   	
zTestParforNumPy.test_randomsc                 C   sX   dd }d}|  |t|f}||}||}| || | t|tjfd d S )Nc                 S   sv   t jj| | fd}t j| | }t jdd| | f}t jd| | f}t jjdd| | fd}t jddd| | f}dS r'  )r   r  r*  r   r+  r,  r  r-  r.  rO   rO   rP   r    s   z4TestParforNumPy.test_dead_randoms.<locals>.test_implr  r   )r   r   r   r   r   r   r   r  r2  rO   rO   rP   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  rS   r  r  rO   rO   rP   r  (  r  z,TestParforNumPy.test_min.<locals>.test_impl1c                 S   r  rS   )r   r  r  rO   rO   rP   r  +  r  z,TestParforNumPy.test_min.<locals>.test_impl2   r   r  zDzero-size array to reduction operation minimum which has no identityr  c                      r  r  r  rO   rU   rO   rP   r  F  r  z*TestParforNumPy.test_min.<locals>.<lambda>r   r  r  r  astypeint32r1  infr   r   r   r  r  r   r   r   r   r  r   r   rN   r  r  r   r"  r  r  r/  r   r   pcfuncer  rO   rU   rP   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  rS   )r  r  rO   rO   rP   r  M  r  z,TestParforNumPy.test_max.<locals>.test_impl1c                 S   r  rS   )r   r  r  rO   rO   rP   r  P  r  z,TestParforNumPy.test_max.<locals>.test_impl2r6  r   r  zDzero-size array to reduction operation maximum which has no identityr  c                      r  r  r  rO   rU   rO   rP   r  k  r  z*TestParforNumPy.test_max.<locals>.<lambda>r7  r;  rO   rU   rP   test_maxL  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  rS   )r  r  rO   rO   rP   r  r  r  z/TestParforNumPy.test_argmax.<locals>.test_impl1c                 S   r  rS   )r   r  r  rO   rO   rP   r  u  r  z/TestParforNumPy.test_argmax.<locals>.test_impl2r6  )r  r(  rz         @rz  r   r  r  r(  r@  rz  z*attempt to get argmax of an empty sequencer  c                      r  r  r  rO   rU   rO   rP   r    r  z-TestParforNumPy.test_argmax.<locals>.<lambda>r   r1  r  r  r8  r9  r  nanr   r   r   r  r  r   r   r   r   r  r   r   r;  rO   rU   rP   test_argmaxq  6   zTestParforNumPy.test_argmaxc              	      s|  dd }dd }d}t g d}t jjd|dt j}t j||f}t d	d
t jd
dg} ||  ||  ||  ||  ||  ||  ||  || d}||fD ]7}	 	|	t
jd d  f}
 t}|
t jg t jd W d    n1 sw   Y   |t|j qf fdd} ||  ||  ||  || d S )Nc                 S   r  rS   r*  r  rO   rO   rP   r    r  z/TestParforNumPy.test_argmin.<locals>.test_impl1c                 S   r  rS   )r   r+  r  rO   rO   rP   r    r  z/TestParforNumPy.test_argmin.<locals>.test_impl2r6  )r  r(  r@  r(  rz  r   r  r  r(  rz  z*attempt to get argmin of an empty sequencer  c                      r  r  r  rO   rU   rO   rP   r    r  z-TestParforNumPy.test_argmin.<locals>.<lambda>rA  r;  rO   rU   rP   test_argmin  rD  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   rO   rO   rP   r       
z4TestParforNumPy.test_ndarray_fill.<locals>.test_implr   r   r  r   zerosr   r   r  r  r   r   rN   r  r   r#  rO   rO   rP   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   rF  rG  rI  rK  rO   rO   rP   r    rL  z6TestParforNumPy.test_ndarray_fill2d.<locals>.test_implr   r   r   r  r   rM  rO  rO   rO   rP   test_ndarray_fill2d  rQ  z#TestParforNumPy.test_ndarray_fill2dc                 C   ,   dd }t g d}d}| ||| d S )Nc                 S   ^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S Nr   r  r   rG   r   rN  r  r  r   rr   rs   Zresult_matrixsub_azresult_datarO   rO   rP   r       z<TestParforNumPy.test_reshape_with_neg_one.<locals>.test_implr  r@  rz  r{        @      @rH  g       @g      "@      $@g      &@rx  r   r   r1  r   rN   r  rr   rs   rO   rO   rP   test_reshape_with_neg_one     
z)TestParforNumPy.test_reshape_with_neg_onec                 C   rT  )Nc                 S   rU  )Nr   r  r   irW  rX  rO   rO   rP   r    r\  z>TestParforNumPy.test_reshape_with_large_neg.<locals>.test_implr]  r   ra  rb  rO   rO   rP   test_reshape_with_large_neg  rd  z+TestParforNumPy.test_reshape_with_large_negc                 C   st   |  tj}tdddd }tg d}d}||| W d    n1 s(w   Y  d}| |t|j d S )NTparallelc                 S   s^   t j||dft jd}| d| }|j} | d }|dd}|| }||d d d d df< |S rV  rW  )rr   rs   ZrmrY  rZ  r[  rO   rO   rP   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   r1  r   r   r  )rN   raisedr  rr   rs   r   rO   rO   rP   "test_reshape_with_too_many_neg_one  s   

z2TestParforNumPy.test_reshape_with_too_many_neg_onec                 C   s"   dd }| j |tddd d S )Nc                 S   s2   t | t |  t |  t |  t |  S rS   )r   r  prodr  r  r   r   rO   rO   rP   r    s   2z0TestParforNumPy.test_0d_array.<locals>.test_impl   Fr   )r   r   r1  r  rO   rO   rP   test_0d_array  s   zTestParforNumPy.test_0d_arrayc                 C   sF   dd }t dd }| || | t|tjd d d fd d S )Nc                 S   s   t | jd | jd  S r  )r   r  realimag)rZ  rO   rO   rP   r    s   z6TestParforNumPy.test_real_imag_attr.<locals>.test_implrl   y      ?      ?r   )r   r|  r   r   r   r   r  )rN   r  rZ  rO   rO   rP   test_real_imag_attr
  s   $z#TestParforNumPy.test_real_imag_attrN)rd   rJ   re   r  r<   r  r  r  r  r  r  r  r"  r$  r&  r3  r4  r>  r?  rC  rE  rP  rS  rc  re  rj  rn  rq  rO   rO   rO   rP   r  z  s4    
	
%%$$		r  c                   @   s*   e Zd ZdZee dedd ZdS )TestParforsUnsupportedz$Tests for unsupported use of parforszOnly impacts 32 bit hardwarec                 C   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.
        Trf  c                 S   r  rS   r  r  rO   rO   rP   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  )rN   ri  rs  r"  rr  r   rO   rO   rP   #test_unsupported_combination_raises  s   
	z:TestParforsUnsupported.test_unsupported_combination_raisesN)	rd   rJ   re   r  unittestskipIfr;   r<   rv  rO   rO   rO   rP   rr    s
    rr  c                   @   sT  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zd d! Zd"d# Zed$d% Zed&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8dhdi Z9djdk Z:dldm Z;dndo Z<dpdq Z=drds Z>dtdu Z?dvdw Z@dxdy ZAdzd{ ZBd|d} ZCd~d ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdS )TestParforsz6 Tests cpython, reduction and various parfors featuresc                    s    dd }  | fdd d S )Nc                 S   s   | | | S rS   rO   )rr   r   r  rO   rO   rP   r  /  rW   z,TestParfors.test_arraymap.<locals>.test_implc                      r  Nr   r  rO   rU   rO   rP   r  2  r  z+TestParfors.test_arraymap.<locals>.<lambda>)r   r  rO   rU   rP   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   r1  r  r  r  r  rO   rO   rP   r  5     

z0TestParfors.test_0d_broadcast.<locals>.test_implrO   r   r   r   r   r  rO   rO   rP   test_0d_broadcast4     
zTestParfors.test_0d_broadcastc                 C   r|  )Nc                  S   s"   t d} t d}t | | S Nr}  )r   r  rN  r  r  rO   rO   rP   r  =  r  z-TestParfors.test_2d_parfor.<locals>.test_implrO   r   r  r  rO   rO   rP   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  rN  r  rO   rO   rP   case1E  s   

z)TestParfors.test_nd_parfor.<locals>.case1c                      s   t   dS r  )r	   r   rO   r  rN   rO   rP   r  J  s    z,TestParfors.test_nd_parfor.<locals>.<lambda>c                 S   s   t | | S rS   r-  r  rO   rO   rP   r  L  r   z-TestParfors.test_nd_parfor.<locals>.test_impl)r   r   )rN   r  r  rO   r  rP   test_nd_parforD  s
   zTestParfors.test_nd_parforc                    s,   ddl m   fdd}d}| || d S )Nr   r  c                    s    | }|d S rZ  rO   r  r  rO   rP   r  T  r  z9TestParfors.test_np_func_direct_import.<locals>.test_implo   )rh  r  r   rN   r  r   rO   r  rP   test_np_func_direct_importR  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 rS   r  )r   r   r"  r  rO   rO   rP   r  [  r  z2TestParfors.test_size_assertion.<locals>.test_implr   Trf  	   zSizes of A, B do not match)r   r  r  r
   r   r   r  )rN   r  r  r   r   rO   rO   rP   test_size_assertionZ  s   zTestParfors.test_size_assertionc                 C   s6   dd }d}t j|}t |}| |||| d S )Nc                 S   sT   t dD ]"}t|| d |d | d D ]}d||< | | dkr&d||< qq|S )Nr   r   r   r   r   r   )r   is_positiver3  r   r!  rO   rO   rP   r  i  s   "z'TestParfors.test_cfg.<locals>.test_implr  )r   r  randrN  r   )rN   r  r3  r   r  rO   rO   rP   test_cfgg  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 rS   r5  rq   rO   rO   rP   r  z  r  <TestParfors.test_reduce.<locals>.test_impl.<locals>.<lambda>r   )r"  Zinit_valrO   rO   rP   r  x  s   z*TestParfors.test_reduce.<locals>.test_implr6  r   r  c                  S   s   dd } t | tg ddS )Nc                 S   s   | d S r  rO   rK  rO   rO   rP   r        r  r   r   r   r   rl   r   )r   r   r1  )grO   rO   rP   r    s      c                 S   s   t | | dk S rz  r-  r  rO   rO   rP   r    r   c                 S   s&   | d d df }t | |dkdf S )Nr   r   r   r-  r"  r  rO   rO   rP   r    s   )   r   c                 S   s*   | d d df }t | |dkddf S )Nr   r   r   r   r-  r  rO   rO   rP   r    s   r   c                 S   s   t | }| | S rS   )r   Zamin)r"  Zmin_valrO   rO   rP   r       
)r   r  r  r   r  r8  r9  ZassertTypingErrorr   r   r   r   r  rN   r  r   r"  rO   rO   rP   test_reducew  s,   
&"zTestParfors.test_reducec                 C   X   dd }d}|  t}| |d}W d    n1 sw   Y  | |t|j d S )Nc                  S   s    d} t dD ]}t| } q| S rP  )r   cmathr  accr   rO   rO   rP   r    s   z9TestParfors.test_use_of_reduction_var1.<locals>.test_implCUse of reduction variable acc in an unsupported reduction function.rO   r  r   r   r   r   r  rN   r  r   r=  r<  rO   rO   rP   test_use_of_reduction_var1  s   z&TestParfors.test_use_of_reduction_var1c                 C   sZ   dd }d}|  tj}| |d}W d    n1 sw   Y  | |t|j d S )Nc                  S   s   d} t dD ]}| d } q| S Nr  r   r   r  rO   rO   rP   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.rO   )r  r   ZNumbaValueErrorr   r   r   r  r  rO   rO   rP   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  rO   rO   rP   r    s   z4TestParfors.test_unsupported_xor1.<locals>.test_implr  rO   r  r  rO   rO   rP   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 rS   r  r  rO   rO   rP   r    r  z8TestParfors.test_parfor_array_access1.<locals>.test_implr6  r   )r   r   rY  r   r  r  rO   rO   rP   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 rZ  )r   r  r   r   r   r   r"  r   r   rO   rO   rP   r    s   
z8TestParfors.test_parfor_array_access2.<locals>.test_implr6  r   r   r   rl  r   r  r  rO   rO   rP   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  rO   rO   rP   r    s   z8TestParfors.test_parfor_array_access3.<locals>.test_implr6  z Overwrite of parallel loop index)r  r   rh  r   r   r   r  )rN   r  r   r  rO   rO   rP   test_parfor_array_access3  s   z%TestParfors.test_parfor_array_access3c                 C   s.  dd }d}d}t j||f}t j|}| ||| t|ttjddttjddf\}}| t	|j
dko?d|j
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   r  rS   r  )r"  rs   rO   rO   rP   r    rW   z8TestParfors.test_parfor_array_access4.<locals>.test_implr6  r   r   r  r   r   FTrq  )r   r  r  r   rO  r   r  r  r  r   rI  rR  r   r   rE  rF  rS  r^  rd  r   r_  ri  rj  r  rm  r	  )rN   r  r   dr"  rs   rL  rN  rV  Zparfor_foundrF  rp  Zbuild_tuple_foundblrO   rO   rP   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   )rr   r   rO   rO   rP   r  '  s   z5TestParfors.test_parfor_dtype_type.<locals>.test_implr   r  )rN   r  rr   rO   rO   rP   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   r  r   r  r  r   rO   rO   rP   r  1  s
   z8TestParfors.test_parfor_array_access5.<locals>.test_implr6  r   r  r  rO   rO   rP   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   rO   rO   rP   r  ?  s   z8TestParfors.test_parfor_hoist_setitem.<locals>.test_implr   r  )rN   r  r  rO   rO   rP   test_parfor_hoist_setitem<  s   
z%TestParfors.test_parfor_hoist_setitemc                 C   sV   dd }d}d}|  ||| | t|tjtjfd | t|tjtjfd d S )Nc                 S   sF   t |}t | |f}t | }tdD ]}| t || }q|S rz  )r   r  r   r  )r3  r/  r  r  r  r   r  rO   rO   rP   r  J  s   

z8TestParfors.test_parfor_generate_fuse.<locals>.test_implr6  r   r   )r   r   rf  r   r  r   )rN   r  r   r  rO   rO   rP   test_parfor_generate_fuseG  s   	z%TestParfors.test_parfor_generate_fusec                 C   s>   dd }t dt j}t dt j}d|d< | ||| d S )Nc                 S   r  rS   )r   Zbitwise_andr  rO   rO   rP   r  [  rW   z.TestParfors.test_ufunc_expr.<locals>.test_implr   r   r   )r   r  Zuint8r   )rN   r  r"  r  rO   rO   rP   test_ufunc_exprY  s
   zTestParfors.test_ufunc_exprc                 C   r  )Nc                 S   s(   t | f}t| D ]}|d ||< q	|S )Nr@  )unsafe_emptyr   r   r"  r   rO   rO   rP   r  d  s   
z;TestParfors.test_find_callname_intrinsic.<locals>.test_implr   )r   rf  r   r  r  rO   rO   rP   test_find_callname_intrinsicc  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   rO   rO   rP   r  p  s   

z7TestParfors.test_reduction_var_reuse.<locals>.test_implr  r  r  rO   rO   rP   test_reduction_var_reusen  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   r0  )r"  condr  r   rO   rO   rP   r  }  s   z8TestParfors.test_non_identity_initial.<locals>.test_implr   boolr   r   r  r8  r  rO   rO   rP   test_non_identity_initial{  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  )r"  r  r  r  r   rO   rO   rP   r    s   

z9TestParfors.test_if_not_else_reduction.<locals>.test_implr   r  r  r  rO   rO   rP   test_if_not_else_reduction  s   $
z&TestParfors.test_if_not_else_reductionc                 C   r  )Nc                 S   sf   d}|d |d  }t |t j}t ||}t| D ]}||7 }qt| D ]}||7 }q*|S N   rk   r   r   r   rN  int_r|  r   r   r   r   shpr  result1tmpr   rO   rO   rP   r    s   

z?TestParfors.test_two_d_array_reduction_reuse.<locals>.test_implr  r  r  rO   rO   rP    test_two_d_array_reduction_reuse  s   z,TestParfors.test_two_d_array_reduction_reusec                 C   r  )Nc                 S   s6   t dt j}t| D ]}|t |gt j7 }q|S r  )r   rN  r  r   r   r1  )r   resultr   rO   rO   rP   r    s   z9TestParfors.test_one_d_array_reduction.<locals>.test_implr  r  r  rO   rO   rP   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  rO   rO   rP   r    s   
z9TestParfors.test_two_d_array_reduction.<locals>.test_implr  r  r  rO   rO   rP   test_two_d_array_reduction  s   z&TestParfors.test_two_d_array_reductionc                 C   r  )Nc                 S   sB   d}t |t j}t g d|}t| D ]}||7 }q|S )Nr   )r  r@  rz  r{  r^  r_  )r   rN  r
  r1  r   r   r   r   r  r  r  r   rO   rO   rP   r    s   
zJTestParfors.test_two_d_array_reduction_with_float_sizes.<locals>.test_implr  r  r  rO   rO   rP   +test_two_d_array_reduction_with_float_sizes  s   
z7TestParfors.test_two_d_array_reduction_with_float_sizesc                 C   r  )Nc                 S   s@   d}dt |t j }dt | }t| D ]}||9 }q|S )Nr  r   )r   r  r  Z	ones_liker   r   r  rO   rO   rP   r    s   
z>TestParfors.test_two_d_array_reduction_prod.<locals>.test_implr  r  r  rO   rO   rP   test_two_d_array_reduction_prod  s   
z+TestParfors.test_two_d_array_reduction_prodc                 C   r  )Nc                 S   s8   d}t |t j}t| D ]}|t |t j7 }q|S )N)r   r   rl  )r   rN  r  r   r   r  )r   r  r  r   rO   rO   rP   r    s
   z;TestParfors.test_three_d_array_reduction.<locals>.test_implr  r  r  rO   rO   rP   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  )Zargsortr  rO   rO   rP   r    rW   z>TestParfors.test_preparfor_canonicalize_kws.<locals>.test_implr6  r   r|  r   r  rO   rO   rP   test_preparfor_canonicalize_kws  s   
z+TestParfors.test_preparfor_canonicalize_kwsc                 C   sH   dd }t dt d}| |t|f}| |||| d S )Nc                 S   s   | j S rS   r  r  rO   rO   rP   r    s   z8TestParfors.test_preparfor_datetime64.<locals>.test_implr   zdatetime64[ns])r   rg  r  r   r   r   r   r   )rN   r  r"  r   rO   rO   rP   test_preparfor_datetime64  s   z%TestParfors.test_preparfor_datetime64c                 C   s    dd }|  |tjd d S )Nc                 S   sP   | j d }d}t|D ]}h d}|| d}|D ]}||7 }q||7 }q|S )Nr   >   r   r   r   )r0  r   rb  )r  r   r  r   Rr  r   rO   rO   rP   r    s   



zITestParfors.test_no_hoisting_with_member_function_call.<locals>.test_implr  )r   r   r  r  r  rO   rO   rP   *test_no_hoisting_with_member_function_call  s   z6TestParfors.test_no_hoisting_with_member_function_callc                 C      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   rN  r  r  rO   rO   rP   r    s   z8TestParfors.test_array_compare_scalar.<locals>.test_implNr  r  rO   rO   rP   test_array_compare_scalar  s   z%TestParfors.test_array_compare_scalarc                 C   s(   dd }t d}| j||ddd d S )Nc                 S   s0   t | }| d| }|r| d|d  }| S r  )r   r  )r   Zhalfr  ZparrrO   rO   rP   r    s
   z?TestParfors.test_array_analysis_optional_def.<locals>.test_implr  TFrm  r  rN   r  r   rO   rO   rP    test_array_analysis_optional_def  s   
z,TestParfors.test_array_analysis_optional_defc              
   C   sd   dd }t jdtd}t jdtd}| ||| | t|ttjddttjddfd d S )Nc                 S   s`   t jt| t jd}t|}t|D ]}| | ||< qt|D ]}|| ||  ||< q!|S r  )r   rg  r   r  r   r   )rr   rs   datar  r   rO   rO   rP   r    s   z7TestParfors.test_prange_side_effects.<locals>.test_implr  r  r   r  )	r   r|  floatr   r   r   r   r  r  )rN   r  r   r  rO   rO   rP   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 )Nry  rl  r   r   )r   r   r   rr   Zatuprs   r   rO   rO   rP   r  1  s
   "z*TestParfors.test_tuple1.<locals>.test_implr   r  r  rO   rO   rP   test_tuple10     
zTestParfors.test_tuple1c                 C   r  )Nc                 S   s:   | j }d}tt| D ]}| |  |d | 7  < q| S )Nrl  r   )r0  r   r   r   r  rO   rO   rP   r  <  s
   z*TestParfors.test_tuple2.<locals>.test_implr   r  r  rO   rO   rP   test_tuple2;  r  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   rl  r   rl   r   )r   r|  r   r   r   r  rO   rO   rP   r  G  s
   &z*TestParfors.test_tuple3.<locals>.test_implr   r  r  rO   rO   rP   test_tuple3F  r  zTestParfors.test_tuple3c                 C   r  )Nc                 S   sD   t ddd}d}tt| D ]}| |  |j|j | 7  < q| S Nr   r   rn   rl  )rm   r   r   r   ro   rp   rr   Zantuprs   r   rO   rO   rP   r  R  
   z/TestParfors.test_namedtuple1.<locals>.test_implr   r  r  rO   rO   rP   test_namedtuple1Q  r  zTestParfors.test_namedtuple1c                    s0   t dd  fdd}td}| || d S )NTestNamedTuple2rn   c                    sD    ddd}d}t t| D ]}| |  |j|j | 7  < q| S r  )r   r   r   ro   rp   r  r  rO   rP   r  ^  r  z/TestParfors.test_namedtuple2.<locals>.test_implr   )r   r   r|  r   r  rO   r  rP   test_namedtuple2\  s   

zTestParfors.test_namedtuple2c                 C   sB   t ddg}dd }dd }|tdd}| j|||gd	 d S )
NTestNamedTuple3r  c                 S   s   d| j d d < d S )Nrl   r  r  rO   rO   rP   r  m  r   z/TestParfors.test_namedtuple3.<locals>.test_implc                 S   s   t j| j|j d S rS   )r   r   r   r  rq   rO   rO   rP   r  p  r  z.TestParfors.test_namedtuple3.<locals>.comparerr   r  r  )r   r   rN  r   )rN   r  r  r  r   rO   rO   rP   test_namedtuple3h  s
   zTestParfors.test_namedtuple3c              
   C   sd   dd }t dd }t dd }| ||| | t|ttjddttjddfd d S )Nc                 S   s   || 7 }|S rS   rO   rq   rO   rO   rP   r  w     z1TestParfors.test_inplace_binop.<locals>.test_implr   r  r   r  )r   r|  r   r   r   r   r  r  rN   r  r  r  rO   rO   rP   test_inplace_binopv  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   rN  Zuint64rQ  rr   r   Zarray_shapeindicesZk_listr   r  rO   rO   rP   r    s   z0TestParfors.test_tuple_concat.<locals>.test_implr   ra  r  rO   rO   rP   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  rG   r  r   r  r   rO   rO   rP   r    s   zCTestParfors.test_tuple_concat_with_reverse_slice.<locals>.test_implr   ra  r  rO   rO   rP   $test_tuple_concat_with_reverse_slice  s   z0TestParfors.test_tuple_concat_with_reverse_slicec                 C   r  )Nc                 S   s   | f| | f }|d   S rZ  r  )rr   SrO   rO   rP   r    s   z6TestParfors.test_array_tuple_concat.<locals>.test_implr   r   r  r  rO   rO   rP   test_array_tuple_concat  s   
z#TestParfors.test_array_tuple_concatc                 C   r  )Nc                 S   s   | d S )Nr^  rO   rK  rO   rO   rP   r    r  z3TestParfors.test_high_dimension1.<locals>.test_impl)r   r   r   r   r      r  r  rO   rO   rP   test_high_dimension1  s   
z TestParfors.test_high_dimension1c                 C   $   dd }d}|  |t|| d S )Nc                 S      t |D ]}d| |< q| S r  r   Zpndindexr   szr   rO   rO   rP   r       
z-TestParfors.test_tuple_arg.<locals>.test_implr   rl   )r   r   rg  rN   r  r  rO   rO   rP   test_tuple_arg     zTestParfors.test_tuple_argc                 C   $   dd }d}|  |t|d d S )Nc                 S   r  r  r  r  rO   rO   rP   r    r  z=TestParfors.test_tuple_arg_not_whole_array.<locals>.test_implr  r   r   r   r   rN  r  rO   rO   rP   test_tuple_arg_not_whole_array  r  z*TestParfors.test_tuple_arg_not_whole_arrayc                 C   "   dd }d}|  |t| d S )Nc                 S       d}t |D ]}d| |< q| S )Nr  r   r  r  rO   rO   rP   r       
z6TestParfors.test_tuple_for_pndindex.<locals>.test_implr  r  r  rO   rO   rP   test_tuple_for_pndindex     z#TestParfors.test_tuple_for_pndindexc                 C   r  )Nc                 S   s$   |df}t |D ]}d| |< q	| S r  r  )r   firstr  r   rO   rO   rP   r    s   
z5TestParfors.test_tuple_arg_literal.<locals>.test_implr  r   r  r  rO   rO   rP   test_tuple_arg_literal  s   z"TestParfors.test_tuple_arg_literalc                    sX   dd dd  dd    fdd}t t d	d
fD ]}|| q#d S )Nc                 S   r  r  r  r  rO   rO   rP   r    r  z?TestParfors.test_tuple_of_literal_nonliteral.<locals>.test_implc                 S   s
   || dS )Nr  rO   )r   r   rO   rO   rP   r    r  z:TestParfors.test_tuple_of_literal_nonliteral.<locals>.callc                   S   r  )Nr  r   rN  rO   rO   rO   rP   r    r  z>TestParfors.test_tuple_of_literal_nonliteral.<locals>.<lambda>c                    s,   | }t  }| |}| d S rS   )r
   assertPreciseEqual)decf1f2gotr  expectedZ	get_inputrN   r  rO   rP   r     s   z;TestParfors.test_tuple_of_literal_nonliteral.<locals>.checkTrf  r
   )rN   r   r  rO   r%  rP    test_tuple_of_literal_nonliteral  s   
z,TestParfors.test_tuple_of_literal_nonliteralc                 C   r
  )Nc                 S   r  r  r  r  rO   rO   rP   r    r  z0TestParfors.test_tuple_arg_1d.<locals>.test_implr   r  r  rO   rO   rP   test_tuple_arg_1d  r  zTestParfors.test_tuple_arg_1dc                 C   r  )Nc                 S   r  Nr)  r   r  r  rO   rO   rP   r    r  z8TestParfors.test_tuple_arg_1d_literal.<locals>.test_implr)  r  r  rO   rO   rP   test_tuple_arg_1d_literal  r  z%TestParfors.test_tuple_arg_1d_literalc                 C       dd }|  |tdd d S )Nc                 S   r  r  r  r  rO   rO   rP   r    r  z4TestParfors.test_int_arg_pndindex.<locals>.test_implr  r   r  r  rO   rO   rP   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   r%  )ur   Zevenr  r!  rO   rO   rP   issue7854_proc  s   $z=TestParfors.test_prange_unknown_call1.<locals>.issue7854_procc                    sL   t d|d D ]	} | |d| qt d|d D ]	} | |d| q| S r  r   r   )r0  r  r   r1  rO   rP   r    s
   z8TestParfors.test_prange_unknown_call1.<locals>.test_implr   r   r   )
rA   r   rN  r   r  r   r  r   r   r   rN   r  r  r0  cptypesrO   r3  rP   test_prange_unknown_call1  s   
z%TestParfors.test_prange_unknown_call1c                 C   s\   dd }d}t ||f}tjd d d d df tjf}| t||d | ||| d S )Nc                 S   s   t d|d D ]!}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  )r0  r  r   r!  rO   rO   rP   r    s    z6TestParfors.test_prange_index_calc1.<locals>.test_implr   r   r   	r   rN  r   r  r   r  r   r   r   r4  rO   rO   rP   test_prange_index_calc1  s   	z#TestParfors.test_prange_index_calc1c                 C   s   dd }d}t ||f}t ||f}tjd d d d df tjd d d d df tjf}| t||d | |||| d S )Nc                 S   sp   t |D ]}t|D ]}|||f d | ||f< qqt |D ]}t|D ]}d|||f< q&q | d |d  S )Nr   r   r  r  )rr   rs   r  r   r!  rO   rO   rP   r  -  s   z9TestParfors.test_prange_reverse_order1.<locals>.test_implr   r   r   r7  rN   r  r  rr   rs   r5  rO   rO   rP   test_prange_reverse_order1*  s   	4z&TestParfors.test_prange_reverse_order1c                 C   sN   dd }d}t |}tjd d  tjf}| t||d | ||| d S )Nc                 S   s<   d}t |D ]}|| |< qt |D ]}|| d 7 }q|S )Nr   rl   r2  )rr   r  rs   r   rO   rO   rP   r  @  s   
z@TestParfors.test_prange_parfor_index_then_not.<locals>.test_implr   r   r7  )rN   r  r  rr   r5  rO   rO   rP   !test_prange_parfor_index_then_not=  s   
z-TestParfors.test_prange_parfor_index_then_notc                 C   sf   dd }d}t |}t|}tjd d  tjtj|tjf}| 	t
||d | |||| d S )Nc                 S   sL   d}t |D ]
}|||  | |< qt |D ]}|| | |d  7 }q|S rP  r2  )rr   tupr  r  r   rO   rO   rP   r  Q  s   zJTestParfors.test_prange_parfor_index_const_tuple_fusion.<locals>.test_implr   r   )r   rN  r   r   r  r   
containersZUniTupler  r   r   r   r9  rO   rO   rP   +test_prange_parfor_index_const_tuple_fusionN  s   
z7TestParfors.test_prange_parfor_index_const_tuple_fusionc                 C   sf   dd }d}t |}t |}tjd d  tjd d  tjf}| t||d | |||| d S )Nc                 S   sL   t |D ]}| d ||< qt |D ]}|| |< q|d  | d 7  < |S )Nrl   r   r2  )rr   rs   r  r   rO   rO   rP   r  e  s   
zITestParfors.test_prange_non_parfor_index_then_opposite.<locals>.test_implr   r   r7  r9  rO   rO   rP   *test_prange_non_parfor_index_then_oppositeb  s   	

 z6TestParfors.test_prange_non_parfor_index_then_oppositec                 C   sF   ddd}t d}| j||d t jjdd gd | | d d S )	Nc                 S   s"   t dD ]
}|d urd| |< qd S )Nr   r(  r  )arrpredr   rO   rO   rP   r  v  s
   z3TestParfors.test_prange_optional.<locals>.test_implr   c                 S   s   | |kS rS   rO   r   r  rO   rO   rP   r  ~  r  z2TestParfors.test_prange_optional.<locals>.<lambda>r  r`  rS   )r   r  r   r   r   r   r  rN   r  r@  rO   rO   rP   test_prange_optionalu  s   


z TestParfors.test_prange_optionalc                 C   r  )Nc                  S   s   d} | d S )Ng333333?g?r   rO   r  rO   rO   rP   r    s   z8TestParfors.test_untraced_value_tuple.<locals>.test_implr  r  r  rO   rO   rP   test_untraced_value_tuple  
   z%TestParfors.test_untraced_value_tuplec                 C   r  )Nc                  S   s   d} | d d S )N)rE  r   rO   r  rO   rO   rP   r    s   zBTestParfors.test_recursive_untraced_value_tuple.<locals>.test_implr  r  r  rO   rO   rP   #test_recursive_untraced_value_tuple  rG  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 )NrE  r   r   r(  r   r   rg  r  r   )r@  rr   Zn1Zarr2r   Zn2Zarr3r!  totalZn3r   rO   rO   rP   r    s   z9TestParfors.test_untraced_value_parfor.<locals>.test_implr   r  r   r  )r   r  r  r   r   r   r|  r   )rN   r  r  r@  rO   rO   rP   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 rP  )r   r0  )r   r  r   rO   rO   rP   r    s   
z;TestParfors.test_setitem_2d_one_replaced.<locals>.test_impl)r   r   r  r  rO   rO   rP   test_setitem_2d_one_replaced  s   
z(TestParfors.test_setitem_2d_one_replacedc                 C   sF   dd }t d}| ||dd | ||dd | ||dd d S )Nc                 S   s@   t | j}|r|t jS |r|| }n||d  }|| j S r  )r   r|  r  r8  r  )r@  Zflag1Zflag2invretrO   rO   rP   r    s   

z7TestParfors.test_1array_control_flow.<locals>.test_implr  TFr  rC  rO   rO   rP   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|  r  )r@  r4  flaginv1inv2rO  rO   rO   rP   r    s   z9TestParfors.test_2array_1_control_flow.<locals>.test_implr  r   TFr  rC  rO   rO   rP   test_2array_1_control_flow  s   
	z&TestParfors.test_2array_1_control_flowc                 C   rQ  )Nc                 S   sZ   t | j}t || j| }|r|| }|| }|| S ||d  }||d  }|| S r  rR  )r@  r4  rS  rT  rU  Zret1Zret2rO   rO   rP   r    s   z9TestParfors.test_2array_2_control_flow.<locals>.test_implr  r   TFr  rC  rO   rO   rP   test_2array_2_control_flow  s   
z&TestParfors.test_2array_2_control_flowc                 C   s.   dd }|  |d | t|tjfd d S )Nc                 S   s   t j| t jd}t j| t jd}t| D ]}t|D ]
}||  d7  < qqt| D ]}|dkr1q*|| ||d   ||< q*|dd  S )Nr  r   r   )r   rN  r  r   r   )r   rcr   r!  rO   rO   rP   r    s   z-TestParfors.test_issue8515.<locals>.test_implr  r   )r   r   r   r   r  r  rO   rO   rP   test_issue8515  s   zTestParfors.test_issue8515c                 C   s4   dd }|  |dd | t|tjtjfd d S )Nc                 S   s8   t d}t|}t d}tt| |}|| | S Nr  )r   r  r  ceilintr  )rr   rs   r  r  rY  rO   rO   rP   r  	  s
   


z:TestParfors.test_fusion_no_side_effects.<locals>.test_implg@g333333@r   )r   r   r   r   r  r  rO   rO   rP   test_fusion_no_side_effects 	  s   z'TestParfors.test_fusion_no_side_effectsN)Mrd   rJ   re   r  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r<   r  r  r  r>   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r(  r*  r,  r.  r6  r8  r:  r;  r>  r?  rD  rF  rH  rK  rM  rP  rV  rW  rZ  r^  rO   rO   rO   rP   ry  *  s    0
&





						

ry  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 rS   r   r   rO   rO   rP   r   	      zTestParforsLeaks.checkc                 C   4   t dddd }tdtj}| || d S )NTrf  c                 S   r  rS   r  )r@  rO   rO   rP   r  	     z2TestParforsLeaks.test_reduction.<locals>.test_implr   r
   r   r|  r8  r  r   rC  rO   rO   rP   test_reduction	  s   
zTestParforsLeaks.test_reductionc                 C   rb  )NTrf  c                 S   s@   d}d}t | jD ]}|| | 7 }|d| | d  7 }q	|| S )Nr(  r  r   )r   r  )r@  rr   rs   r   rO   rO   rP   r  	  s   z@TestParforsLeaks.test_multiple_reduction_vars.<locals>.test_implr   rd  rC  rO   rO   rP   test_multiple_reduction_vars	  s   
z-TestParforsLeaks.test_multiple_reduction_varsN)rd   rJ   re   r   re  rf  rO   rO   rO   rP   r_  	  s    	r_  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
dd Ze
dd Ze
dd Zdd Zdd Zdd Zdd Zdd Ze
dd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9S ):TestParforsSlicec                 C   rL  )Nc                 S   s,   | j \}| d|d  | d|d   }|S Nr   r   r   r0  rr   r   rs   rO   rO   rP   r  +	      z6TestParforsSlice.test_parfor_slice1.<locals>.test_implr   r   r   r  r  rO   rO   rP   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 rh  ri  rr   r   r   rs   rO   rO   rP   r  3	  s   z6TestParforsSlice.test_parfor_slice2.<locals>.test_implr   r  Trf  do not match	r   r   r  r  r  r
   r   r   r  r  rO   rO   rP   test_parfor_slice22	  s   z#TestParforsSlice.test_parfor_slice2c                 C   rL  )Nc                 S   s>   | j \}}| d|d d|d f | d|d|f  }|S rP  ri  ro  rO   rO   rP   r  @	  s   
0z6TestParforsSlice.test_parfor_slice3.<locals>.test_implr   r   rl  r  rO   rO   rP   test_parfor_slice3?	  rn  z#TestParforsSlice.test_parfor_slice3c                 C   rL  )Nc                 S   s:   | j \}}| d d d|d f | d d d|f  }|S rP  ri  ro  rO   rO   rP   r  H	     
,z6TestParforsSlice.test_parfor_slice4.<locals>.test_implrs  rl  r  rO   rO   rP   test_parfor_slice4G	  rn  z#TestParforsSlice.test_parfor_slice4c                 C   rL  )Nc                 S   s:   | j \}}| d|d d d f | d|d d f  }|S rP  ri  ro  rO   rO   rP   r  P	  ru  z6TestParforsSlice.test_parfor_slice5.<locals>.test_implrs  rl  r  rO   rO   rP   test_parfor_slice5O	  rn  z#TestParforsSlice.test_parfor_slice5c                 C   rL  )Nc                 S   s,   |   }| dd d f |d d df  }|S r  	transposerr   rs   rY  rO   rO   rP   r  X	  rk  z6TestParforsSlice.test_parfor_slice6.<locals>.test_implrs  rl  r  rO   rO   rP   test_parfor_slice6W	  rn  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  rx  rz  rO   rO   rP   r  `	  rk  z6TestParforsSlice.test_parfor_slice7.<locals>.test_implr  Trf  ry  rp  rq  r  rO   rO   rP   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  r0  ry  ro  rO   rO   rP   r  n	     
$z6TestParforsSlice.test_parfor_slice8.<locals>.test_implr  r  r   r   r|  r   r  rO   rO   rP   test_parfor_slice8l	     z#TestParforsSlice.test_parfor_slice8c                 C   r}  )Nc                 S   s:   | j \}}|  }| d d d|f |d|d|f< |S r  r~  ro  rO   rO   rP   r  x	  r  z6TestParforsSlice.test_parfor_slice9.<locals>.test_implr~  ry  r  r  rO   rO   rP   test_parfor_slice9v	  r  z#TestParforsSlice.test_parfor_slice9c                 C   r}  )Nc                 S   s2   | j \}}|  }| dd|f |dd|f< |S r  r~  ro  rO   rO   rP   r  	     
z7TestParforsSlice.test_parfor_slice10.<locals>.test_implr  r  r  r  rO   rO   rP   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  r0  r   )rr   r   r   r4  rs   rO   rO   rP   r  	  s   (z7TestParforsSlice.test_parfor_slice11.<locals>.test_impl   )r   r   r   r  r  rO   rO   rP   test_parfor_slice11	     z$TestParforsSlice.test_parfor_slice11c                 C   r}  )Nc                 S   s2   | j \}}|  }| dd df |dddf< |S )Nr   r   rG   r  ro  rO   rO   rP   r  	  r  z7TestParforsSlice.test_parfor_slice12.<locals>.test_implr~  ry  r  r  rO   rO   rP   test_parfor_slice12	  r  z$TestParforsSlice.test_parfor_slice12c                 C   r}  )Nc                 S   s<   | j \}}|  }d}| d| |d f |dd|f< |S )NrG   r   r   r  )rr   r   r   rs   rY  rO   rO   rP   r  	  s
   
"z7TestParforsSlice.test_parfor_slice13.<locals>.test_implr~  ry  r  r  rO   rO   rP   test_parfor_slice13	  s   z$TestParforsSlice.test_parfor_slice13c                 C   r}  )Nc                 S   s2   | j \}}|  }| dddf |dd df< |S )Nr   r   r   rG   r  ro  rO   rO   rP   r  	  r  z7TestParforsSlice.test_parfor_slice14.<locals>.test_implr~  ry  r  r  rO   rO   rP   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  ro  rO   rO   rP   r  	  s   
"z7TestParforsSlice.test_parfor_slice15.<locals>.test_implr~  ry  r  r  rO   rO   rP   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   ri  )rr   rs   r   rO   rO   rP   r  	  s   z7TestParforsSlice.test_parfor_slice16.<locals>.test_implr      Nr   )	r   r   r  rN  r   r  r  r   r   rN   r  r~   rO   rO   rP   test_parfor_slice16	  s    z$TestParforsSlice.test_parfor_slice16c                 C   s    dd }|  |dtd d S )Nc                 S   s$   t | }t|}||| d < |S rS   r   rN  r   )r   r"  r  r   rO   rO   rP   r  	  s   
z7TestParforsSlice.test_parfor_slice17.<locals>.test_implr   rl  r  rO   rO   rP   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   rl  r   r  r   )r   rN  r|  )rr   r  rO   rO   rP   r  	  s   
z7TestParforsSlice.test_parfor_slice18.<locals>.test_implr  r  rO   rO   rP   test_parfor_slice18	  s   z$TestParforsSlice.test_parfor_slice18c                 C   rL  )Nc                 S   s   | d d  d7  < | S rP  rO   r  rO   rO   rP   r  	     z7TestParforsSlice.test_parfor_slice19.<locals>.test_implr   rl  r  rO   rO   rP   test_parfor_slice19	     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   )rr   rY  r  rO   rO   rP   r  	  s   
z7TestParforsSlice.test_parfor_slice20.<locals>.test_implFrm  r  r  rO   rO   rP   test_parfor_slice20	  s   z$TestParforsSlice.test_parfor_slice20c                 C   s2   dd }t jd}t jd}| ||| d S )Nc                 S   s4   |  | jd} | |jd}| |d dd d f kS )Nr   rG   )r   r  )x1x2rO   rO   rP   r  	  s   z7TestParforsSlice.test_parfor_slice21.<locals>.test_implrl   r   )r   r  r  r   rN   r  r  r  rO   rO   rP   test_parfor_slice21	  s   z$TestParforsSlice.test_parfor_slice21c                 C   s.   dd }t d}t d}| ||| d S )Nc                 S   s0   t d}tdD ]}|| d d |f 7 }q	|S r+  )r   rN  r   )r  r  rs   r   rO   rO   rP   r  	  s   
z7TestParforsSlice.test_parfor_slice22.<locals>.test_impl)r   rl  r   )r   rN  r1  r   r  rO   rO   rP   test_parfor_slice22	  s   

z$TestParforsSlice.test_parfor_slice22c                 C   rL  )Nc                 S   s   d| d d< | S )Nr   r   rO   rK  rO   rO   rP   r  
     z7TestParforsSlice.test_parfor_slice23.<locals>.test_implr   rl  r  rO   rO   rP   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 rS   r  r   r"  r   r  r  rO   rO   rP   r  
     
z7TestParforsSlice.test_parfor_slice24.<locals>.test_implr  r   r   r   r   r  rN   r  r   rO   rO   rP   test_parfor_slice24

     z$TestParforsSlice.test_parfor_slice24c                 C   r  )Nc                 S   s*   t | }|d | }|d t| }|S rS   r  r  rO   rO   rP   r  
  r  z7TestParforsSlice.test_parfor_slice25.<locals>.test_implr  r  r   r  r  rO   rO   rP   test_parfor_slice25
  r  z$TestParforsSlice.test_parfor_slice25c                 C   rL  )Nc                 S   s.   | j \}|  }| dd ||d  d < |S )Nr  r   r   r  rj  rO   rO   rP   r  
  s   z7TestParforsSlice.test_parfor_slice26.<locals>.test_implr   r   r   r|  r  rO   rO   rP   test_parfor_slice26
  s   z$TestParforsSlice.test_parfor_slice26c                 C   rL  )Nc                 S   s@   d}t | jd D ]}| | dkr|d7 }|r| d | }q	dS rP  r  )rr   Zn_valid_valsr   ZunusedrO   rO   rP   r  *
  s   z7TestParforsSlice.test_parfor_slice27.<locals>.test_implr   r  r  rO   rO   rP   test_parfor_slice27'
  s   z$TestParforsSlice.test_parfor_slice27c                    s   t ddd t dd d t d ddt d d d t d d dfD ](  fdd}d}| || t|d	 |d	f} fd
d}| || qd S )Nr   r   r   rG   r  c                    sD   t | d | df}d}t| D ]}||| f  7 }q|S Nr   r   )r   r|  r   r   r   r  r  tsrO   rP   r  <
  s
   zHTestParforsSlice.test_parfor_array_access_lower_slice.<locals>.test_implr   r   c                    s2   d}t | jd D ]}|| | f  7 }q
|S rZ  )r   r   r0  r  )r  r  r   r  rO   rP   r  H
  s   )slicer   r   r|  r   rN   r  r   r  rO   r  rP   $test_parfor_array_access_lower_slice8
  s   z5TestParforsSlice.test_parfor_array_access_lower_sliceN) rd   rJ   re   rm  rr  rt  rv  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  rO   rO   rO   rP   rg  '	  sB    
	
	
			
		
	




	rg  c                   @   rv  )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   rO   rO   r   rO   rO   rP   r   X
  r   zMTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<listcomp>c                 S   s   | | S rS   rO   rB  rO   rO   rP   r  \
  r  zKTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<lambda>)r0  r   r  r1  r   r   r   )rr   r   rs   rY  r   rO   rO   rP   r  U
  s   

z9TestParforsOptions.test_parfor_options.<locals>.test_implr   r   F)fusionr   )r  comprehensionrl   )r  r  setitemr   )r  r  r  r   r   )r  r  r  r   	reductionr   )r  r  r  r   r  rh  r   )r   r   r  r   r  r   r   r  rO   rO   rP   test_parfor_optionsT
  s@   	z&TestParforsOptions.test_parfor_optionsN)rd   rJ   re   r  rO   rO   rO   rP   r  Q
  s    r  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestParforsBitMaskc                 C   r-  )Nc                 S   s   | |k}d| |< | S rZ  rO   rj  rO   rO   rP   r  {
  s   z:TestParforsBitMask.test_parfor_bitmask1.<locals>.test_implr   rl   r  r  rO   rO   rP   test_parfor_bitmask1z
  s   z'TestParforsBitMask.test_parfor_bitmask1c                 C   ,   dd }t d}|dk}| ||| d S )Nc                 S   s   d| |< | S rZ  rO   rq   rO   rO   rP   r  
  r  z:TestParforsBitMask.test_parfor_bitmask2.<locals>.test_implr   rl   r  rb  rO   rO   rP   test_parfor_bitmask2
     
z'TestParforsBitMask.test_parfor_bitmask2c                 C   r  )Nc                 S   s   | | | |< | S rS   rO   rq   rO   rO   rP   r  
  r  z:TestParforsBitMask.test_parfor_bitmask3.<locals>.test_implr   rl   r  rb  rO   rO   rP   test_parfor_bitmask3
  r  z'TestParforsBitMask.test_parfor_bitmask3c                 C   r  )Nc                 S   s   d|  | | |< | S r  rO   rq   rO   rO   rP   r  
  r%  z:TestParforsBitMask.test_parfor_bitmask4.<locals>.test_implr   rl   r  rb  rO   rO   rP   test_parfor_bitmask4
  r  z'TestParforsBitMask.test_parfor_bitmask4c                 C   r  )Nc                 S   s   | | | |  | |< | S rS   rO   rq   rO   rO   rP   r  
  r  z:TestParforsBitMask.test_parfor_bitmask5.<locals>.test_implr   rl   r  rb  rO   rO   rP   test_parfor_bitmask5
  r  z'TestParforsBitMask.test_parfor_bitmask5c                 C   sx   dd }t d}|dk}t t|}| t}| |||| W d    n1 s,w   Y  | dt|j	 d S )Nc                 S   s   || |< | S rS   rO   rz  rO   rO   rP   r  
  r  z:TestParforsBitMask.test_parfor_bitmask6.<locals>.test_implr   rl   r  )
r   r|  rN  r  r  r  r   r   r   r  )rN   r  rr   rs   rY  r  rO   rO   rP   test_parfor_bitmask6
  s   
z'TestParforsBitMask.test_parfor_bitmask6N)	rd   rJ   re   r  r  r  r  r  r  rO   rO   rO   rP   r  w
  s    				r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zedd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zed(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestParforsMiscz?
    Tests miscellaneous parts of ParallelAccelerator use.
    c                 C   s   dd }t ddd|}tjdd"}td tjddd	 tjdd
tjjdd |  W d    n1 s7w   Y  | t	|d dd |j
 D }| |dg d S )Nc                  S   s.   t d} t| jD ]
}| |  |7  < q
| S r[  )r   r  r   r  )r@  r   rO   rO   rP   r   
  s   
z9TestParforsMisc.test_no_warn_if_cache_set.<locals>.pyfuncT)rg  cacherecordalwaysignoreZ	typeguard)actionmodulez.*TBB_INTERFACE_VERSION.*znumba\.np\.ufunc\.parallel.*)r  messagecategoryr  r   c                 S   s   g | ]}|j jqS rO   )r   has_dynamic_globals)r   r   rO   rO   rP   r   
  s    z=TestParforsMisc.test_no_warn_if_cache_set.<locals>.<listcomp>F)r
   warningscatch_warningssimplefilterfilterwarningsr   r   ZNumbaWarningr   r   Z	overloadsrd  )rN   r   r   raised_warningsr  rO   rO   rP   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   rl  r   r  za[3]:r   )r   rN  r|  printr  rO   rO   rP   r   
  s
   
zITestParforsMisc.test_statement_reordering_respects_aliasing.<locals>.implrO   z	a[3]: 2.0)r   r5   r   getvaluer   r   )rN   r   r   stdoutlinerO   rO   rP   +test_statement_reordering_respects_aliasing
  s   
z;TestParforsMisc.test_statement_reordering_respects_aliasingc                 C   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   r  rS   )r   isinfr  rO   rO   rP   r  
  r  z;TestParforsMisc.test_parfor_ufunc_typing.<locals>.test_implr(  Trf  )
r   r1  r:  r
   r   rE  rF  sequential_parfor_loweringr   Zassert_array_equal)rN   r  r"  r   Zold_seq_flagrO   rO   rP   test_parfor_ufunc_typing
  s   

z(TestParforsMisc.test_parfor_ufunc_typingc                 C   s   dd }|  t|dd d S )Nc                  S   sD   d} g d}t jj  |}t dD ]}| || 7 } q| |d  S )Nr   r  rl   r   )r   rE  rF  Zinit_pranger   )resr@  dummyr   rO   rO   rP   r  
  s   z6TestParforsMisc.test_init_block_dce.<locals>.test_implrO   r   )r   r\  r  rO   rO   rP   test_init_block_dce
  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   rN  )r  rH   r  rO   rO   rP   r    s
   
zBTestParforsMisc.test_alias_analysis_for_parfor1.<locals>.test_implr  r  rO   rO   rP   test_alias_analysis_for_parfor1   s   z/TestParforsMisc.test_alias_analysis_for_parfor1c                    s   d t dddG  fdddtG fdddt}td|d	d
d }| tjjj | 	t
j}|  W d    n1 sBw   Y  |  t|j | tjjj d S )N
BROKEN_MSGTF)Zmutates_CFGZanalysis_onlyc                       s$   e Zd ZdZdd Z fddZdS )zVTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsZbreak_parforsc                 S   s   t |  d S rS   )r2   r|   rU   rO   rO   rP   r|     r   z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.__init__c                    sR   |j j D ] }|jD ]}t|tjjjr#G  fdddt	}| |_
q dS d S )Nc                          e Zd Z fddZdS )zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Brokenc                    s
   t  rS   )r   LoweringError)rN   otherr  rO   rP   
difference%  r  zzTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Broken.differenceN)rd   rJ   re   r  rO   r  rO   rP   Broken#      r  T)r7  rI  rd  rR  r   r   rE  rF  rS  r   Zraces)rN   r?  Zblkrp  r  r  rO   rP   run_pass  s   
z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_passN)rd   rJ   re   _namer|   r  rO   r  rO   rP   BreakParfors  s    r  c                       r  )z^TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompilerc                    s&   t | j}| t |  |gS rS   )r0   Zdefine_nopython_pipeliner?  Zadd_pass_afterr3   finalize)rN   pmr  rO   rP   define_pipelines.  s   zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompiler.define_pipelinesN)rd   rJ   re   r  rO   r  rO   rP   BreakParforsCompiler,  r  r  )rg  Zpipeline_classc                  S   s   d} t dD ]}| d7 } q| S r  r  )r   rH   rO   rO   rP   foo5  s   
zMTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.foo)r1   r2   r/   r
   assertFalser   rE  rF  r  r  r   r  r   r   r  )rN   r  r  r  rO   )r  r  rP   0test_no_state_change_in_gufunc_lowering_on_error  s   

	
z@TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_errorc                    s   G dd dt j}|dt|tj G dd dt}t|fdd}t|dd	 }t	|d
ddiddd }t
dd  t
 fdd}tjjj}| | z||  | tjjj W |tjj_d S |tjj_w )Nc                   @      e Zd ZdS )z2TestParforsMisc.test_issue_5098.<locals>.DummyTypeNrd   rJ   re   rO   rO   rO   rP   	DummyTypeH      r  Zmy_dummyc                   @   r  )z.TestParforsMisc.test_issue_5098.<locals>.DummyNr  rO   rO   rO   rP   DummyN  r  r  c                    s    S rS   rO   )valrY  )
dummy_typerO   rP   typeof_DummyQ     z5TestParforsMisc.test_issue_5098.<locals>.typeof_Dummyc                 S   s   t |j S rS   )r    contextZget_dummy_value)typobjrY  rO   rO   rP   unbox_indexU  s   z4TestParforsMisc.test_issue_5098.<locals>.unbox_indexmethod1rg  T)Zjit_optionsc                 S   s   dd }|S )Nc                 S   sp   dd }t |}tj|tjd}t|D ]}||| |||< qt|d D ]}||  ||| |7  < q&|S )Nc                 S   s    |   }tj|t| < ||S rS   )r   r   rB  r  )rr   frY  rO   rO   rP   baz\  s   zPTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foo.<locals>.bazr  r   rI  )r  r@  r   r  lengthZ
output_arrr   rO   rO   rP   _foo[  s   zCTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foorO   )r  r@  r   r  rO   rO   rP   _get_method1Y  s   z5TestParforsMisc.test_issue_5098.<locals>._get_method1c                 S   r  rS   r  )rr  rO   rO   rP   barj  rc  z,TestParforsMisc.test_issue_5098.<locals>.barc                    s   |  tg dg dg S )Nr  r@  rz  )r{  r^  r_  )r  r   r1  )r  )r  rO   rP   test1n  s   z.TestParforsMisc.test_issue_5098.<locals>.test1)r   ZOpaquer   r!   ZOpaqueModelobjectr   registerr   r   r
   r   rE  rF  r  r  )rN   r  r  r  r   r  r	  Z
save_staterO   )r  r  rP   test_issue_5098G  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 )
NTrf  c                 S   s&   d}d}t dD ]}|||  7 }q|S )N)r   r   r   r   r   r   r  )idxZbig_tuprZ  r   rO   rO   rP   oversize_tuple~  s
   zMTestParforsMisc.test_oversized_tuple_as_arg_to_kernel.<locals>.oversize_tupleZNUMBA_PARFOR_MAX_TUPLE_SIZE3r   zUse of a tuplezin a parallel region)r
   r7   r  r   ru  r   r  r   )rN   r  r  ZerrstrrO   rO   rP   %test_oversized_tuple_as_arg_to_kernel|  s   


z5TestParforsMisc.test_oversized_tuple_as_arg_to_kernelc                 C   sB   dd }d}t jjdd|d}t jjdd|d}| ||| d S )Nc                 S   s~   d}t j| j|| jd}| j}t|d D ]'}t|d D ]}| ||f |||f  | ||f |||f   |||f< qq|S Nr   r  r   )r   fullr0  r  r   )Zimg_nirZimg_red	fillvalueZout_imgdimsr  r   rO   rO   rP   	ndvi_njit  s   z1TestParforsMisc.test_issue5167.<locals>.ndvi_njit)r   r   r  g     @)lowr)  r  )r   r  uniformr   )rN   r  Z
tile_shapeZarray1Zarray2rO   rO   rP   test_issue5167  s
   
zTestParforsMisc.test_issue5167c                 C   s^   dd }t dd }tjjdd}t dd|| |d	}|| |d	}tj|| d S )
Nc                 S   s   t j| jd | jd ft jd}t| jd D ](}t|d | jd D ]}|| | | | g|R  }||||f< ||||f< q#q|S r  )r   rN  r0  r
  r   r   )rr   r,  Z	dist_argsr  r   r!  r  rO   rO   rP   
reproducer  s    z2TestParforsMisc.test_issue5065.<locals>.reproducerc                 S   s:   d}t | jd D ]}|| | ||  d 7 }q	t|S )Nr(  r   r   )r   r0  r   r  )r   r  r  r   rO   rO   rP   	euclidean  s   
z1TestParforsMisc.test_issue5065.<locals>.euclidean)rl   r   r  Trf  rO   )r
   r   r  r   r   r1  )rN   r  r  rr   r$  r&  rO   rO   rP   test_issue5065  s   	
zTestParforsMisc.test_issue5065c                 C   s,   dd }t dt df}| || d S )Nc                 S   s4   dgt |  }tt | D ]
}t | | ||< q|S rZ  )r   r   )myarrayr  r   rO   rO   rP   test_numba_parallel  s   z;TestParforsMisc.test_issue5001.<locals>.test_numba_parallelr  2   )r   rg  r   )rN   r  r  rO   rO   rP   test_issue5001  s   zTestParforsMisc.test_issue5001c                    s6   t dd  t dd fdd}|dgfd  d S )	Nc                 S   s   d S rS   rO   )gridsrO   rO   rP   r    r  z+TestParforsMisc.test_issue3169.<locals>.fooTrf  c                    s   t dD ]} |  qd S r  r  )r   r   r  rO   rP   r    s   
z+TestParforsMisc.test_issue3169.<locals>.barr   r   r'  )rN   r  rO   r!  rP   test_issue3169  s
   
zTestParforsMisc.test_issue3169c                    sD   t dd} fdd}tdddd  |d	d
d}| || d S )Nmytyperq   c                    s   t dD ]} ||  q| jS rz  )r   rr   )mydatar   innerrO   rP   outer  s   z-TestParforsMisc.test_issue4846.<locals>.outerT)Znogilc                 S   s   | |j f}| |jf}d S rS   rq   )r   r$  r  r  rO   rO   rP   r&    s   
z-TestParforsMisc.test_issue4846.<locals>.innerrr   rs   )r   r
   r   )rN   r#  r'  r$  rO   r%  rP   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   rr   r   rO   rO   rP   test1b  s
   z.TestParforsMisc.test_issue3748.<locals>.test1br  )rN   r)  rO   rO   rP   test_issue3748  s   zTestParforsMisc.test_issue3748c                 C   s,   dd }d}t j|td}| ||| d S )Nc                 S   s<   t | d D ]}t | d D ]}|d | || |< qq|S )Nr   r   g      @r  )r  r@  r   r  rO   rO   rP   parallel_test  s
   z5TestParforsMisc.test_issue5277.<locals>.parallel_testr  r  )r   rN  r]  r   )rN   r+  r  r@  rO   rO   rP   test_issue5277  s   zTestParforsMisc.test_issue5277c                 C   sL   t dddd }td}d}td}| |||||||| d S )NTrf  c                 S   s8   t dD ]}tdD ]}d|||f< q
q|r|d7 }|S r  )r   r   )r   methodr  r   r!  rO   rO   rP   r    s   z5TestParforsMisc.test_issue5570_ssa_races.<locals>.foo)rl   rl   9   rR  )r
   r   rN  r   py_func)rN   r  r   r-  r  rO   rO   rP   test_issue5570_ssa_races  s   



z(TestParforsMisc.test_issue5570_ssa_racesc                 C   sD   t dddd }tjd tjd}| |||| d S )NTrf  c                 S   s4   | }t ddD ]}||d d d d f }qt|S )Nr   r   )r   r   r  )r~   packagert  Zz_stackrO   rO   rP   find_maxima_3D_jit  s   
zDTestParforsMisc.test_issue6095_numpy_max.<locals>.find_maxima_3D_jitr   )r   r   r   )r
   r   r  r  r   r/  )rN   r2  r~   rO   rO   rP   test_issue6095_numpy_max  s   
z(TestParforsMisc.test_issue6095_numpy_maxc                 C   sJ   dd }d}d}t j||ft jd}t j||ft jd}| ||| d S )Nc                 S   sP   | j }|d }t|D ]}| |d d f ||d d f< ||df  d7  < q|S rP  )r0  r   )gggg_nextgsr  i_ggrO   rO   rP   r  !  s   z3TestParforsMisc.test_issue5942_1.<locals>.test_implr   r   r  )r   rN  r9  r   )rN   r  r  r   r4  r5  rO   rO   rP   test_issue5942_1  s   	z TestParforsMisc.test_issue5942_1c                 C   s"   dd }d}d}|  ||| d S )Nc                 S   s   t j| |ft jd}t j| |ft jd}t| D ]'}t|D ]}||||f< q||d d f ||d d f< ||df  d7  < q|S )Nr  r   r   )r   rN  r9  r   r   )r  r   r4  r5  r7  r   rO   rO   rP   r  3  s   z3TestParforsMisc.test_issue5942_2.<locals>.test_implr   r   r  )rN   r  r  r   rO   rO   rP   test_issue5942_21  s   z TestParforsMisc.test_issue5942_2c                 C   sB   t dddd }tg dg dg}| |||| d S )NTrf  c                 S   s   t | jd D ]?}tj}tjg dtjd}dD ]!}tj| |d d f | }||k r9|}tj|||gtjd}q| |d d f  |7  < q| S )Nr   )r   r   r   r  )r   r   rG   )r   r0  r   r:  r1  r
  r  Znorm)rX  r   r,  trr   Zdist_trO   rO   rP   r  H  s   z)TestParforsMisc.test_issue6102.<locals>.f)r(  r(  r(  )r(  r(  r  )r
   r   r1  r   r/  )rN   r  rX  rO   rO   rP   test_issue6102D  s   
zTestParforsMisc.test_issue6102c                 C   s    t dddd }| | d S )NTrf  c                  S   sP   d} t | f}t | d f}tt|D ]}t |||d  ||< q|S r  )r   r  rg  r   r   r  )r   Zna_maskr  r   rO   rO   rP   r  Y  s   z1TestParforsMisc.test_issue6774.<locals>.test_impl)r
   r   r  rO   rO   rP   test_issue6774X  s   
zTestParforsMisc.test_issue6774c                 C   r  )Nc                  S   s   t ttf} | S rS   )r   rN  _GLOBAL_INT_FOR_TESTING1_GLOBAL_INT_FOR_TESTING2bufrO   rO   rP   r  e     z9TestParforsMisc.test_issue4963_globals.<locals>.test_implr  r  rO   rO   rP   test_issue4963_globalsd  s   z&TestParforsMisc.test_issue4963_globalsc                    s$   d d fdd}|  | d S )Nrk   rl   c                     s   t  f} | S rS   r  r?  Z_FREEVAR_INT_FOR_TESTING1Z_FREEVAR_INT_FOR_TESTING2rO   rP   r  m  rA  z:TestParforsMisc.test_issue4963_freevars.<locals>.test_implr  r  rO   rC  rP   test_issue4963_freevarsj  s   z'TestParforsMisc.test_issue4963_freevarsN)rd   rJ   re   r  r  r  r  r  r  r  r  r  r  r  r  r"  r>   r(  r*  r,  r0  r3  r8  r9  r?   r;  r<  rB  rD  rO   rO   rO   rP   r  
  s6    <5

r  c                   @   st   e Zd Zdd Zdd Zdd Z			ddd	Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestParforsDiagnosticsc                 O   r`  rS   r   r   rO   rO   rP   r   v  ra  zTestParforsDiagnostics.checkc                 C   s$   |  |}|  |}| || d S rS   )_fusion_equivalentr   )rN   r$  r&  rr   rs   rO   rO   rP   assert_fusion_equivalencez  s   

z0TestParforsDiagnostics.assert_fusion_equivalencec                    sH   t t}t|  t| D ]} fdd|| D ||  < q|S )Nc                    s   g | ]}|  qS rO   rO   r   Zmin_keyrO   rP   r     r   z=TestParforsDiagnostics._fusion_equivalent.<locals>.<listcomp>)r   r   r  keyssorted)rN   thingnewr   rO   rH  rP   rF    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   rl   )r   Zcount_parforsrG  fusion_infonested_fusion_inforG  rd  r  hoisted_allocationsr   r5   r   dump)rN   r;  parfors_countrM  rN  rG  rO  replr   Zreplacedr   hoisted_allocsrO   rO   rP   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   rr   rs   rO   rO   rP   r    s   

z9TestParforsDiagnostics.test_array_expr.<locals>.test_implrO   parfor_diagnosticsr   r   r   rl   )rQ  rM  r   r   rH  rT  rN   r  r   r;  rO   rO   rP   test_array_expr  s   



z&TestParforsDiagnostics.test_array_exprc                 C   :   dd }|  | | |d}|jd }| j|dd d S )Nc                  S   s,   d} t | }t| D ]}|d ||< q|S rU  r   rg  r   )r   rr   r   rO   rO   rP   r    
   
z5TestParforsDiagnostics.test_prange.<locals>.test_implrO   rW  r   rQ  rX  rY  rO   rO   rP   test_prange  s
   

z"TestParforsDiagnostics.test_prangec                 C   sF   dd }|  | | |d}|jd }| tdd |jD  dS )zEmake sure original user variable name is used in fusion info
        c                  S   sj   d} t | }t |}t || }d}t| d D ]}t| d D ]}||| ||d   7 }q#q|S )Nr   r   r   r   )r   r  sincosr   )r   r   rr   rs   r  r   r!  rO   rO   rP   r    s   

z;TestParforsDiagnostics.test_user_varname.<locals>.test_implrO   rW  c                 s   s    | ]}d |j v V  qdS )zslice(0, n, 1)N)r  )r   rX  rO   rO   rP   rs    s    z;TestParforsDiagnostics.test_user_varname.<locals>.<genexpr>N)r   r   rH  r  anyZfusion_reportsrY  rO   rO   rP   test_user_varname  s   

z(TestParforsDiagnostics.test_user_varnamec                 C   sB   dd }|  | | |d}|jd }| j|dddgid d S )Nc                  S   sF   d} t | | f}t| D ]}t| D ]}|d | |||f< qq|S rU  r\  )r   rr   r   r!  rO   rO   rP   r    s   z<TestParforsDiagnostics.test_nested_prange.<locals>.test_implrO   rW  r   r   )rQ  rN  rX  rY  rO   rO   rP   test_nested_prange  s   


z)TestParforsDiagnostics.test_nested_prangec                 C   sF   dd }|  | | |d}|jd }| j|dddgidgd	 d S )
Nc                  S   s   d} t | }t |}|S rU  )r   r  r+  rV  rO   rO   rP   r    s   

zCTestParforsDiagnostics.test_function_replacement.<locals>.test_implrO   rW  r   r   r   )r+  rh  )rQ  rM  rG  rX  rY  rO   rO   rP   test_function_replacement  s   


z0TestParforsDiagnostics.test_function_replacementc                 C   r[  )Nc                  S   s4   d} t | d }d}t| D ]}||| 7 }q|S r  )r   r  r   )r   rr   r  r   rO   rO   rP   r    s   z8TestParforsDiagnostics.test_reduction.<locals>.test_implrO   rW  r   r^  rX  rY  rO   rO   rP   re    s
   

z%TestParforsDiagnostics.test_reductionc                 C   r[  )Nc                  S   s   d} t | }d|d d < |S )Nr   rl  r  )r   rr   rO   rO   rP   r    s   
z6TestParforsDiagnostics.test_setitem.<locals>.test_implrO   rW  r   r^  rX  rY  rO   rO   rP   test_setitem  s
   

z#TestParforsDiagnostics.test_setitemc                 C   r[  )Nc                  S   sL   d} d}d}t | D ]}t|f}t|D ]}|||< q||d 7 }q
|S )Nr   rl   r   rG   )r   r   rN  r   )r   r   r  r   tempr!  rO   rO   rP   r    s   
zBTestParforsDiagnostics.test_allocation_hoisting.<locals>.test_implrO   rW  r   )rO  rX  rY  rO   rO   rP   test_allocation_hoisting  s
   

z/TestParforsDiagnostics.test_allocation_hoisting)NNNNN)rd   rJ   re   r   rG  rF  rT  rZ  r_  rc  rd  re  re  rf  rh  rO   rO   rO   rP   rE  s  s     
rE  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}n^|jd}g }t|D ]}|j	dkrFt
|j|krF||jd  q0|d t|}t|d }	tjdkrad|	d>  }	t|j}t|t|kspJ |D ]
}
||
 }|	||< qrt|}|j||d	}t|t }|S )
z
        This function does the actual code augmentation to enable the explicit
        testing of `prange` calls in place of `range`.
        Nr   c                 S   s   g | ]
}|d kr
|ndqS )r   r   rO   r   rO   rO   rP   r   2  s    z7TestPrangeBase.generate_prange_func.<locals>.<listcomp>LOAD_GLOBALr   r   )r   r   )co_codeco_names)__code__r   rl  r   bytesrk  rt  disBytecodeopnamerB   r  r   offsetr   rC   Z	PYVERSION	bytearrayreplacepytypesFunctionTypeglobals)rN   r   patch_instanceZpyfunc_codeZprange_namesZnew_codeZ	range_idxZrange_locationsinstrZ
prange_idxr   r  Zprange_codepfuncrO   rO   rP   generate_prange_func%  s>   





z#TestPrangeBase.generate_prange_funcc                 O   s   | dd}| dd}| dd}| ||}tdd |D }| ||}	tjdd	}
td
 | ||}W 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

        rx  Nr   Fcheck_fastmath_resultc                 S   r   rO   r   r   rO   rO   rP   r     r   z0TestPrangeBase.prange_tester.<locals>.<listcomp>Tr  r  r   )r   r{  r   r   r  r  r  r   r  r   r   r   )rN   r   r~   r   rx  r   r|  rz  r   r   r  r   Z
fastcpfuncrO   rO   rP   prange_testerW  s"   A
zTestPrangeBase.prange_testerN)rd   rJ   re   r{  r}  rO   rO   rO   rP   ri  #  s    2ri  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   rN  r   r  rO   rO   rP   r    r]  z0TestPrangeBasic.test_prange01.<locals>.test_implr   Tr   r   r}  r  rO   rO   rP   test_prange01     
zTestPrangeBasic.test_prange01c                 C   r  )Nc                  S   s6   d} t | d }td| D ]
}d| ||d < q|S )Nr   r   r@  r  r  rO   rO   rP   r    s
   z0TestPrangeBasic.test_prange02.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange02  r  zTestPrangeBasic.test_prange02c                 C   r  )Nc                  S   s   d} t dD ]}| d7 } q| S Nr   r   r%  r  r   rO   rO   rP   r    r  z0TestPrangeBasic.test_prange03.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange03     
zTestPrangeBasic.test_prange03c                 C   r  )Nc                  S   s   d} t dD ]}| d9 } q| S )Nr   r   r   r%  r  rO   rO   rP   r    r  z3TestPrangeBasic.test_prange03mul.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange03mul  r  z TestPrangeBasic.test_prange03mulc                 C   r  )Nc                  S   s   d} t dD ]}| d8 } q| S )Nr  r   r   r%  r  rO   rO   rP   r    r  z3TestPrangeBasic.test_prange03sub.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange03sub  r  z TestPrangeBasic.test_prange03subc                 C   r  )Nc                  S   s   d} t dD ]}| d } q| S r  r%  r  rO   rO   rP   r    r  z3TestPrangeBasic.test_prange03div.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange03div  r  z TestPrangeBasic.test_prange03divc                 C   r  )Nc                  S   s>   d} d}t d}tdD ]}|| kr|||< qd||< q|S )Nr   r   r   r   r   rg  r   rr   rs   r"  r   rO   rO   rP   r    s   


z0TestPrangeBasic.test_prange04.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange04  s   

zTestPrangeBasic.test_prange04c                 C   r  )Nc                  S   s>   d} t j| t jd}d}td| d dD ]}||| 7 }q|S Nr   r  r   r   r   r  r  r   r   r"  r  r   rO   rO   rP   r    s   z0TestPrangeBasic.test_prange05.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange05      
zTestPrangeBasic.test_prange05c                 C   r  )Nc                  S   s:   d} t j| t jd}d}tdddD ]}||| 7 }q|S r  r  r  rO   rO   rP   r    s   z0TestPrangeBasic.test_prange06.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange06  r  zTestPrangeBasic.test_prange06c                 C   r  )Nc                  S   s8   d} t j| t jd}d}t| dD ]}||| 7 }q|S r  r  r  rO   rO   rP   r    s   z0TestPrangeBasic.test_prange07.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange07  r  zTestPrangeBasic.test_prange07c                 C   r  )Nc                  S   sF   d} t | }d}tt|D ]}tt|D ]}||| 7 }qq|S r  r   r  r   r   r   r"  r  r   r!  rO   rO   rP   r  "  s   
z0TestPrangeBasic.test_prange08.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange08!     
zTestPrangeBasic.test_prange08c                 C   r  )Nc                  S   s>   d} t | }d}tdD ]}tdD ]}||| 7 }qq|S r  r   r  r   r  rO   rO   rP   r  .  s   
z2TestPrangeBasic.test_prange08_1.<locals>.test_implr   Tr  r  r  rO   rO   rP   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   r%  )r   r  r   r!  rO   rO   rP   r  :  s   
z0TestPrangeBasic.test_prange09.<locals>.test_implr   r   Trx  r   r   r  r  rO   rO   rP   test_prange099  s
   

zTestPrangeBasic.test_prange09c                 C   r  )Nc                  S   s<   d} d}t | D ]}d}t | D ]}|d7 }q||7 }q|S r  r%  )r   Zacc2r!  Zacc1r   rO   rO   rP   r  G  s   

z0TestPrangeBasic.test_prange10.<locals>.test_implr   r   Tr  r  r  rO   rO   rP   test_prange10F  s
   


zTestPrangeBasic.test_prange10z1list append is not thread-safe yet (#2391, #2408)c                 C   r  )Nc                  S   s   d} dd t | D S )Nr   c                 S   r   rO   )r   r`  r   rO   rO   rP   r   Y  r   zDTestPrangeBasic.test_prange11.<locals>.test_impl.<locals>.<listcomp>r%  r   rO   rO   rP   r  W  s   z0TestPrangeBasic.test_prange11.<locals>.test_implr   Tr  r  r  rO   rO   rP   test_prange11U  s   
zTestPrangeBasic.test_prange11c                 C   r  )Nc                  S   s6   d} d}t |}tt| D ]}| || 7 } q| S r  r  )r  r   r  r   rO   rO   rP   r  ^  s   
z0TestPrangeBasic.test_prange12.<locals>.test_implr   Tr  r  r  rO   rO   rP   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 rP  r%  r  rO   rO   rP   r  i  r  z0TestPrangeBasic.test_prange13.<locals>.test_implr   r   Tr  )r}  r   r9  r  rO   rO   rP   test_prange13h  s   
zTestPrangeBasic.test_prange13c                 C   s&   dd }| j |tjdddd d S )Nc                 S   s*   d}t t| D ]
}|| | d 7 }q|S )Nr   r   r   r   )r"  r  r   rO   rO   rP   r  r  s   z0TestPrangeBasic.test_prange14.<locals>.test_implr   r   Tr  )r}  r   r  r  r  rO   rO   rP   test_prange14q  s
   
zTestPrangeBasic.test_prange14c                 C      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  )r3  r  r   r   rO   rO   rP   r    s
   
z0TestPrangeBasic.test_prange15.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange15~  s   

zTestPrangeBasic.test_prange15c                 C   r  )Nc                 S   s"   d}t |  | D ]}|d7 }q|S r  r%  r3  r  r   rO   rO   rP   r       
z0TestPrangeBasic.test_prange16.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange16     

zTestPrangeBasic.test_prange16c                 C   r  )Nc                 S   s0   d}t | }t|  | D ]}||| 7 }q|S rZ  r  r3  r  r  r   rO   rO   rP   r    s
   
z0TestPrangeBasic.test_prange17.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange17     

zTestPrangeBasic.test_prange17c                 C   r  )Nc                 S   sL   d}t | }t|  dD ]}||| 7 }td| D ]}||| 7 }qq|S )Nr   rl   r  )r3  r  r  r   r!  rO   rO   rP   r    s   
z0TestPrangeBasic.test_prange18.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange18     

zTestPrangeBasic.test_prange18c                 C   r  )Nc                 S   sR   d}| d }t | |f}t|  | D ]}t| |D ]
}||||f 7 }qq|S r  r  )r3  r  Mr  r   r!  rO   rO   rP   r    s   z0TestPrangeBasic.test_prange19.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange19  r  zTestPrangeBasic.test_prange19c                 C   r  )Nc                 S   s.   d}t | }td| D ]}||| 7 }q|S )Nr   rG   r  r  rO   rO   rP   r    s
   
z0TestPrangeBasic.test_prange20.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange20  r  zTestPrangeBasic.test_prange20c                 C   r  )Nc                 S   s    d}t ddD ]}|d7 }q|S )Nr   r  rG   r   r%  r  rO   rO   rP   r    r  z0TestPrangeBasic.test_prange21.<locals>.test_implr  r   Tr  r  r  rO   rO   rP   test_prange21  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   rG   rl  r  r  rO   rO   rP   r    s   



z0TestPrangeBasic.test_prange22.<locals>.test_implr   Tr   r   r|  r  r  rO   rO   rP   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 rS   r  r"  r   rO   rO   rP   r    s   
z0TestPrangeBasic.test_prange23.<locals>.test_impl    r   r   Tr  r   rN  r}  rN   r  r"  rO   rO   rP   test_prange23  
   

zTestPrangeBasic.test_prange23c                 C   r  )Nc                 S   s"   t t|  dD ]}|| |< q| S rZ  r  r  rO   rO   rP   r    s   
z0TestPrangeBasic.test_prange24.<locals>.test_implr  r   r   Tr  r  r  rO   rO   rP   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 rO   )r   
zeros_like)r   rH   r  rO   rP   r     r   zDTestPrangeBasic.test_prange25.<locals>.test_impl.<locals>.<listcomp>)r   r   )r"  r   r@  r   rO   r  rP   r    s
   z0TestPrangeBasic.test_prange25.<locals>.test_implr)  r   r   T)rx  r   r   r|  rW  r   )
r   r  r}  r   r   r   rH  rO  r   r   )rN   r  r"  r   r;  rS  rO   rO   rP   test_prange25  s   

zTestPrangeBasic.test_prange25c                 C   r  )Nc                 S   s,   | d d d }t t|D ]}|||< q| S rz  r  )r"  r  r   rO   rO   rP   r    s   
z0TestPrangeBasic.test_prange26.<locals>.test_implr  r   r   Tr  r  r  rO   rO   rP   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)rr   rs   rY  r!  r   rZ  rO   rO   rP   r  
  s
   z0TestPrangeBasic.test_prange27.<locals>.test_implr  )
r   r   r   r   r   r   r   r   r   r   r   r   r   Tr  )r}  r   r|  Zasarrayr  rO   rO   rP   test_prange27  s   
zTestPrangeBasic.test_prange27c              	   C   sx   dd }t ddgddgddgddgddgddgg}t ddgddgdd	gd	d
gd
dgg}| j|||dddd d S )Nc           
      S   sn   t t|}tdt|D ]&}||df }||df }| | }| | }|| }|d |d  }	|	||< q|S rP  )r   rN  r   r   )
r   r  r  r  Zi0i1ZPt1ZPt2rr  Zvl2rO   rO   rP   r    s   
z0TestPrangeBasic.test_prange28.<locals>.test_impl      r  r(  r   r   r   r   r   rl   r   Tr  )r   r1  r}  r  rO   rO   rP   test_prange28  s"   


zTestPrangeBasic.test_prange28c                 C   s$   dd }|  |d |  |d d S )Nc                 S   s<   d}| rt dD ]}|d7 }q|S t dD ]}|d8 }q|S )Nr   r   r   r%  )rS  r  r   rO   rO   rP   r  9  s   

z0TestPrangeBasic.test_prange29.<locals>.test_implTFr  r  rO   rO   rP   test_prange297  s   
zTestPrangeBasic.test_prange29c                 C   s>   dd }t t ddd}t 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  )r0  r   r   rN  r  r   )
r   parZ
numthreadsZn_parZn_xr  Zchunklenr   r  r  rO   rO   rP   r  H  s   
*z0TestPrangeBasic.test_prange30.<locals>.test_implr   r   r  r  r   )r   r1  r|  r}  )rN   r  r   r  rO   rO   rP   test_prange30F  s   zTestPrangeBasic.test_prange30N)(rd   rJ   re   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rw  skipr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO   rO   rO   rP   r~    sJ    

				
		

	


r~  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zed2d3 Zed4d5 Zd6S )7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   r%  r   rY  r   rO   rO   rP   r  a     zRTestPrangeSpecific.test_prange_two_instances_same_reduction_var.<locals>.test_implr  r  r  rO   rO   rP   ,test_prange_two_instances_same_reduction_var_  s   z?TestPrangeSpecific.test_prange_two_instances_same_reduction_varc                 C   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  r%  r  rO   rO   rP   r  k  r  zKTestPrangeSpecific.test_prange_conflicting_reduction_ops.<locals>.test_implr  zBReduction variable c has multiple conflicting reduction operators.)r  r   ZUnsupportedErrorr}  r   r   r  rN   r  r  r   rO   rO   rP   %test_prange_conflicting_reduction_opsj  s   z8TestPrangeSpecific.test_prange_conflicting_reduction_opsc                 C   r  )Nc                  S   sJ   d } }t dD ]}|dkr| d7 } qtd}|d r |d7 }q| |fS )Nr   r   r   r  r  r  )r"  r  r   r   rO   rO   rP   r  {  s   

zLTestPrangeSpecific.test_prange_two_conditional_reductions.<locals>.test_implr  r  rO   rO   rP   &test_prange_two_conditional_reductionsy  s   
z9TestPrangeSpecific.test_prange_two_conditional_reductionsc                 C   r  )Nc                  S   s4   d} t dD ]}t dD ]
}|dkr| d7 } qq| S rP  r%  )r"  r   r   rO   rO   rP   r    s   zCTestPrangeSpecific.test_prange_nested_reduction1.<locals>.test_implr  r  rO   rO   rP   test_prange_nested_reduction1  s   z0TestPrangeSpecific.test_prange_nested_reduction1c                 C   s   dd }|  t}|  W 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   r  r  rO   rO   rP   r    r]  z<TestPrangeSpecific.test_check_error_model.<locals>.test_implrO   r   )	r  ZeroDivisionErrorr{  r   r   r   r   r   r:  )rN   r  r  rz  ZpcresZpfcresr  rO   rO   rP   test_check_error_model  s   
z)TestPrangeSpecific.test_check_error_modelc           
      C   s   dd }t ddd}| j||dddd | |d }tt|g}| ||}| 	|}|
 D ]\}}| D ]}	d	|	v rQ||	v rQ| |	d
d  nq<q4d S )Nc                 S   s*   t t| D ]}| | }d|d d < q| S r  r  )r"  r   r  rO   rO   rP   r    s   z?TestPrangeSpecific.test_check_alias_analysis.<locals>.test_implr  r   r  r   Tr  ZdefineZnoaliasr   )r   rN  r   r}  r{  r   r   r   r   r   r	  r   r   r  )
rN   r  r"  rz  r   r   r
  r   rr  r  rO   rO   rP   test_check_alias_analysis  s    

z,TestPrangeSpecific.test_check_alias_analysisc                 C   r  )Nc                 S   s"   d}t d| dD ]}|d7 }q|S r  r%  r  rO   rO   rP   r    r  zJTestPrangeSpecific.test_prange_raises_invalid_step_size.<locals>.test_implr  z4Only constant step size of 1 is supported for prange)r  r   rh  r}  r   r   r  r  rO   rO   rP   $test_prange_raises_invalid_step_size  s   z7TestPrangeSpecific.test_prange_raises_invalid_step_sizec                 C   s   dd }| j |ddd | |d }| |d}| |}d}d}t|||f }td	|||f }| D ]$\}	}
|
 }t|D ]\}}|	|rO nqD| 
|	||d
   q8d S )Nc                  S   s&   d} d}t | D ]}||d 7 }q|S )Nr  r   r@  r%  r  rO   rO   rP   r    s
   zFTestPrangeSpecific.test_prange_fastmath_check_works.<locals>.test_implr   Tr  rO   z%[A-Z_0-9]?(.[0-9]+)+[.]?[i]?z)\s+%s = fmul fast double %s, 5.000000e-01z\s+%s = fadd fast double %s, %sr   )r}  r{  r   r   r   compiler	  r   rQ  r  r  )rN   r  rz  r   r   Z_idZ
recipr_strZreciprocal_instZ	fadd_instr   Zkernelr   r   r   rO   rO   rP    test_prange_fastmath_check_works  s*   

z3TestPrangeSpecific.test_prange_fastmath_check_worksc                 C   r  )Nc                 S   s8   t | | f}|d }t| D ]}|d ||< q| S rP  r   rN  r   r  )r   rs   rr   r!  rO   rO   rP   r    s
   z8TestPrangeSpecific.test_parfor_alias1.<locals>.test_implr   r  r  rO   rO   rP   test_parfor_alias1  s   z%TestPrangeSpecific.test_parfor_alias1c                 C   r  )Nc                 S   sF   t | | f}t| D ]}|| }t| D ]}|| ||< qq| S rS   r  )r   rs   r   rr   r!  rO   rO   rP   r    s   z8TestPrangeSpecific.test_parfor_alias2.<locals>.test_implr   r  r  rO   rO   rP   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 rS   r  )r   rs   r   rr   r!  rY  r   rO   rO   rP   r     s   z8TestPrangeSpecific.test_parfor_alias3.<locals>.test_implr   r  r  rO   rO   rP   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 rS   r%  )r   r  r!  r   rO   rO   rP   r    s   z8TestPrangeSpecific.test_parfor_race_1.<locals>.test_implr   r  r   zVariable k used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results.)r}  r   r   r  )rN   r  r  Zwarning_objZexpected_msgrO   rO   rP   test_parfor_race_1  s
   z%TestPrangeSpecific.test_parfor_race_1c                 C   r  )a   issue 3686: if a prange has something inside it that causes
            a nested parfor to be generated and both the inner and outer
            parfor use the same call variable defined outside the parfors
            then ensure that when that call variable is pushed into the
            parfor that the call variable isn't duplicated with the same
            name resulting in a redundant type lock.
        c                  S   sf   d} t j}tdD ]}|d}| |t dd 7 } q	tdD ]}|d}| |t dd 7 } q| S )Nr   r   r  r   )r   negativer   rN  )r  r  r   this_mattersrO   rO   rP   r    s   zGTestPrangeSpecific.test_nested_parfor_push_call_vars.<locals>.test_implNr  r  rO   rO   rP   !test_nested_parfor_push_call_vars  s   z4TestPrangeSpecific.test_nested_parfor_push_call_varsc                 C   sD   dd }d}t |||f}t j|t jd}| j|||dgd dS )a+   issue4903: a global is copied next to a parfor so that
            it can be inlined into the parfor and thus not have to be
            passed to the parfor (i.e., an unsupported function type).
            This global needs to be renamed in the block into which
            it is copied.
        c                 S   s   t t|}t t|}tdD ]*}|| }t|D ]}|t | ||f 7 }qt|D ]}|t | ||f 7 }q.q||fS r  )r   rN  r   r   r  )zztcZlhlcr   ntr  rO   rO   rP   r  3  s   zATestPrangeSpecific.test_copy_global_for_parfor.<locals>.test_implr   r  r   )rx  N)r   r  r  r}  )rN   r  r   r  r  rO   rO   rP   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   r  )r   r  r   )r   r  r  r   r  rO   rO   rP   r  D  s   zGTestPrangeSpecific.test_multiple_call_getattr_object.<locals>.test_implr  r  r  rO   rO   rP   !test_multiple_call_getattr_objectC  r  z4TestPrangeSpecific.test_multiple_call_getattr_objectc                 C   s   dd }t jddtfdtfgd}t jddtfdtfgd}t jddtfdtfgd}|t j}|t j}|t j}t||}tt||}	t|dd}
t|
|}| ||	 | || d S )	Nc                 S   s    t t| D ]}d| j|< q| S rG  )r   r   r   )r   r   rO   rO   rP   r  P  s   zHTestPrangeSpecific.test_argument_alias_recarray_field.<locals>.test_implr   r   r  r  Trf  )	r   rN  r  r]  viewZrecarrayr   r
   r   )rN   r  ZX1ZX2ZX3r  r  Zv3
python_resnjit_respa_funcpa_resrO   rO   rP   "test_argument_alias_recarray_fieldN  s   z5TestPrangeSpecific.test_argument_alias_recarray_fieldc                    s\   t dd   fdd}|d}t |d}t |dd}|d}| || | || dS )	z issue3699: test that mutable variable to call in loop
            is not hoisted.  The call in test_impl forces a manual
            check here rather than using prange_tester.
        c                 S   s"   | d }| d d }|  | |S )z If the variable X is hoisted in the test_impl prange
                then subsequent list_check calls would return increasing
                values.
            rG   r   )r   )r  rO  rr   rO   rO   rP   
list_checki  s   
z>TestPrangeSpecific.test_mutable_list_param.<locals>.list_checkc                    s    t | D ]	}dg} |}q|S r[  r  )r   r   r  rr   r  rO   rP   r  s  s   
z=TestPrangeSpecific.test_mutable_list_param.<locals>.test_implr   Trf  Nr
   r   )rN   r  r  r  r  r  rO   r  rP   test_mutable_list_paramd  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 rO   )r   r   rK  rO   rP   r     s    zXTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl.<locals>.<listcomp>)r   r1  r   r   rK  rO   rK  rP   r        zDTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl)r   r   r   r  r   r   )r   r1  r]  r}  r  rO   rO   rP   test_list_comprehension_prange  s   $z1TestPrangeSpecific.test_list_comprehension_prangec                 C   s,   dd }t jdt jd}| ||dd d S )Nc                 S   sZ   t | j}t| jd D ]}| | d d }|dkrd}|dkr#d}|||g||< q|S )Nr   g     o@)r   rN  r0  r   )imagerr   rs   rg  r   rX  hrO   rO   rP   r    s   z>TestPrangeSpecific.test_ssa_false_reduction.<locals>.test_implr  r  r   )r   rN  r9  r}  )rN   r  r  rO   rO   rP   test_ssa_false_reduction  s   z+TestPrangeSpecific.test_ssa_false_reductionc                 C   r  )Nc                  S   s@   d} t j| t jd}tdD ]}dg}d|d< |d ||< q|S )Nrl   r  r   r   )r   rg  r  r   )r   rr   r   r  rO   rO   rP   r    s   z@TestPrangeSpecific.test_list_setitem_hoisting.<locals>.test_implr  r  rO   rO   rP   test_list_setitem_hoisting  s   	z-TestPrangeSpecific.test_list_setitem_hoistingc                 C   sB   t dt jfg}dd }dd }| j|t jd|d|gd d S )	Nr   c                 S   s   t dD ]}d| | d< qd S )Nr   r   r%  )statesr   rO   rO   rP   r    s   z?TestPrangeSpecific.test_record_array_setitem.<locals>.test_implc                 S   s    | d d |d d ksJ d S )Nr   r   rO   rq   rO   rO   rP   r    r  z>TestPrangeSpecific.test_record_array_setitem.<locals>.comparerr   )r0  r  r  )r   r  r9  r}  rN  )rN   state_dtyper  r  rO   rO   rP   test_record_array_setitem  s   
z,TestPrangeSpecific.test_record_array_setitemc                 C   sF   t dt jfg}dd }t jd|d}dd }| j|||gd d S )	Nr   c                 S   s*   | j }t| j D ]
}d| | d |< q| S )Nrl  r   )r  r   )r  r   r   rO   rO   rP   r    s   zKTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.test_implr   r  c                 S   r  rS   r  rq   rO   rO   rP   r    r   zJTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.comparerr  )r   r  r  rN  r}  )rN   r  r  r  r  rO   rO   rP   %test_record_array_setitem_yield_array  s   
z8TestPrangeSpecific.test_record_array_setitem_yield_arrayc                 C   s   dd }|  |dd d S )Nc                 S   s`   t | f}|dkrt| D ]
}||  d7  < q|d S t| D ]
}||  d7  < q!|d S )Nr   r   r   r  )r  caser  r   rO   rO   rP   r    s   z4TestPrangeSpecific.test_issue7501.<locals>.test_implr   r   r  r  rO   rO   rP   test_issue7501  s   
z!TestPrangeSpecific.test_issue7501c                 C   s(   dd }d}t j|}| || d S )Nc           
      S   s   d}t 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   r1  r0  r   r  r  r  r  )
r  rs   Zpointsr3  r   Zexpsr   pr  r   rO   rO   rP   r    s   


2z6TestPrangeSpecific.test_kde_example.<locals>.test_implr  )r   r  r  r}  r  rO   rO   rP   test_kde_example  s   z#TestPrangeSpecific.test_kde_examplec                 C   s.   t jtjddgdt jd}| d|  d S )Nz-mz#numba.tests.parfors_max_label_errorr  )rI   stderrzTEST PASSED)subpcheck_outputsys
executableSTDOUTr   decode)rN   r  rO   rO   rP   test_issue_due_to_max_label  s   
z.TestPrangeSpecific.test_issue_due_to_max_labelc                 C   r  )Nc                 S   s6   t | }t | }tt| D ]}| ||< q|S rS   )r   r  ra  r   r   r  )r   r"  r  r   rO   rO   rP   r    s
   

z4TestPrangeSpecific.test_issue7578.<locals>.test_implr`  )r   r|  r}  r  rO   rO   rP   test_issue7578  s   
	z!TestPrangeSpecific.test_issue7578N) rd   rJ   re   r  r  r  r  r  r>   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r:   r
  r  rO   rO   rO   rP   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 rZ  r   rU   rO   rO   rP   setUp	  rW   zTestParforChunksizing.setUpc                 C   r  rZ  r  rU   rO   rO   rP   tearDown  rW   zTestParforChunksizing.tearDownc                 C   s>   |  t d td |  t d td |  t d d S Nr   r  )r   r   r   rU   rO   rO   rP   $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   rU   rO   rO   rP   test_python_with_chunksize  s
   
z0TestParforChunksizing.test_python_with_chunksizec                 C   sV   t dd }t dd }| | d |d | | d |d | | d d S )Nc                   S   s   t  S rS   )r   rO   rO   rO   rP   get_cs   s   zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.get_csc                 S   s   t | S rS   r  rK  rO   rO   rP   set_cs$  rc  zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.set_csr   r  r  )rN   r  r  rO   rO   rP   "test_njit_parallel_chunksize_basic  s   

z8TestParforChunksizing.test_njit_parallel_chunksize_basicc                 C   sB   t dd }|d\}}}| |d | |d | |d d S )Nc                 S   sD   t  }td t  }W d    n1 sw   Y  t  }|||fS )Nr  )r   r   )r   cs1cs2cs3rO   rO   rP   r  0  s   

zATestParforChunksizing.test_njit_with_chunksize.<locals>.test_implr  r   r  )rN   r  r  r  r  rO   rO   rP   test_njit_with_chunksize.  s   
z.TestParforChunksizing.test_njit_with_chunksizec                 C   sh   t dddd }dD ]&}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. Trf  c                 S   sr   t |}t |d}t|  t|D ]}t ||< d||< qW d    ||fS 1 s0w   Y  ||fS )Nir  )r   rN  r  r   r   r   r   )csr   r  inner_csr   rO   rO   rP   r  C  s   


zLTestParforChunksizing.test_all_iterations_reset_chunksize.<locals>.test_impl)i  i  i  i  r  r   r  r   N)r
   r   r  r   all)rN   r  r!  r   r  r  rO   rO   rP   #test_all_iterations_reset_chunksize>  s   
z9TestParforChunksizing.test_all_iterations_reset_chunksizec                 C   sV   |  t}tdd }|  W d    n1 sw   Y  d}| |t|j d S )Nc                   S   r  )NrG   r  rO   rO   rO   rP   neg_testY  rt  zMTestParforChunksizing.test_njit_parallel_chunksize_negative.<locals>.neg_test/chunksize must be greater than or equal to zero)r  r   r
   r   r   r  )rN   ri  r  r   rO   rO   rP   %test_njit_parallel_chunksize_negativeV  s   
z;TestParforChunksizing.test_njit_parallel_chunksize_negativec                 C   L   |  t}td W d    n1 sw   Y  d}| |t|j d S )NrG   r   )r  r   r   r   r   r  rN   ri  r   rO   rO   rP   'test_python_parallel_chunksize_negativeb  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  rO   rO   rO   rP   r   l  rt  zMTestParforChunksizing.test_njit_parallel_chunksize_invalid_type.<locals>.impl)The parallel chunksize must be an integer)r  r   ZTypingErrorr
   r   r   r  )rN   ri  r   r   rO   rO   rP   )test_njit_parallel_chunksize_invalid_typej  s   
z?TestParforChunksizing.test_njit_parallel_chunksize_invalid_typec                 C   r"  )Nr%  r&  )r  	TypeErrorr   r   r   r  r#  rO   rO   rP   +test_python_parallel_chunksize_invalid_typeu  s
   
zATestParforChunksizing.test_python_parallel_chunksize_invalid_typeN)rd   rJ   re   r  rf   r  r  r  r  r  r  r  r!  r$  r'  r)  rO   rO   rO   rP   r    s    r  c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )TestParforsVectorizerFc              	   O   s\  | dd}| dd}| dd}| dd}||d	}	g }
|	 D ]\}}|
t|| 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 )Nrz   Fcpu_namezskylake-avx512
assertionsTcpu_featuresz-prefer-256-bit)ZNUMBA_CPU_NAMEZNUMBA_CPU_FEATURESr   r   c                 S   r   rO   r   r   rO   rO   rP   r     r   z8TestParforsVectorizer.get_gufunc_asm.<locals>.<listcomp>z%call\s+\w+\*\s+@do_scheduling_(\w+)\()r   r	  r   r7   r   r{  r   r   r   r   r  findallr   r   r   r   r   ZassertNotEqual)rN   r   Zschedule_typer~   r   rz   r+  r,  r-  Zenv_optsZ	overridesr   rr  r   Zpfunc_vectorizabler   asmZschedtymatchesrO   rO   rP   get_gufunc_asm  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 rZ  r   r   r   r  )r"  r   r  r   rO   rO   rP   will_vectorize  s
   zJTestParforsVectorizer.test_vectorizer_fastmath_asm.<locals>.will_vectorizer   r   Trz   FZvaddpdvsqrtpd__svml_sqrtzmmvsqrtsdZvaddsdN)r   rN  r1  rd  r  )rN   r4  r  Zfast_asmZslow_asmrr  rO   rO   rP   test_vectorizer_fastmath_asm  s&   



z2TestParforsVectorizer.test_vectorizer_fastmath_asmc                 C   s   dd }dd }t d}tdd | j|d|d	d
}| j|d|d	d
}W d   n1 s/w   Y  | D ]}| d|v | d|v  | d|v q8| D ]}| d|v p_d|v  | d|v  | d|v  qTdS )r2  c                 S   s0   t | }t| dD ]}t| | | |< q
| S rZ  r3  r"  r   r   rO   rO   rP   will_not_vectorize  s   zTTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_not_vectorizec                 S   s,   t | }t|D ]}t| | | |< q| S rS   r3  r;  rO   rO   rP   r4    s   zPTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_vectorizer   NUMBA_BOUNDSCHECK0r   Tr5  r   Nr6  r9  r8  r7  Zvmovupd)r   rN  r7   r1  rd  r  )rN   r<  r4  r  Z	novec_asmZvec_asmrr  rO   rO   rP   "test_unsigned_refusal_to_vectorize  s(   


z8TestParforsVectorizer.test_unsigned_refusal_to_vectorizec                 C   s"  dd }dd }t dd | j|ddd	}| j|d
dd	}W d   n1 s(w   Y  dd }| D ]\}}||} | D ]\}}||}	 ddlm}
 | t|t|	 t||	D ].\}}||kriq`|
dd ||}| }|D ]}|d dkr| ||d |d  d qwq`dS )z This checks vectorization for signed vs unsigned variants of a
        trivial accumulator, the only meaningful difference should be the
        presence of signed vs. unsigned unpack instructions (for the
        induction var).
        c                  S   s&   d} d}t |  dD ]}||7 }q
|S )N   r(  r   r%  r  rO   rO   rP   signed_variant  s
   
zMTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.signed_variantc                  S   s"   d} d}t | D ]}||7 }q|S )Nr@  r(  r%  r  rO   rO   rP   unsigned_variant  s
   
zOTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.unsigned_variantr=  r>  r   Tr5  r   Nc                 S   s`   g }|   D ]'}| }|dkr-|ds-|ds-|ds-d|v s-|tdd| q|S )N rF   rH   "r   z[	])r   strip
startswithr   r   sub)r/  r  r   ZspdrO   rO   rP   strip_instrs  s   zKTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.strip_instrsr   )SequenceMatcherc                 S   s   | dkS )N	rO   rK  rO   rO   rP   r  9  r  zGTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.<lambda>insertr  rG   r0  )	r7   r1  r	  difflibrI  r   r   r   Zget_opcodes)rN   rA  rB  Z
signed_asmZunsigned_asmrH  r   rr  Zsigned_instrZunsigned_instrsmrr   rs   r  r  r  rO   rO   rP   test_signed_vs_unsigned_vec_asm  s<   	z5TestParforsVectorizer.test_signed_vs_unsigned_vec_asmN)	rd   rJ   re   rf   r1  r8   r:  r?  rN  rO   rO   rO   rP   r*  }  s    %
'
+r*  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	 TestParforReductionSetNumThreadszCTest execution correctness on reductions with set_num_threads.
    c                    P   t j}d|  |d tdd fdd}|}|}| || d S )Nr   r   Trf  c                    s@   d}t |  t D ]}d|  }t | t }||7 }q
|S rP  r   r   r   Znthreadsr  r   Z
local_maskZgntr  maskrO   rP   udtI     
z6TestParforReductionSetNumThreads.test_add.<locals>.udtr   NUMBA_NUM_THREADSr
   r/  r   rN   r3  rU  expectr$  rO   rS  rP   test_addD     

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

z)TestParforReductionSetNumThreads.test_mulc                    rP  )Nr   r   Trf  c                    sB   d}t |  t D ]}d|  }t | t }t||}q
|S r  )r   r   r   r  rR  rS  rO   rP   rU  s  s   z6TestParforReductionSetNumThreads.test_max.<locals>.udtrW  rY  rO   rS  rP   r?  n  r\  z)TestParforReductionSetNumThreads.test_maxN)rd   rJ   re   r  r[  r]  r?  rO   rO   rO   rP   rO  @  s
    rO  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4ZNUMBA_PARALLEL_DIAGNOSTICSTrf  c                  S   s.   d} t j| t jd}t| D ]}d||< q|S )Nr  r  r   )r   rN  r  r   )r   rs   r   rO   rO   rP   r     s
   
z<TestDiagnosticEnvVar.test_diagnostics_env_var1.<locals>.implzParallel Accelerator Optimizing)osenvironr5   r
   r  r   )rN   r  r   Z
the_outputrO   rO   rP   test_diagnostics_env_var1  s   


z.TestDiagnosticEnvVar.test_diagnostics_env_var1N)rd   rJ   re   r4   Zrun_test_in_subprocessrb  rO   rO   rO   rP   r^    s    r^  __main__rS   )r  r   ro  r   r`  rg   r  
subprocessr   ru  r  	functoolsr   rh  r   Znumpy.randomr   r  collectionsr   r   r   	itertoolsr   r	   r  Znumba.parfors.parforr   r
   r   r   r   r   r   r   r   Z
numba.corer   r   r   r   r   r   r   r   r   Znumba.extendingr   r   r   r   r    r!   Znumba.core.registryr"   Znumba.core.annotationsr#   Znumba.core.ir_utilsr$   r%   r&   r'   r(   r)   r*   Znumba.np.unsafe.ndarrayr+   r  Znumba.core.bytecoder,   Znumba.core.compilerr-   r.   r/   r0   Znumba.core.compiler_machineryr1   r2   Znumba.core.typed_passesr3   Znumba.tests.supportr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Znumba.core.extendingrA   rB   rC   r  rw  rD   rx  rh   Zx86_onlyr=  r>  rm   rt   ru   r  r  r5  rO  r   rY  r\  rW  rf  re  rl  rk  rn  r
  r=  rw  r  r  rr  ry  r_  rg  r  r  r  rE  ri  r~  r  r  r*  rO  r^  rd   mainrO   rO   rO   rP   <module>   s   (0 $<=
	  $B	
" ,*          g  +%=   @ 0    '   )z BB
