U
    iâËdwg ã                   @   sp  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z
d dlZd dlmZ d dlZd dlmZ d dlZd dlmZmZ d dlZd dlmZmZ d dlZd dlZd dlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ d dl%m	Z	m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d d	l/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d d
l6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZD d dlEmFZF d dlGmHZHmIZImJZJmKZK d dlLmMZMmNZN d dlOmPZP d dlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^ d dl_m`Z` d dlEmaZa d dl%mbZb d dlcZcd dldZdeXG dd„ deRƒƒZeed fe g¡ dkd¡ZhdZidZjeddƒZkdd„ Zle^G d d!„ d!eRƒƒZmd"d#„ Znd$d%„ Zod&d'„ Zpd(d)„ Zqd*d+„ Zrd,d-„ Zsd.d/„ Ztd0d1„ Zud2d3„ Zvd4d5„ Zwd6d7„ Zxdcd8d9„Zyd:d;„ ZzG d<d=„ d=e{ƒZ|eXG d>d?„ d?emƒƒZ}eXG d@dA„ dAemƒƒZ~eXG dBdC„ dCemƒƒZG dDdE„ dEeRƒZ€eXG dFdG„ dGemƒƒZ�eXG dHdI„ dIeTemƒƒZ‚eXG dJdK„ dKemƒƒZƒeXG dLdM„ dMemƒƒZ„eXG dNdO„ dOemƒƒZ…eXG dPdQ„ dQemƒƒZ†eXG dRdS„ dSemƒƒZ‡G dTdU„ dUemƒZˆeXG dVdW„ dWeˆƒƒZ‰eXG dXdY„ dYeˆƒƒZŠeXG dZd[„ d[eRƒƒZ‹eXehG d\d]„ d]eˆƒƒƒZŒeXG d^d_„ d_eRƒƒZ�eXG d`da„ daeRƒƒZŽe�dbk�rled �¡  dS )dé    )ÚsqrtN©Úreduce©Úrandn)ÚdefaultdictÚ
namedtuple)ÚcycleÚchain)ÚnjitÚprangeÚparallel_chunksizeÚget_parallel_chunksizeÚset_parallel_chunksizeÚset_num_threadsÚget_num_threadsÚtypeof)
ÚtypesÚ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© rP   úQ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_parfors.pyÚrunnerP   s    þzTestParforsRunner.runnerc                 C   s   |   ¡  d S ©N©rR   ©rO   rP   rP   rQ   Útest_TestParforBasicX   s    z&TestParforsRunner.test_TestParforBasicc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforNumericalMisc[   s    z.TestParforsRunner.test_TestParforNumericalMiscc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforNumPy^   s    z&TestParforsRunner.test_TestParforNumPyc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsa   s    z"TestParforsRunner.test_TestParforsc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsBitMaskd   s    z)TestParforsRunner.test_TestParforsBitMaskc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsDiagnosticsg   s    z-TestParforsRunner.test_TestParforsDiagnosticsc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsLeaksj   s    z'TestParforsRunner.test_TestParforsLeaksc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsMiscm   s    z&TestParforsRunner.test_TestParforsMiscc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsOptionsp   s    z)TestParforsRunner.test_TestParforsOptionsc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsSlices   s    z'TestParforsRunner.test_TestParforsSlicec                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestParforsVectorizerv   s    z,TestParforsRunner.test_TestParforsVectorizerc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestPrangeBasicy   s    z&TestParforsRunner.test_TestPrangeBasicc                 C   s   |   ¡  d S rS   rT   rU   rP   rP   rQ   Útest_TestPrangeSpecific|   s    z)TestParforsRunner.test_TestPrangeSpecificN)Ú__name__rK   Ú__qualname__Ú_numba_parallel_test_ÚplatformÚmachinerN   rR   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rP   rP   rP   rQ   rE   B   s    rE   )Ú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.
    NrP   ©ÚaÚbrP   rP   rQ   Únull_comparerˆ   s    rs   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Úsuperrt   Ú__init__©rO   Úargs©Ú	__class__rP   rQ   r{   ›   s    zTestParforsBase.__init__c                 C   s   t |||d�S ©N)Úflags)r.   )rO   ÚfuncÚsigr�   rP   rP   rQ   Ú_compile_this¬   s    zTestParforsBase._compile_thisc                 C   s   | j ||| jd�S r€   )r„   rv   ©rO   r‚   rƒ   rP   rP   rQ   Úcompile_parallel¯   s    z TestParforsBase.compile_parallelc                 C   s   | j ||| jd�S r€   )r„   rx   r…   rP   rP   rQ   Úcompile_parallel_fastmath²   s    z)TestParforsBase.compile_parallel_fastmathc                 C   s   | j ||| jd�S r€   )r„   ru   r…   rP   rP   rQ   Úcompile_njitµ   s    zTestParforsBase.compile_njitc                 O   s2   t dd„ |D ƒƒ}|  ||¡}|  ||¡}||fS )Nc                 S   s   g | ]}t  |¡‘qS rP   ©Únumbar   ©Ú.0ÚxrP   rP   rQ   Ú
<listcomp>¹   s     z/TestParforsBase.compile_all.<locals>.<listcomp>)Útupler†   rˆ   )rO   Úpyfuncr}   Úkwargsrƒ   ÚcpfuncÚcfuncrP   rP   rQ   Úcompile_all¸   s    zTestParforsBase.compile_allc                 O   sF  |  dd¡}|  dd¡}|  dd¡}|  dd¡}	|  dd¡}
dd	„ }||Ž }||Ž }||Ž }|j|Ž }||Ž }|j|Ž }|
dkrºtjj||f|Ž tjj||f|Ž |  t|ƒt|ƒ¡ nLt|ƒt|
ƒksÎt‚t	||||
ƒD ](\}}}}|||f|Ž |||f|Ž qÜ|	�r|  
||¡ |dk	�rB|j||Ž Ž }tjj||f|Ž dS )
a-  
        Checks python, njit and parfor impls produce the same result.

        Arguments:
            pyfunc - the python function to test
            cfunc - CompilerResult from njit of pyfunc
            cpfunc - CompilerResult from njit(parallel=True) of pyfunc
            args - arguments for the function being tested
        Keyword Arguments:
            scheduler_type - 'signed', 'unsigned' or None, default is None.
                           Supply in cases where the presence of a specific
                           scheduler is to be asserted.
            fastmath_pcres - a fastmath parallel compile result, if supplied
                             will be run to make sure the result is correct
            check_arg_equality - some functions need to check that a
                                 parameter is modified rather than a certain
                                 value returned.  If this keyword argument
                                 is supplied, it should be a list of
                                 comparison functions such that the i'th
                                 function in the list is used to compare the
                                 i'th parameter of the njit and parallel=True
                                 functions against the i'th parameter of the
                                 standard Python function, asserting if they
                                 differ.  The length of this list must be equal
                                 to the number of parameters to the function.
                                 The null comparator is available for use
                                 when you do not desire to test if some
                                 particular parameter is changed.
            Remaining kwargs are passed to np.testing.assert_almost_equal
        Úscheduler_typeNÚcheck_fastmathÚfastmath_pcresÚcheck_schedulingTÚcheck_arg_equalityc                  W   sÈ   | s
t ƒ S g }| D ]¬}t|tjƒr4| | d¡¡ qt|tjƒrP| | ¡ ¡ qt|tjƒrh| |¡ q|d kr|| |¡ qt|t ƒr˜| t 	|¡¡ qt|t
ƒr¶| |d d … ¡ qtdƒ‚qt |ƒS )NÚkz%Unsupported argument type encountered)r�   Ú
isinstanceÚnpZndarrayÚappendÚcopyÚnumberÚnumbersÚNumberÚdeepcopyÚlistÚ
ValueError)r}   Únew_argsr�   rP   rP   rQ   Ú	copy_argsè   s$    


z:TestParforsBase.check_parfors_vs_others.<locals>.copy_args)ÚpopÚentry_pointrœ   ÚtestingÚassert_almost_equalÚassertEqualÚtypeÚlenÚAssertionErrorÚzipr˜   )rO   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_outputrP   rP   rQ   Úcheck_parfors_vs_othersÃ   s@    

   ÿ
ÿz'TestParforsBase.check_parfors_vs_othersc                 O   s.   | j |f|žŽ \}}| j|||f|ž|Ž dS )z‹Checks that pyfunc compiles for *args under parallel=True and njit
        and asserts that all version execute and produce the same resultN©r”   r±   ©rO   r�   r}   r‘   r“   r’   rP   rP   rQ   Úcheck  s    zTestParforsBase.checkc              
   K   sB   |ƒ D ]6}|   ttt|ƒƒ¡� | j|f|ž|Ž W 5 Q R X qdS )zHRun self.check(impl, ...) on array data generated from arg_gen.
        N)ÚsubTestr£   Úmapr   r´   )rO   ÚimplÚarg_genr‘   r}   rP   rP   rQ   Úcheck_variants#  s    
zTestParforsBase.check_variantsc              
   K   sP   |ƒ D ]D}|   ttt|ƒƒ¡�& ttt|ƒƒ}|  t||ƒd¡ W 5 Q R X qdS )zXRun self.countParfors(impl, ...) on array types generated from
        arg_gen.
        é   N)rµ   r£   r¶   r   r�   ÚassertGreaterEqualÚcountParfors)rO   r·   r¸   r‘   r}   ZargtysrP   rP   rQ   Úcount_parfors_variants*  s    
z&TestParforsBase.count_parfors_variantsc                 C   sH   d}|d k	r2|dkr"|d| 7 }nd}t || ƒ‚|  ||j ¡ ¡ d S )Nz@do_scheduling)ÚsignedÚunsignedrI   z$Unknown scheduler_type specified: %s)r¤   ÚassertInÚlibraryÚget_llvm_str)rO   Úcresr•   Zscheduler_strÚmsgrP   rP   rQ   r˜   4  s    z TestParforsBase.check_schedulingc                    s,   ‡ fdd„}t |ƒ ƒ‰‡fdd„t|ƒD ƒS )zFMake *ct* sample 1D arrays of length *n* using np.linspace().
        c                   3   s4   t  ddˆ ¡V  t  ddˆ ¡V  t  ddˆ ¡V  d S ©Nr   rº   é   ©rœ   ÚlinspacerP   ©ÚnrP   rQ   ÚgenC  s    z)TestParforsBase.gen_linspace.<locals>.genc                    s   g | ]}t ˆ ƒ‘qS rP   )Únext©rŒ   Úi)ÚsrcrP   rQ   rŽ   I  s     z0TestParforsBase.gen_linspace.<locals>.<listcomp>)r	   Úrange)rO   rÊ   ÚctrË   rP   )rÊ   rÏ   rQ   Úgen_linspace@  s    
zTestParforsBase.gen_linspacec                 c   sp   | j d|d�V  dd„ | j d|d�D ƒ}|V  dd„ |D ƒV  dd„ | j d	|d�D ƒ}|V  d
d„ |D ƒV  dS )z?Make 1D, 2D, 3D variants of the data in C and F orders
        é
   )rÑ   c                 S   s   g | ]}|  d ¡‘qS )©rÆ   é   ©Úreshaper‹   rP   rP   rQ   rŽ   R  s   ÿz9TestParforsBase.gen_linspace_variants.<locals>.<listcomp>é   )rÊ   rÑ   c                 S   s   g | ]}t  |¡‘qS rP   ©rœ   Zasfortranarrayr‹   rP   rP   rQ   rŽ   V  s     c                 S   s   g | ]}|  d ¡‘qS ))rÆ   rÕ   é   rÖ   r‹   rP   rP   rQ   rŽ   Y  s   ÿé   c                 S   s   g | ]}t  |¡‘qS rP   rÙ   r‹   rP   rP   rQ   rŽ   ]  s     N)rÒ   )rO   rÑ   Zarr2dsZarr3dsrP   rP   rQ   Úgen_linspace_variantsK  s    ÿÿz%TestParforsBase.gen_linspace_variantsNc                    s8   ‡ fdd„|D ƒ}|dk	r4|D ]}|t |ƒkst‚q|S )z. helper function to filter out modules by namec                    s   g | ]}ˆ |j kr|‘qS rP   ©Únamer‹   ©ÚmagicstrrP   rQ   rŽ   a  s     
 z/TestParforsBase._filter_mod.<locals>.<listcomp>N)Ústrr®   )rO   Úmodrà   ÚcheckstrZfiltr�   rP   rß   rQ   Ú_filter_mod_  s
    zTestParforsBase._filter_modc                 C   s(   dd„ |j jjjjD ƒ}| j|||d�S )z gets the gufunc LLVM Modulesc                 S   s   g | ]}|‘qS rP   rP   r‹   rP   rP   rQ   rŽ   i  s     z7TestParforsBase._get_gufunc_modules.<locals>.<listcomp>)rã   )rÁ   Ú_codegenZ_engineZ_eeÚ_modulesrä   )rO   rÃ   rà   rã   ræ   rP   rP   rQ   Ú_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Þ   )rO   rÃ   Úfnrà   Zgufunc_modsr�   râ   rP   rP   rQ   Ú_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á   )rO   rÃ   rP   rP   rQ   Ú_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â   ©ÚtmrP   rQ   Úemit_asm‰  s    z1TestParforsBase._get_gufunc_asm.<locals>.emit_asm)rÁ   rå   Z_tmrë   )rO   rÃ   rï   rP   rí   rQ   Ú_get_gufunc_asm€  s    
zTestParforsBase._get_gufunc_asmc           
         sP   ˆ   ||¡}ˆ  |¡}dd„ }‡ fdd„}| ¡ D ]\}}||ƒ}	||	ƒ q2dS )a�  
        Asserts that the fastmath flag has some effect in that suitable
        instructions are now labelled as `fast`. Whether LLVM can actually do
        anything to optimise better now the derestrictions are supplied is
        another matter!

        Arguments:
         pyfunc - a function that contains operations with parallel semantics
         sig - the type signature of pyfunc
        c                 S   s8   |   ¡ }g }|D ]"}t d|¡}|d k	r| |¡ q|S )Nz\bfast\b)Ú
splitlinesÚreÚsearchr�   )r   ÚsplittedZ	fast_instr�   ÚmrP   rP   rQ   Ú_get_fast_instructionsœ  s    z?TestParforsBase.assert_fastmath.<locals>._get_fast_instructionsc                    sF   d}| D ]8}d}|D ]}|d }||kr|d7 }qˆ   |dk¡ qd S )N)ZfaddZfsubZfmulZfdivZfremZfcmpÚcallr   z fastrº   )Ú
assertTrue)ZinstrsÚopsÚinstÚcountÚopÚmatchrU   rP   rQ   Ú_assert_fast¥  s    
z5TestParforsBase.assert_fastmath.<locals>._assert_fastN)r‡   rì   Úitems)
rO   r�   rƒ   rÃ   Ú_irrö   rþ   rÞ   Zguirrú   rP   rU   rQ   Úassert_fastmath�  s    
	
zTestParforsBase.assert_fastmath)N)N)rc   rK   rd   Ú__doc__re   r{   r„   r†   r‡   rˆ   r”   r±   r´   r¹   r½   r˜   rÒ   rÜ   rä   rç   rë   rì   rð   r  Ú__classcell__rP   rP   r~   rQ   rt   ‘   s*   Z




rt   c                 C   s”   t  | | ¡}d| | }|t  |¡ }|| | | | }|| }	dd|  }
dd|	  }|t  | | ¡ }|| }| |
 | }|| |  }|S )Nç      à?ç      ð?)rœ   Úlogr   Úexp)ZsptpriceÚstrikeZrateZ
volatilityZtimevZlogtermZpowtermZdenZd1Zd2ZNofXd1ZNofXd2ZfutureValueÚc1r÷   ÚputrP   rP   rQ   Úblackscholes_impl´  s    r  c                 C   sF   t |ƒD ]8}|t ddt |  t ||¡ ¡  d |  |¡8 }q|S ©Nr  )rÐ   rœ   Údotr  )ÚYÚXÚwZ
iterationsrÎ   rP   rP   rQ   Úlr_implÄ  s    6r  c                    s|   |‰ˆ j \}‰t|ƒD ]`}t ‡ ‡‡fdd„t|ƒD ƒ¡‰t ‡fdd„t|ƒD ƒ¡‰t ‡ ‡‡fdd„tˆƒD ƒ¡‰qˆS )Nc                    s&   g | ]‰ ‡‡‡ fd d„t ˆƒD ƒ‘qS )c              
      s:   g | ]2}t t ˆ ˆd d …f ˆ|d d …f  d ¡ƒ‘qS ©NrÆ   )r   rœ   Úsum©rŒ   Új)ÚAÚ	centroidsrÎ   rP   rQ   rŽ   Ï  s   ÿú2example_kmeans_test.<locals>.<listcomp>.<listcomp>©rÐ   ©rŒ   )r  r  Ú	numCenter©rÎ   rQ   rŽ   Ï  s   ÿÿz'example_kmeans_test.<locals>.<listcomp>c                    s    g | ]}ˆ |d d …f   ¡ ‘qS rS   ©ÚargminrÍ   )ÚdistrP   rQ   rŽ   Ñ  s     c                    s&   g | ]‰ ‡‡ ‡fd d„t ˆƒD ƒ‘qS )c                    s0   g | ](}t  ˆ ˆˆk|f ¡t  ˆˆk¡ ‘qS rP   ©rœ   r  r  )r  rÎ   ÚlabelsrP   rQ   rŽ   Ó  s   ÿr  r  r  )r  ÚDr!  r  rQ   rŽ   Ó  s   ÿÿ)ÚshaperÐ   rœ   Úarray)r  r  ZnumIterÚinit_centroidsÚNÚlrP   )r  r"  r  r  r!  r  rQ   Úexample_kmeans_testÊ  s    
ÿÿ
r(  c                 K   sF  t  ¡ }t |d¡}t | ¡}|r.t |¡}n
t d¡}t||||ƒ}t 	||¡��ä | 
¡  | 
¡  tj|jj|dd�}| ¡  tj d|j¡ t |jj|jj|jj|jjd ¡\|j_|j_|j_}	tj|jj|jj|jjdd |jj|jjtjd� tj j! "¡ }
tj j!j#|jj|jj|jj|jj|jj||
j$d�}| ¡  tj d|j¡ t %¡ }tj j!j&|jj|jj|jj|jj|jj|jj|||jj'|
d	�
}| ¡  tj j!j(|jj|jj|jj|jj|jj|jj|||jj'|
d	�
}| ¡  tj j!j)|jj|jj|jj|jj|jj|jj|||jj'|
d	�
}| ¡  t*|j+ƒ|_,W 5 Q R X ||fS )
Nr   T)Útypedzbefore-inferencerP   )Úfunc_irÚtypemapÚ	calltypesZliftedZlifted_fromr}   Úreturn_typeZhtml_output)Zswappedzafter-inference)Údiagnostics)-r   ÚContextr   Z
CPUContextr   Zrun_frontendrw   ÚTestPipeliner#   Znested_contextÚrefreshr   ZInlineClosureCallPassÚstater*  Úrunr   Zrewrite_registryÚapplyr   Ztype_inference_stageÚ	typingctxÚ	targetctxr}   r+  r-  r,  r$   ZTypeAnnotationr   ÚHTMLrŠ   ÚparforsÚparforZParforDiagnosticsZPreParforPassÚreplaced_fnsr/   Z
ParforPassÚmetadataZParforFusionPassZParforPreLoweringPassr'   ÚblocksZ_definitions)Ú	test_funcr}   Úkwsr5  r6  Útest_irÚoptionsÚtpZinline_passrI   r.  Zpreparfor_passr�   Zparfor_passrP   rP   rQ   Úget_optimized_numba_irØ  s®    


þ
   ÿÿø
    ý       ý       ý       ýrB  c           
      K   sZ   t | |f|Ž\}}d}|j ¡ D ]4\}}t|jƒD ] \}}	t|	tjjj	ƒr2|d7 }q2q |S ©Nr   rº   )
rB  r<  rÿ   Ú	enumerateÚbodyr›   rŠ   r8  r9  ÚParfor)
r=  r}   r>  r?  rA  Ú	ret_countÚlabelÚblockrÎ   rú   rP   rP   rQ   r¼     s    r¼   c                 K   s"   t | |f|Ž\}}t|j|jjƒS rS   )rB  Ú_count_arrays_innerr<  r2  r+  ©r=  r}   r>  r?  rA  rP   rP   rQ   ÚcountArrays&  s    rL  c                 K   sf   t | |f|Ž\}}|j}d}| ¡ D ]<\}}t|jƒD ](\}	}
t|
tjjj	ƒr6|t
|
jjƒ7 }q6q$|S ©Nr   )rB  r<  rÿ   rD  rE  r›   rŠ   r8  r9  rF  r­   Ú
init_block)r=  r}   r>  r?  rA  r<  rG  rH  rI  rÎ   rú   rP   rP   rQ   Úget_init_block_size*  s    rO  c           	      C   s    d}t ƒ }|  ¡ D ]|\}}t|jƒD ]h\}}t|tjjjƒr^|j	 
¡ }|j|d< |t||ƒ7 }t|tjƒr$t||jj tjƒr$| |jj¡ q$q|t|ƒ7 }|S rM  )Úsetrÿ   rD  rE  r›   rŠ   r8  r9  rF  Ú	loop_bodyrž   rN  rJ  r   ÚAssignÚtargetrÞ   r   ÚArrayCompatibleÚaddr­   )	r<  r+  rG  Zarr_setrH  rI  rÎ   rú   Úparfor_blocksrP   rP   rQ   rJ  7  s     

ÿÿrJ  c                 K   s8   t | |f|Ž\}}d}|j ¡ D ]}|t||ƒ7 }q |S rM  )rB  r<  ÚvaluesÚ_count_array_allocs_inner)r=  r}   r>  r?  rA  rG  rI  rP   rP   rQ   ÚcountArrayAllocsI  s
    rY  c                 C   s¤   d}|j D ]”}t|tjjjƒrL|t| |jƒ7 }|j 	¡ D ]}|t| |ƒ7 }q8t|t
jƒr
t|jt
jƒr
|jjdkr
tt| |jƒdks–tt| |jƒdkr
|d7 }q
|S )Nr   r÷   )ÚemptyÚnumpy)r,   znumba.np.unsafe.ndarrayrº   )rE  r›   rŠ   r8  r9  rF  rX  rN  rQ  rW  r   rR  ÚvalueÚExprrü   r&   r%   )r*  rI  rG  rú   rr   rP   rP   rQ   rX  R  s"    

ÿþÿý
rX  c                 K   s$   t | |f|Ž\}}t||j|jjƒS rS   )rB  Ú&_count_non_parfor_array_accesses_innerr<  r2  r+  rK  rP   rP   rQ   ÚcountNonParforArrayAccessesc  s    ÿr_  c           	      C   s  d}|d krt ƒ }| ¡ D � ]ü\}}|jD ]ì}t|tjjjƒrt| |j	j
¡ |j ¡ }|j|d< |t| |||ƒ7 }q*t|ƒr¬t||jjj
 tjƒr¬t| t|ƒ|ƒs¬|d7 }q*t|ƒrât||jj
 tjƒrât| t|ƒ|ƒsâ|d7 }q*t|tjƒr*t|jtjƒr*|jj
|kr*| |jj
¡ q*q|S rC  )rP  rÿ   rE  r›   rŠ   r8  r9  rF  rU  Ú	index_varrÞ   rQ  rž   rN  r^  r)   r\  r   rT  Ú_uses_indicesr+   r*   rS  r   rR  ZVar)	Úf_irr<  r+  Zparfor_indicesrG  rH  rI  ÚstmtrV  rP   rP   rQ   r^  h  sT    


   ÿÿ  ÿÿ
ÿ  ÿÿ
ÿ
þr^  c                 C   sX   |j |krdS tt| |ƒ}t|tjƒrT|jdkrTtdd„ |jD ƒƒ}t	||@ ƒdkS dS )NTÚbuild_tuplec                 s   s   | ]}|j V  qd S rS   rÝ   )rŒ   ÚvrP   rP   rQ   Ú	<genexpr>�  s     z _uses_indices.<locals>.<genexpr>r   F)
rÞ   r&   r(   r›   r   r]  rü   rP  rÿ   r­   )rb  ÚindexZ	index_setZind_defÚvarnamesrP   rP   rQ   ra  Š  s    
ra  c                   @   s   e Zd Zdd„ ZdS )r0  c                 C   sN   t  ¡ | _|| j_|| j_|| j_|| j_d | j_d | j_d | j_	i | j_
d S rS   )r   Z	StateDictr2  r5  r6  r}   r*  r+  r-  r,  r;  )rO   r5  r6  r}   r?  rP   rP   rQ   r{   —  s    
zTestPipeline.__init__N)rc   rK   rd   r{   rP   rP   rP   rQ   r0  –  s   r0  c                   @   s  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZd*d+„ Zd,d-„ Zd.d/„ Zed0d1„ ƒZed2d3„ ƒZed4d5„ ƒZ d6d7„ Z!d8S )9ÚTestParforBasiczZSmoke tests for the parfors transforms. These tests check the most basic
    functionalityc                 G   sB   t j| f|žŽ  t t d¡d¡}t d¡t d¡||jg| _d S )Nç      (@©rÕ   rÚ   ç      @ç      @)rt   r{   rœ   r×   ÚarangeÚTÚsimple_args)rO   r}   rõ   rP   rP   rQ   r{   ¨  s    zTestParforBasic.__init__c              	   C   s>   dd„ }|   t¡�}|  |¡ W 5 Q R X |  dt|jƒ¡ d S )Nc                   S   s
   t  d¡S )NrP   ©rœ   ÚonesrP   rP   rP   rQ   Ú	test_impl¯  s    z0TestParforBasic.test_simple01.<locals>.test_implú'@do_scheduling' not found©ÚassertRaisesr®   r´   rÀ   rá   Ú	exception©rO   rs  ÚraisesrP   rP   rQ   Útest_simple01®  s    zTestParforBasic.test_simple01c                 C   s   dd„ }|   |¡ d S )Nc                   S   s
   t  d¡S )N©rº   rq  rP   rP   rP   rQ   rs  ¶  s    z0TestParforBasic.test_simple02.<locals>.test_impl©r´   ©rO   rs  rP   rP   rQ   Útest_simple02µ  s    zTestParforBasic.test_simple02c                 C   s   dd„ }|   |¡ d S )Nc                   S   s
   t  d¡S ©N©rº   rÆ   rq  rP   rP   rP   rQ   rs  »  s    z0TestParforBasic.test_simple03.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple03º  s    zTestParforBasic.test_simple03c                 C   s   dd„ }|   |¡ d S )Nc                   S   s
   t  d¡S ©Nrº   rq  rP   rP   rP   rQ   rs  À  s    z0TestParforBasic.test_simple04.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple04¿  s    zTestParforBasic.test_simple04c                 C   s   dd„ }|   |¡ d S )Nc                   S   s   t jdt jd�S )Nr€  ©Údtype©rœ   rr  Ú
complex128rP   rP   rP   rQ   rs  Å  s    z0TestParforBasic.test_simple07.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple07Ä  s    zTestParforBasic.test_simple07c                 C   s   dd„ }|   |¡ d S )Nc                   S   s   t  d¡t  d¡ S r  rq  rP   rP   rP   rQ   rs  Ê  s    z0TestParforBasic.test_simple08.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple08É  s    zTestParforBasic.test_simple08c                 C   s   dd„ }|   |¡ d S )Nc                   S   s
   t  d¡S )N©rº   rº   rq  rP   rP   rP   rQ   rs  Ï  s    z0TestParforBasic.test_simple09.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple09Î  s    zTestParforBasic.test_simple09c                 C   s   dd„ }|   |¡ d S )Nc                   S   s
   t  d¡S )N©r   r   rq  rP   rP   rP   rQ   rs  Ô  s    z0TestParforBasic.test_simple10.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple10Ó  s    zTestParforBasic.test_simple10c                 C   s   dd„ }|   |¡ d S )Nc                   S   s   t  d¡d S ©N©rÓ   rÓ   r  rq  rP   rP   rP   rQ   rs  Ù  s    z0TestParforBasic.test_simple11.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple11Ø  s    zTestParforBasic.test_simple11c                 C   s   dd„ }|   |¡ d S )Nc                   S   s   t  d¡t  d¡ S rŽ  r†  rP   rP   rP   rQ   rs  Þ  s    z0TestParforBasic.test_simple12.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple12Ý  s    zTestParforBasic.test_simple12c              	   C   s>   dd„ }|   t¡�}|  |¡ W 5 Q R X |  dt|jƒ¡ d S )Nc                   S   s
   t  d¡S r  )rœ   r‡  rP   rP   rP   rQ   rs  ã  s    z0TestParforBasic.test_simple13.<locals>.test_implrt  ru  rx  rP   rP   rQ   Útest_simple13â  s    zTestParforBasic.test_simple13c                 C   s   dd„ }|   |¡ d S )Nc                   S   s   t  d¡dd d… S )Nr�  r   é   rq  rP   rP   rP   rQ   rs  ê  s    z0TestParforBasic.test_simple14.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple14é  s    zTestParforBasic.test_simple14c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   | |  S rS   rP   ©Úv1Úv2Úm1Úm2rP   rP   rQ   rs  ï  s    z0TestParforBasic.test_simple15.<locals>.test_impl©r´   rp  r}  rP   rP   rQ   Útest_simple15î  s    zTestParforBasic.test_simple15c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   || S rS   rP   r•  rP   rP   rQ   rs  ô  s    z0TestParforBasic.test_simple16.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple16ó  s    zTestParforBasic.test_simple16c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   ||  S rS   rP   r•  rP   rP   rQ   rs  ù  s    z0TestParforBasic.test_simple17.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple17ø  s    zTestParforBasic.test_simple17c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   |j tj |¡d  S r‚  )ro  rœ   ÚlinalgZsvdr•  rP   rP   rQ   rs  ÿ  s    z0TestParforBasic.test_simple18.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple18ý  s    zTestParforBasic.test_simple18c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   t  ||¡S rS   ©rœ   r  r•  rP   rP   rQ   rs    s    z0TestParforBasic.test_simple19.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple19  s    zTestParforBasic.test_simple19c              	   C   sF   dd„ }|   t¡�}| j|f| jžŽ  W 5 Q R X |  dt|jƒ¡ d S )Nc                 S   s   t  ||¡S rS   r   r•  rP   rP   rQ   rs    s    z0TestParforBasic.test_simple20.<locals>.test_implrt  )rv  r®   r´   rp  rÀ   rá   rw  rx  rP   rP   rQ   Útest_simple20	  s    zTestParforBasic.test_simple20c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   t  | | ¡S rS   r   r•  rP   rP   rQ   rs    s    z0TestParforBasic.test_simple21.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple21  s    zTestParforBasic.test_simple21c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   t  | |  ¡S rS   r   r•  rP   rP   rQ   rs    s    z0TestParforBasic.test_simple22.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple22  s    zTestParforBasic.test_simple22c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s2   d|  }d|  }dt  |d |d  dk ¡ d S )NrÆ   rÚ   rº   rÓ   r   )r–  r—  r˜  r™  r�   ÚyrP   rP   rQ   rs    s    z0TestParforBasic.test_simple23.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple23  s    zTestParforBasic.test_simple23c                 C   s   dd„ }|   |¡ d S )Nc                  S   s2   d} t  | | f¡}t  | ¡}t  |d d …|f ¡S )Nr“  )rœ   rr  rn  r  )rÊ   r  rr   rP   rP   rQ   rs  %  s    
z0TestParforBasic.test_simple24.<locals>.test_implr|  r}  rP   rP   rQ   Útest_simple24$  s    zTestParforBasic.test_simple24c                 C   s   dd„ }| j |f| jžŽ  dS )zAsame as corresponding test_simple_<n> case but using operator.addc                 S   s   t  | | ¡S rS   ©ÚoperatorrU  r•  rP   rP   rQ   rs  /  s    z:TestParforBasic.test_simple_operator_15.<locals>.test_implNrš  r}  rP   rP   rQ   Útest_simple_operator_15,  s    z'TestParforBasic.test_simple_operator_15c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   t  ||¡S rS   r¨  r•  rP   rP   rQ   rs  6  s    z:TestParforBasic.test_simple_operator_16.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple_operator_164  s    z'TestParforBasic.test_simple_operator_16c                 C   s   dd„ }| j |f| jžŽ  d S )Nc                 S   s   t  || ¡S rS   r¨  r•  rP   rP   rQ   rs  =  s    z:TestParforBasic.test_simple_operator_17.<locals>.test_implrš  r}  rP   rP   rQ   Útest_simple_operator_17;  s    z'TestParforBasic.test_simple_operator_17c                 C   s0   dd„ }dd„ }t  d¡}| j|||gd� d S )Nc                 S   s   | d7 } d| d d …< d S )Nrº   rÕ   rP   ©rq   rP   rP   rQ   rs  D  s    z5TestParforBasic.test_inplace_alias.<locals>.test_implc                 S   s   t j | |¡ d S rS   ©rœ   r©   Zassert_equalrp   rP   rP   rQ   ÚcomparerH  s    z4TestParforBasic.test_inplace_alias.<locals>.comparerrº   ©r™   ©rœ   rr  r´   )rO   rs  r¯  r�   rP   rP   rQ   Útest_inplace_aliasB  s    
z"TestParforBasic.test_inplace_aliasN)"rc   rK   rd   r  r{   rz  r~  r�  rƒ  rˆ  r‰  r‹  r�  r�  r‘  r’  r”  r›  rœ  r�  r>   rŸ  r=   r¡  r¢  r£  r¤  r¦  r§  r?   rª  r«  r¬  r²  rP   rP   rP   rQ   ri  £  sF   






ri  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¥  rP   rP   rQ   rs  T  s    z2TestParforNumericalMisc.test_pi.<locals>.test_impli † rº   ©Údecimalr   )r´   r«   r¼   r   Úint64rL  Úintpr}  rP   rP   rQ   Útest_piS  s    zTestParforNumericalMisc.test_pic                 C   s*   t jd d … fd }|  tt|ƒd¡ d S ©Nrk   rº   )rŠ   Úfloat64r«   r¼   r  r|   rP   rP   rQ   Ú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  rY  r|   rP   rP   rQ   Útest_logistic_regressionb  s
    ,ÿz0TestParforNumericalMisc.test_logistic_regressionc                 C   sŒ   t j d¡ d}d}d}t j ||f¡}t j ||f¡}| jt||d|dd� t tjdd¡tj	tj	t tjdd¡f}|  
tt|ƒd¡ d S )	Nr   é   rÓ   rÕ   rº   r¶  rÆ   ÚC)rœ   r´  Úseedrµ  r´   r(  r   ÚArrayr¼  r¹  r«   r_  )rO   r&  r"  Zcentersr  r%  Zarg_typsrP   rP   rQ   Útest_kmeansi  s     ÿÿ ÿz#TestParforNumericalMisc.test_kmeansN)	rc   rK   rd   r  rº  r½  r=   r¿  rÄ  rP   rP   rP   rQ   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.S )/ÚTestParforNumPyz'Tests NumPy functionality under parforsc                 C   s>   dd„ }t  ddd¡ dd¡}t  ddd¡}|  |||¡ d S )Nc                 S   s   t  | |¡S rS   r   ©rq   re  rP   rP   rQ   rs  €  s    z-TestParforNumPy.test_mvdot.<locals>.test_implr   rº   r“  rÆ   rÓ   )rœ   rÈ   r×   r´   )rO   rs  r  re  rP   rP   rQ   Ú
test_mvdot~  s    zTestParforNumPy.test_mvdotc                    sb   t jt jt jt jfD ]H‰ ‡ fdd„}|  |d¡ |  t|tj	fƒd¡ |  t
|tjfƒd¡ qd S )Nc                    s"   t  | ¡}ˆ |ƒ}| ¡ }|| S rS   ©rœ   rr  r  )rÊ   r  rÁ  ÚB©rü   rP   rQ   rs  Š  s    
zBTestParforNumPy.test_fuse_argmin_argmax_max_min.<locals>.test_implé   rº   r   )rœ   r  ÚargmaxÚminÚmaxr´   r«   r¼   r   r¸  rL  r¹  r}  rP   rÊ  rQ   Útest_fuse_argmin_argmax_max_minˆ  s
    z/TestParforNumPy.test_fuse_argmin_argmax_max_minc                 C   s"   dd„ }|   t|tjfƒd¡ d S )Nc                 S   s   t | ƒ}|d S rM  r   ©rÊ   r  rP   rP   rQ   rs  ”  s    zDTestParforNumPy.test_np_random_func_direct_import.<locals>.test_implrº   ©r«   r¼   r   r¸  r}  rP   rP   rQ   Ú!test_np_random_func_direct_import“  s    z1TestParforNumPy.test_np_random_func_direct_importc                 C   sf   dd„ }dd„ }dd„ }ddd	t d
dƒt dd
ƒfD ].}|  ||¡ |  |d|¡ |  |d|d¡ q2d S )Nc                 S   s
   t  | ¡S rS   ©rœ   rn  rÉ   rP   rP   rQ   Ú
test_impl1›  s    z/TestParforNumPy.test_arange.<locals>.test_impl1c                 S   s
   t  |¡S rS   rÓ  )ÚsrÊ   rP   rP   rQ   Ú
test_impl2ž  s    z/TestParforNumPy.test_arange.<locals>.test_impl2c                 S   s   t  | ||¡S rS   rÓ  )rÕ  rÊ   ÚtrP   rP   rQ   Ú
test_impl3¡  s    z/TestParforNumPy.test_arange.<locals>.test_impl3é   é€   ç      >@rÚ   rk   rÆ   ©Úcomplexr´   )rO   rÔ  rÖ  rØ  ÚargrP   rP   rQ   Útest_arange™  s    zTestParforNumPy.test_arangec                 C   sR   dd„ }dd„ }dddt dd	ƒt d	dƒfD ]"}|  |d
|¡ |  |d
|d¡ q*d S )Nc                 S   s   t  | |¡S rS   rÇ   )ÚstartÚstoprP   rP   rQ   rÔ  «  s    z1TestParforNumPy.test_linspace.<locals>.test_impl1c                 S   s   t  | ||¡S rS   rÇ   )rà  rá  ÚnumrP   rP   rQ   rÖ  ®  s    z1TestParforNumPy.test_linspace.<locals>.test_impl2rÙ  rÚ  rÛ  rÚ   rk   rÆ   é   rÜ  )rO   rÔ  rÖ  rÞ  rP   rP   rQ   Útest_linspace©  s
    zTestParforNumPy.test_linspacec              	      s¬   dd„ }d}t j |¡}t jjd|dfd�}ˆ  ||¡ ˆ  ||¡ ˆ  t|t tj	dd¡fƒd¡ ˆ  t|t tj	d	d¡fƒd¡ ‡ fd
d„}ˆ  
||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   ©Zmean©r  rP   rP   rQ   rs  ¶  s    z,TestParforNumPy.test_mean.<locals>.test_impléd   rÓ   rÕ   ©Úsizerº   rÁ  rÆ   c                      s
   ˆ   d¡S r‚  ©rÜ   rP   rU   rP   rQ   Ú<lambda>Á  ó    z+TestParforNumPy.test_mean.<locals>.<lambda>©rœ   r´  rµ  Úrandintr´   r«   r¼   r   rÃ  r¼  r¹   r½   )rO   rs  r&  r  rÉ  Údata_genrP   rU   rQ   Ú	test_meanµ  s      zTestParforNumPy.test_meanc              	      sÄ   dd„ }d}t j |¡}t jjd|dfd�}|d|  }ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  t|t tj	dd	¡fƒd
¡ ˆ  t|t tj	d
d	¡fƒd
¡ ‡ fdd„}ˆ  
||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   )Úvarræ  rP   rP   rQ   rs  Æ  s    z+TestParforNumPy.test_var.<locals>.test_implrç  rÓ   rÕ   rè  ù              ð?rº   rÁ  rÆ   c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë  Ó  rì  z*TestParforNumPy.test_var.<locals>.<lambda>rí  )rO   rs  r&  r  rÉ  rÁ  rï  rP   rU   rQ   Útest_varÅ  s      zTestParforNumPy.test_varc                    sº   dd„ }d}t j |¡}t jjd|dfd�}|d|  }ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ t tjdd	¡f}ˆ  t	||ƒd
¡ ˆ  t	||ƒd
¡ ‡ fdd„}ˆ  
||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   )Zstdræ  rP   rP   rQ   rs  Ø  s    z+TestParforNumPy.test_std.<locals>.test_implrç  rÓ   rÕ   rè  rò  rº   rÁ  rÆ   c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë  æ  rì  z*TestParforNumPy.test_std.<locals>.<lambda>)rœ   r´  rµ  rî  r´   r   rÃ  r¼  r«   r¼   r¹   r½   )rO   rs  r&  r  rÉ  rÁ  Úargtyrï  rP   rU   rQ   Ú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Ð  rP   rP   rQ   rs  ï  s    z5TestParforNumPy.test_random_parfor.<locals>.test_implrº   NrÑ  r}  rP   rP   rQ   Ú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ÚFrP   rP   rQ   rs  õ  s    z/TestParforNumPy.test_randoms.<locals>.test_implrÚ  gš™™™™™©?)Zrtolrº   )r†   rŠ   r   r¨   rœ   r©   Úassert_allcloser«   r¼   r   r¸  ©rO   rs  rÊ   r’   r°   Z	py_outputrP   rP   rQ   Ú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þ  rP   rP   rQ   rs    s    z4TestParforNumPy.test_dead_randoms.<locals>.test_implrÚ  r   )r†   rŠ   r   r¨   r«   r¼   r   r¸  r  rP   rP   rQ   Útest_dead_randoms  s    	
z!TestParforNumPy.test_dead_randomsc              
      sb  dd„ }dd„ }d}t j |¡}t jjd|d� t j¡}t j ||f¡}t  t jt jg¡}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d}||fD ]Z}	ˆ  	|	t
jd d … f¡}
ˆ  t¡�}|
 t jg t jd	�¡ W 5 Q R X ˆ  |t|jƒ¡ qÆ‡ fd
d„}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   ©rÍ  ræ  rP   rP   rQ   rÔ    s    z,TestParforNumPy.test_min.<locals>.test_impl1c                 S   s
   t  | ¡S rS   )rœ   rÍ  ræ  rP   rP   rQ   rÖ    s    z,TestParforNumPy.test_min.<locals>.test_impl2éÓ   rÓ   rè  zDzero-size array to reduction operation minimum which has no identityr„  c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë  6  rì  z*TestParforNumPy.test_min.<locals>.<lambda>©rœ   r´  rµ  rî  ÚastypeÚint32r$  Úinfr´   r†   r   r¸  rv  r¤   r¨   rÀ   rá   rw  r¹   r½   ©rO   rÔ  rÖ  rÊ   r  rÉ  rÁ  r"  rÄ   r·   ÚpcfuncÚerï  rP   rU   rQ   Útest_min  s4     zTestParforNumPy.test_minc              
      sf  dd„ }dd„ }d}t j |¡}t jjd|d� t j¡}t j ||f¡}t  t j t j g¡}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d}||fD ]Z}	ˆ  	|	t
jd d … f¡}
ˆ  t¡�}|
 t jg t jd	�¡ W 5 Q R X ˆ  |t|jƒ¡ qÊ‡ fd
d„}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   )rÎ  ræ  rP   rP   rQ   rÔ  =  s    z,TestParforNumPy.test_max.<locals>.test_impl1c                 S   s
   t  | ¡S rS   )rœ   rÎ  ræ  rP   rP   rQ   rÖ  @  s    z,TestParforNumPy.test_max.<locals>.test_impl2r  rÓ   rè  zDzero-size array to reduction operation maximum which has no identityr„  c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë  [  rì  z*TestParforNumPy.test_max.<locals>.<lambda>r  r  rP   rU   rQ   Útest_max<  s4     zTestParforNumPy.test_maxc              
      sn  dd„ }dd„ }d}t  dddd	dg¡}t jjd
|d� t j¡}t j ||f¡}t  ddt jd	dg¡}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d}||fD ]Z}	ˆ  	|	t
jd d … f¡}
ˆ  t¡�}|
 t jg t jd�¡ W 5 Q R X ˆ  |t|jƒ¡ qÒ‡ fdd„}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   )rÌ  ræ  rP   rP   rQ   rÔ  b  s    z/TestParforNumPy.test_argmax.<locals>.test_impl1c                 S   s
   t  | ¡S rS   )rœ   rÌ  ræ  rP   rP   rQ   rÖ  e  s    z/TestParforNumPy.test_argmax.<locals>.test_impl2r  r  rø  rl  ç       @rÓ   rè  z*attempt to get argmax of an empty sequencer„  c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë    rì  z-TestParforNumPy.test_argmax.<locals>.<lambda>©rœ   r$  r´  rî  r  r	  rµ  Únanr´   r†   r   r¸  rv  r¤   r¨   rÀ   rá   rw  r¹   r½   r  rP   rU   rQ   Útest_argmaxa  s4     zTestParforNumPy.test_argmaxc              
      sn  dd„ }dd„ }d}t  ddddd	g¡}t jjd
|d� t j¡}t j ||f¡}t  ddt jdd	g¡}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d}||fD ]Z}	ˆ  	|	t
jd d … f¡}
ˆ  t¡�}|
 t jg t jd�¡ W 5 Q R X ˆ  |t|jƒ¡ qÒ‡ fdd„}ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ ˆ  ||¡ d S )Nc                 S   s   |   ¡ S rS   r  ræ  rP   rP   rQ   rÔ  †  s    z/TestParforNumPy.test_argmin.<locals>.test_impl1c                 S   s
   t  | ¡S rS   )rœ   r  ræ  rP   rP   rQ   rÖ  ‰  s    z/TestParforNumPy.test_argmin.<locals>.test_impl2r  r  rø  r  rl  rÓ   rè  z*attempt to get argmin of an empty sequencer„  c                      s
   ˆ   d¡S r‚  rê  rP   rU   rP   rQ   rë  £  rì  z-TestParforNumPy.test_argmin.<locals>.<lambda>r  r  rP   rU   rQ   Útest_argmin…  s4     zTestParforNumPy.test_argminc                 C   sF   dd„ }t  d¡}|  ||¡ t tjdd¡f}|  t||ƒd¡ d S )Nc                 S   s   |   d¡ | S ©Nç      @©Úfill©r�   rP   rP   rQ   rs  ª  s    
z4TestParforNumPy.test_ndarray_fill.<locals>.test_implrÓ   rº   rÁ  ©rœ   Úzerosr´   r   rÃ  r¼  r«   r¼   ©rO   rs  r�   rô  rP   rP   rQ   Útest_ndarray_fill©  s
    
z!TestParforNumPy.test_ndarray_fillc                 C   sF   dd„ }t  d¡}|  ||¡ t tjdd¡f}|  t||ƒd¡ d S )Nc                 S   s   |   d¡ | S r  r  r  rP   rP   rQ   rs  ³  s    
z6TestParforNumPy.test_ndarray_fill2d.<locals>.test_impl©rÆ   rÆ   rÆ   rÁ  rº   r  r  rP   rP   rQ   Útest_ndarray_fill2d²  s
    
z#TestParforNumPy.test_ndarray_fill2dc                 C   s@   dd„ }t  ddddddd	d
ddddg¡}d}|  |||¡ d S )Nc                 S   s^   t j||dft jd�}| d|… }|j} | d }| dd¡}|| }||d d …d d …df< |S ©Nrº   r„  r   rH   ©rœ   r  r¼  ré  r×   ©rq   rr   Zresult_matrixÚsub_aÚzÚresult_datarP   rP   rQ   rs  ½  s    z<TestParforNumPy.test_reshape_with_neg_one.<locals>.test_implr  r  rl  rm  ç      @ç      @r  ç       @ç      "@ç      $@ç      &@rj  rÕ   ©rœ   r$  r´   ©rO   rs  rq   rr   rP   rP   rQ   Útest_reshape_with_neg_one»  s    
     ÿz)TestParforNumPy.test_reshape_with_neg_onec                 C   s@   dd„ }t  ddddddd	d
ddddg¡}d}|  |||¡ d S )Nc                 S   s^   t j||dft jd�}| d|… }|j} | d }| dd¡}|| }||d d …d d …df< |S )Nrº   r„  r   iåúÿÿr!  r"  rP   rP   rQ   rs  Ï  s    z>TestParforNumPy.test_reshape_with_large_neg.<locals>.test_implr  r  rl  rm  r&  r'  r  r(  r)  r*  r+  rj  rÕ   r,  r-  rP   rP   rQ   Útest_reshape_with_large_negÍ  s    
     ÿz+TestParforNumPy.test_reshape_with_large_negc                 C   st   |   tj¡�H}tdd�dd„ ƒ}t ddddd	d
ddddddg¡}d}|||ƒ W 5 Q R X d}|  |t|jƒ¡ d S )NT©Úparallelc                 S   s^   t j||dft jd�}| d|… }|j} | d }| dd¡}|| }||d d …d d …df< |S r   r!  )rq   rr   Zrmr#  r$  r%  rP   rP   rQ   rs  â  s    zETestParforNumPy.test_reshape_with_too_many_neg_one.<locals>.test_implr  r  rl  rm  r&  r'  r  r(  r)  r*  r+  rj  rÕ   z7The reshape API may only include one negative argument.)	rv  r   ÚUnsupportedRewriteErrorr   rœ   r$  rÀ   rá   rw  )rO   Úraisedrs  rq   rr   rÄ   rP   rP   rQ   Ú"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É   rP   rP   rQ   rs  ö  s    z0TestParforNumPy.test_0d_array.<locals>.test_implé   F©r˜   )r´   rœ   r$  r}  rP   rP   rQ   Útest_0d_arrayõ  s    zTestParforNumPy.test_0d_arrayc                 C   sF   dd„ }t  d¡d }|  ||¡ |  t|tjd d d… fƒd¡ d S )Nc                 S   s   t  | jd | jd  ¡S r  )rœ   r  ÚrealÚimag)r$  rP   rP   rQ   rs  ü  s    z6TestParforNumPy.test_real_imag_attr.<locals>.test_implrk   y      ð?      ð?rº   )rœ   rn  r´   r«   r¼   r   r‡  )rO   rs  r$  rP   rP   rQ   Útest_real_imag_attrú  s    z#TestParforNumPy.test_real_imag_attrN)rc   rK   rd   r  r=   rÇ  rÏ  rÒ  rß  rä  rð  ró  rõ  rö  r  r  r  r  r  r  r  r  r.  r/  r4  r8  r;  rP   rP   rP   rQ   rÅ  z  s0   
	
%%$$		rÅ  c                   @   s*   e Zd ZdZe e d¡edd„ ƒƒZdS )ÚTestParforsUnsupportedz$Tests for unsupported use of parforszOnly impacts 32 bit hardwarec              	   C   sr   |   tj¡�F}tdd�dd„ ƒ}t ddd¡ dd	¡}t ddd	¡}|||ƒ W 5 Q R X d
}|  |t|j	ƒ¡ dS )zu
        This test is in place until issues with the 'parallel'
        target on 32 bit hardware are fixed.
        Tr0  c                 S   s   t  | |¡S rS   r   rÆ  rP   rP   rQ   Úddot  s    zHTestParforsUnsupported.test_unsupported_combination_raises.<locals>.ddotr   rº   r“  rÆ   rÓ   zCThe 'parallel' target is not currently supported on 32 bit hardwareN)
rv  r   ÚUnsupportedParforsErrorr   rœ   rÈ   r×   rÀ   rá   rw  )rO   r3  r=  r  re  rÄ   rP   rP   rQ   Ú#test_unsupported_combination_raises  s    
z:TestParforsUnsupported.test_unsupported_combination_raisesN)	rc   rK   rd   r  ÚunittestÚskipIfr<   r=   r?  rP   rP   rP   rQ   r<    s   r<  c                   @   sL  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„ ZDd€d�„ ZEd‚dƒ„ ZFd„d…„ ZGd†d‡„ ZHdˆd‰„ ZIdŠd‹„ ZJdŒd�„ ZKdŽS )�ÚTestParforsz6 Tests cpython, reduction and various parfors featuresc                    s    dd„ }ˆ   |‡ fdd„¡ d S )Nc                 S   s   | | | S rS   rP   )rq   r�   r¥  rP   rP   rQ   rs    s    z,TestParfors.test_arraymap.<locals>.test_implc                      s
   ˆ   d¡S ©NrÕ   rê  rP   rU   rP   rQ   rë  "  rì  z+TestParfors.test_arraymap.<locals>.<lambda>)r¹   r}  rP   rU   rQ   Útest_arraymap  s    zTestParfors.test_arraymapc                 C   s(   dd„ }|   |¡ |  t|dƒd¡ d S )Nc                  S   s"   t  d¡} t  d¡}t  | | ¡S )Nrº   ©rÓ   é   )rœ   r$  rr  r  ©r  r  rP   rP   rQ   rs  %  s    

z0TestParfors.test_0d_broadcast.<locals>.test_implrP   rº   ©r´   r«   r¼   r}  rP   rP   rQ   Útest_0d_broadcast$  s    
zTestParfors.test_0d_broadcastc                 C   s(   dd„ }|   |¡ |  t|dƒd¡ d S )Nc                  S   s"   t  d¡} t  d¡}t  | | ¡S ©NrE  )rœ   rr  r  r  rG  rP   rP   rQ   rs  -  s    

z-TestParfors.test_2d_parfor.<locals>.test_implrP   rº   rH  r}  rP   rP   rQ   Útest_2d_parfor,  s    
zTestParfors.test_2d_parforc                    s:   dd„ ‰ ‡ ‡fdd„}dd„ }ˆ  ||¡ ˆ ||¡ d S )Nc                  s   s"   t  d¡} t  d¡}| |fV  d S rJ  ©rœ   rr  r  rG  rP   rP   rQ   Úcase15  s    

z)TestParfors.test_nd_parfor.<locals>.case1c                      s   t ˆ ƒ ˆ d¡ƒS r  )r
   rÜ   rP   ©rM  rO   rP   rQ   rë  :  rì  z,TestParfors.test_nd_parfor.<locals>.<lambda>c                 S   s   t  | | ¡S rS   r   rG  rP   rP   rQ   rs  <  s    z-TestParfors.test_nd_parfor.<locals>.test_impl)r¹   r½   )rO   rï  rs  rP   rN  rQ   Útest_nd_parfor4  s
    zTestParfors.test_nd_parforc                    s,   ddl m‰  ‡ fdd„}d}|  ||¡ d S )Nr   ©rr  c                    s   ˆ | ƒ}|d S rM  rP   rÐ  rP  rP   rQ   rs  D  s    z9TestParfors.test_np_func_direct_import.<locals>.test_impléo   )r[  rr  r´   ©rO   rs  rÊ   rP   rP  rQ   Útest_np_func_direct_importB  s    z&TestParfors.test_np_func_direct_importc              	   C   s^   dd„ }|   |dd¡ |  t¡�}tdd�|ƒ}|ddƒ W 5 Q R X d}|  |t|jƒ¡ d S )Nc                 S   s"   t  | ¡}t  |¡}t  || ¡S rS   rÈ  )rõ   rÊ   r  rÉ  rP   rP   rQ   rs  K  s    

z2TestParfors.test_size_assertion.<locals>.test_implrÓ   Tr0  é	   zSizes of A, B do not match)r´   rv  r®   r   rÀ   rá   rw  )rO   rs  ry  r“   rÄ   rP   rP   rQ   Útest_size_assertionJ  s    zTestParfors.test_size_assertionc                 C   s6   dd„ }d}t j |¡}t  |¡}|  ||||¡ d S )Nc                 S   sT   t  d¡D ]D}t|| d |d | d ƒD ] }d||< | | dkr,d||< q,q
|S )NrÆ   rº   r   ©rŠ   r   rÐ   )r�   Úis_positiver&  rÎ   r  rP   rP   rQ   rs  Y  s    "z'TestParfors.test_cfg.<locals>.test_implrç  )rœ   r´  Úrandr  r´   )rO   rs  r&  r�   rW  rP   rP   rQ   Útest_cfgW  s
    	
zTestParfors.test_cfgc              	   C   s.  dd„ }d}t j |¡}|  ||¡ t jjd|d� t j¡}|  ||¡ dd„ }|  ¡ � |  |¡ W 5 Q R X d}t jjd|d� t j¡}dd„ }|  ||¡ d	d„ }|  || d
¡¡ dd„ }|  || d
¡¡ |  	t
|tjd d …d d …f fƒd¡ dd„ }|  ||¡ |  	t
|tjd d … fƒd¡ d S )Nc                 S   s   d}t dd„ | |ƒS )NrÓ   c                 S   s
   t | |ƒS rS   r  rp   rP   rP   rQ   rë  j  rì  ú<TestParfors.test_reduce.<locals>.test_impl.<locals>.<lambda>r   )r  Zinit_valrP   rP   rQ   rs  h  s    z*TestParfors.test_reduce.<locals>.test_implr  rÓ   rè  c               	   S   s$   dd„ } t | t dddddg¡dƒS )Nc                 S   s   | d S r  rP   r  rP   rP   rQ   rë  t  rì  rZ  rº   rÆ   rÕ   rÚ   rk   )r   rœ   r$  )ÚgrP   rP   rQ   rs  s  s    é    c                 S   s   t  | | dk ¡S rC  r   ræ  rP   rP   rQ   rs  |  s    c                 S   s&   | d d …df }t  | |dkdf ¡S )Nr   rÕ   rº   r   ©r  rÉ  rP   rP   rQ   rs  ‚  s    )é   rÓ   c                 S   s*   | d d …df }t  | |dkdd…f ¡S )Nr   rÕ   rº   rÆ   r   r]  rP   rP   rQ   rs  ‰  s    rÆ   c                 S   s   t  | ¡}| | S rS   )rœ   Zamin)r  Zmin_valrP   rP   rQ   rs  �  s    
)rœ   r´  rµ  r´   rî  r  r	  ZassertTypingErrorr×   r«   r¼   rŠ   r¼  ©rO   rs  rÊ   r  rP   rP   rQ   Útest_reduceg  s*    
&zTestParfors.test_reducec              	   C   sD   dd„ }d}|   t¡�}|  |d¡}W 5 Q R X |  |t|jƒ¡ d S )Nc                  S   s    d} t dƒD ]}t | ¡} q| S rC  )r   Úcmathr   ©ÚaccrÎ   rP   rP   rQ   rs  ˜  s    z9TestParfors.test_use_of_reduction_var1.<locals>.test_implúCUse of reduction variable acc in an unsupported reduction function.rP   ©rv  r¤   r†   rÀ   rá   rw  ©rO   rs  rÄ   r  r  rP   rP   rQ   Útest_use_of_reduction_var1—  s
    z&TestParfors.test_use_of_reduction_var1c              	   C   sF   dd„ }d}|   tj¡�}|  |d¡}W 5 Q R X |  |t|jƒ¡ d S )Nc                  S   s   d} t dƒD ]}| d } q| S ©Nrç  rÆ   ©r   rb  rP   rP   rQ   rs  ¥  s    
z9TestParfors.test_unsupported_floordiv1.<locals>.test_implzÑParallel 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.rP   )rv  r   ZNumbaValueErrorr†   rÀ   rá   rw  rf  rP   rP   rQ   Útest_unsupported_floordiv1¤  s
    z&TestParfors.test_unsupported_floordiv1c              	   C   sD   dd„ }d}|   t¡�}|  |d¡}W 5 Q R X |  |t|jƒ¡ d S )Nc                  S   s"   d} t dƒD ]}| |d N } q| S rh  ri  rb  rP   rP   rQ   rs  ¶  s    z4TestParfors.test_unsupported_xor1.<locals>.test_implrd  rP   re  rf  rP   rP   rQ   Útest_unsupported_xor1µ  s
    z!TestParfors.test_unsupported_xor1c                 C   s2   dd„ }d}|   ||¡ |  t|tjfƒd¡ d S )Nc                 S   s   t  | ¡}| ¡ S rS   rÈ  rÐ  rP   rP   rQ   rs  Ä  s    
z8TestParfors.test_parfor_array_access1.<locals>.test_implr  r   )r´   r«   rL  r   r¹  rR  rP   rP   rQ   Útest_parfor_array_access1Á  s    z%TestParfors.test_parfor_array_access1c                 C   s2   dd„ }d}|   ||¡ |  t|tjfƒd¡ d S )Nc                 S   sb   t  | ¡}d}d} t t|ƒ¡D ]}||| 7 }q t t|ƒ¡D ]}|| kr@| || 7 } q@||  S rM  )rœ   rr  rŠ   r   r­   ©rÊ   r  rõ   rÎ   rP   rP   rQ   rs  Ï  s    
z8TestParfors.test_parfor_array_access2.<locals>.test_implr  r   ©r´   r«   r_  r   r¹  rR  rP   rP   rQ   Útest_parfor_array_access2Ì  s    z%TestParfors.test_parfor_array_access2c              	   C   sF   dd„ }d}|   tj¡�}|  ||¡ W 5 Q R X |  dt|jƒ¡ d S )Nc                 S   sB   t  | t j¡}d}t t|ƒ¡D ]}||| 7 }|dkr |}q d S ©Nr   rÆ   )rœ   rr  r¸  rŠ   r   r­   rm  rP   rP   rQ   rs  á  s    z8TestParfors.test_parfor_array_access3.<locals>.test_implr  z Overwrite of parallel loop index)rv  r   r2  r´   rÀ   rá   rw  )rO   rs  rÊ   ry  rP   rP   rQ   Útest_parfor_array_access3à  s
    z%TestParfors.test_parfor_array_access3c                 C   s.  dd„ }d}d}t j ||f¡}t j |¡}|  |||¡ t|t tjdd¡t tjdd¡fƒ\}}|  t	|j
ƒdko~d|j
k¡ |j
d }d	}	d }
|jD ]}t|tjjjƒršd
}	|}
qš|  |	¡ d	}|
j ¡ D ]N}|jD ]B}t|tjƒrÚt|jtjƒrÚ|jjdkrÚd
}|  |
j|jjk¡ qÚqÐ|  |¡ d S )Nc                 S   s   t  | |¡S rS   r   )r  rr   rP   rP   rQ   rs  ò  s    z8TestParfors.test_parfor_array_access4.<locals>.test_implr  rÚ   rÆ   rÁ  rº   r   FTrd  )rœ   r´  rµ  r´   rB  r   rÃ  r¼  rø   r­   r<  rE  r›   rŠ   r8  r9  rF  rQ  rW  r   rR  r\  r]  rü   r`  rÿ   )rO   rs  rÊ   Údr  rr   r?  rA  rI  Zparfor_foundr9  rc  Zbuild_tuple_foundÚblrP   rP   rQ   Útest_parfor_array_access4î  s@     ÿÿ



ÿ
þz%TestParfors.test_parfor_array_access4c                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s,   t  t| ƒ¡D ]}| j d¡| |< q| d S ©Nr   rÚ   )rŠ   r   r­   r…  r¬   )rq   rÎ   rP   rP   rQ   rs    s    z5TestParfors.test_parfor_dtype_type.<locals>.test_implrÓ   r±  )rO   rs  rq   rP   rP   rQ   Útest_parfor_dtype_type  s    
z"TestParfors.test_parfor_dtype_typec                 C   s2   dd„ }d}|   ||¡ |  t|tjfƒd¡ d S )Nc                 S   s>   t  | df¡}d}t | ¡D ]}|||d d …f  ¡ 7 }q|S )NrÕ   r   )rœ   rr  rŠ   r   r  ©rÊ   r  r¥  rÎ   rP   rP   rQ   rs  !  s
    z8TestParfors.test_parfor_array_access5.<locals>.test_implr  r   rn  rR  rP   rP   rQ   Útest_parfor_array_access5  s    z%TestParfors.test_parfor_array_access5c                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s&   t dƒD ]}d| d  | d< q| d S )NrÓ   rÆ   r   ri  )ÚoutrÎ   rP   rP   rQ   rs  /  s    z8TestParfors.test_parfor_hoist_setitem.<locals>.test_implrº   r±  )rO   rs  ry  rP   rP   rQ   Ú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 rC  )rœ   rr  rÐ   r  )r&  r"  r  r  r  rÎ   rÉ  rP   rP   rQ   rs  :  s    

z8TestParfors.test_parfor_generate_fuse.<locals>.test_implr  rÕ   rÚ   )r´   r«   rY  r   r¹  r¼   )rO   rs  rÊ   rr  rP   rP   rQ   Útest_parfor_generate_fuse7  s    	z%TestParfors.test_parfor_generate_fusec                 C   s>   dd„ }t  dt j¡}t  dt j¡}d|d< |  |||¡ d S )Nc                 S   s   t  | |¡S rS   )rœ   Zbitwise_andr]  rP   rP   rQ   rs  K  s    z.TestParfors.test_ufunc_expr.<locals>.test_implrÕ   r   rº   )rœ   rr  Zuint8r´   )rO   rs  r  rÉ  rP   rP   rQ   Útest_ufunc_exprI  s
    zTestParfors.test_ufunc_exprc                 C   s"   dd„ }|   t|tjfƒd¡ d S )Nc                 S   s(   t | fƒ}t| ƒD ]}|d ||< q|S )Nr  )Úunsafe_emptyrÐ   ©rÊ   r  rÎ   rP   rP   rQ   rs  T  s    
z;TestParfors.test_find_callname_intrinsic.<locals>.test_implrº   )r«   rY  r   r¹  r}  rP   rP   rQ   Útest_find_callname_intrinsicS  s    z(TestParfors.test_find_callname_intrinsicc                 C   s   dd„ }|   |d¡ d S )Nc                 S   s4   d}t | ƒD ]}|d7 }qt | ƒD ]}|d7 }q"|S rÅ   ri  ©rÊ   rc  rÎ   rP   rP   rQ   rs  `  s    

z7TestParfors.test_reduction_var_reuse.<locals>.test_implr^  r|  r}  rP   rP   rQ   Útest_reduction_var_reuse^  s    	z$TestParfors.test_reduction_var_reusec                 C   s,   dd„ }|   |t d¡t d¡ d¡¡ d S )Nc                 S   s,   d}t | jd ƒD ]}|| r|d7 }q|S ©Nrº   r   ©r   r#  )r  ÚcondrÕ  rÎ   rP   rP   rQ   rs  m  s
    
z8TestParfors.test_non_identity_initial.<locals>.test_implrÓ   Úbool©r´   rœ   rr  r  r}  rP   rP   rQ   Útest_non_identity_initialk  s    z%TestParfors.test_non_identity_initialc                 C   s,   dd„ }|   |t d¡t d¡ d¡¡ d S )Nc                 S   sF   d}d}t | jd ƒD ]&}|| r4|d7 }|d7 }q|d7 }q|| S )Nrº   rÓ   r   rÆ   rƒ  )r  r„  rÕ  r×  rÎ   rP   rP   rQ   rs  w  s    

z9TestParfors.test_if_not_else_reduction.<locals>.test_implrÓ   r…  r†  r}  rP   rP   rQ   Útest_if_not_else_reductionu  s    
z&TestParfors.test_if_not_else_reductionc                 C   s   dd„ }|   |d¡ d S )Nc                 S   sf   d}|d |d  }t  |t j¡}t  |¡ |¡}t | ¡D ]}||7 }q<t | ¡D ]}||7 }qT|S ©N©é   rj   r   rº   ©rœ   r  Úint_rn  r×   rŠ   r   ©rÊ   Úshpré  Úresult1ÚtmprÎ   rP   rP   rQ   rs  „  s    

z?TestParfors.test_two_d_array_reduction_reuse.<locals>.test_implrç  r|  r}  rP   rP   rQ   Ú test_two_d_array_reduction_reuseƒ  s    z,TestParfors.test_two_d_array_reduction_reusec                 C   s   dd„ }|   |d¡ d S )Nc                 S   s6   t  dt j¡}t | ¡D ]}|t  |gt j¡7 }q|S r‚  )rœ   r  r�  rŠ   r   r$  )rÊ   ÚresultrÎ   rP   rP   rQ   rs  •  s    z9TestParfors.test_one_d_array_reduction.<locals>.test_implrç  r|  r}  rP   rP   rQ   Útest_one_d_array_reduction”  s    z&TestParfors.test_one_d_array_reductionc                 C   s   dd„ }|   |d¡ d S )Nc                 S   sN   d}|d |d  }t  |t j¡}t  |¡ |¡}t | ¡D ]}||7 }q<|S r‰  rŒ  rŽ  rP   rP   rQ   rs     s    
z9TestParfors.test_two_d_array_reduction.<locals>.test_implrç  r|  r}  rP   rP   rQ   Útest_two_d_array_reductionŸ  s    z&TestParfors.test_two_d_array_reductionc                 C   s   dd„ }|   |d¡ d S )Nc                 S   sJ   d}t  |t j¡}t  ddddddg¡ |¡}t | ¡D ]}||7 }q8|S )NrÔ   r  r  rl  rm  r&  r'  )rœ   r  Úfloat32r$  r×   rŠ   r   ©rÊ   r�  r�  r‘  rÎ   rP   rP   rQ   rs  °  s    
zJTestParfors.test_two_d_array_reduction_with_float_sizes.<locals>.test_implrç  r|  r}  rP   rP   rQ   Ú+test_two_d_array_reduction_with_float_sizes­  s    
z7TestParfors.test_two_d_array_reduction_with_float_sizesc                 C   s   dd„ }|   |d¡ d S )Nc                 S   s@   d}dt  |t j¡ }dt  |¡ }t | ¡D ]}||9 }q.|S )NrŠ  rÆ   )rœ   rr  r�  Z	ones_likerŠ   r   r—  rP   rP   rQ   rs  ½  s    
z>TestParfors.test_two_d_array_reduction_prod.<locals>.test_implrç  r|  r}  rP   rP   rQ   Útest_two_d_array_reduction_prod¼  s    
z+TestParfors.test_two_d_array_reduction_prodc                 C   s   dd„ }|   |d¡ d S )Nc                 S   s8   d}t  |t j¡}t | ¡D ]}|t  |t j¡7 }q|S )N)rÕ   rÆ   r6  )rœ   r  r�  rŠ   r   rr  )rÊ   r�  r�  rÎ   rP   rP   rQ   rs  Ê  s
    z;TestParfors.test_three_d_array_reduction.<locals>.test_implrç  r|  r}  rP   rP   rQ   Útest_three_d_array_reductionÉ  s    	z(TestParfors.test_three_d_array_reductionc                 C   s&   dd„ }d}t  |¡}|  ||¡ d S )Nc                 S   s   |   ¡ d S r‚  )Zargsortræ  rP   rP   rQ   rs  ×  s    z>TestParfors.test_preparfor_canonicalize_kws.<locals>.test_implr  ©rœ   rn  r´   r_  rP   rP   rQ   Ú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æ  rP   rP   rQ   rs  à  s    z8TestParfors.test_preparfor_datetime64.<locals>.test_implrº   zdatetime64[ns])rœ   rZ  r…  r†   rŠ   r   r«   r¨   )rO   rs  r  r’   rP   rP   rQ   Útest_preparfor_datetime64Þ  s    z%TestParfors.test_preparfor_datetime64c                 C   s    dd„ }|   |tj d¡¡ d S )Nc                 S   sR   | j d }d}t|ƒD ]6}dddh}| |¡ d}|D ]}||7 }q6||7 }q|S )Nr   rº   rÆ   rÕ   )r#  r   rU  )r  rÊ   rc  rÎ   ÚRr‘  r�   rP   rP   rQ   rs  è  s    




zITestParfors.test_no_hoisting_with_member_function_call.<locals>.test_implrÚ  )r´   rœ   r´  rµ  r}  rP   rP   rQ   Ú*test_no_hoisting_with_member_function_callç  s    z6TestParfors.test_no_hoisting_with_member_function_callc                 C   s   dd„ }|   |¡ dS )zñ issue3671: X != 0 becomes an arrayexpr with operator.ne.
            That is turned into a parfor by devectorizing.  Make sure
            the return type of the devectorized operator.ne
            on integer types works properly.
        c                  S   s   t jdt jd�} | dkS )NrÓ   r„  r   )rœ   r  r�  ©r  rP   rP   rQ   rs  ü  s    z8TestParfors.test_array_compare_scalar.<locals>.test_implNr|  r}  rP   rP   rQ   Ú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 rp  )r­   r  )r�   Zhalfré  ZparrrP   rP   rQ   rs    s
    z?TestParfors.test_array_analysis_optional_def.<locals>.test_implr“  TFr7  r±  ©rO   rs  r�   rP   rP   rQ   Ú test_array_analysis_optional_def  s    
z,TestParfors.test_array_analysis_optional_defc              
   C   sd   dd„ }t jdtd�}t jdtd�}|  |||¡ |  t|t tjdd¡t tjdd¡fƒd¡ d S )Nc                 S   s`   t jt| ƒt jd�}t|ƒ}t |¡D ]}| | ||< q&t |¡D ]}|| ||  ||< qB|S )Nr„  )rœ   rZ  r­   r¼  rŠ   r   )rq   rr   Údataré  rÎ   rP   rP   rQ   rs    s    z7TestParfors.test_prange_side_effects.<locals>.test_implrç  r„  rº   rÁ  )	rœ   rn  Úfloatr´   r«   r¼   r   rÃ  r¼  )rO   rs  r�   r¥  rP   rP   rQ   Útest_prange_side_effects  s    	ÿÿþz$TestParfors.test_prange_side_effectsc                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s@   d}d}t  t| ƒ¡D ]$}| |  |d |d  | 7  < q| S )Nrk  r6  r   rº   )rŠ   r   r­   ©rq   Zatuprr   rÎ   rP   rP   rQ   rs  !  s
    "z*TestParfors.test_tuple1.<locals>.test_implrÓ   r›  r¢  rP   rP   rQ   Útest_tuple1   s    
zTestParfors.test_tuple1c                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s:   | j }d}t t| ƒ¡D ]}| |  |d | 7  < q| S )Nr6  r   )r#  rŠ   r   r­   r§  rP   rP   rQ   rs  ,  s
    z*TestParfors.test_tuple2.<locals>.test_implrÓ   r›  r¢  rP   rP   rQ   Útest_tuple2+  s    
zTestParfors.test_tuple2c                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   sN   t  d¡df}d}t t| ƒ¡D ](}| |  |d d |d  | 7  < q | S )NrÓ   rÚ   r6  r   rk   rº   )rœ   rn  rŠ   r   r­   r§  rP   rP   rQ   rs  7  s
    &z*TestParfors.test_tuple3.<locals>.test_implrÓ   r›  r¢  rP   rP   rQ   Útest_tuple36  s    
zTestParfors.test_tuple3c                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   sD   t ddd�}d}t t| ƒ¡D ] }| |  |j|j | 7  < q| S ©NrÕ   rÚ   rm   r6  )rl   rŠ   r   r­   rn   ro   ©rq   Zantuprr   rÎ   rP   rP   rQ   rs  B  s
    z/TestParfors.test_namedtuple1.<locals>.test_implrÓ   r›  r¢  rP   rP   rQ   Útest_namedtuple1A  s    
zTestParfors.test_namedtuple1c                    s0   t ddƒ‰ ‡ fdd„}t d¡}|  ||¡ d S )NÚTestNamedTuple2rm   c                    sD   ˆ ddd�}d}t  t| ƒ¡D ] }| |  |j|j | 7  < q| S r«  )rŠ   r   r­   rn   ro   r¬  ©r®  rP   rQ   rs  N  s
    z/TestParfors.test_namedtuple2.<locals>.test_implrÓ   )r   rœ   rn  r´   r¢  rP   r¯  rQ   Útest_namedtuple2L  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 )Nrk   ©r¥  r­  rP   rP   rQ   rs  ]  s    z/TestParfors.test_namedtuple3.<locals>.test_implc                 S   s   t j | j|j¡ d S rS   )rœ   r©   rª   r¥  rp   rP   rP   rQ   r¯  `  s    z.TestParfors.test_namedtuple3.<locals>.comparerrÓ   r²  r°  )r   rœ   r  r´   )rO   r±  rs  r¯  r�   rP   rP   rQ   Útest_namedtuple3X  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   rP   rp   rP   rP   rQ   rs  g  s    z1TestParfors.test_inplace_binop.<locals>.test_implrÓ   rç  rº   rÁ  )rœ   rn  r´   r«   r¼   r   rÃ  r¼  ©rO   rs  r  r  rP   rP   rQ   Útest_inplace_binopf  s    ÿÿþzTestParfors.test_inplace_binopc                 C   s&   dd„ }t  ddg¡}|  ||¡ d S )Nc                 S   sZ   t | ƒ}||f}tjd| d tjd�}|dd d …f }t| ƒD ]\}}||||f< q@|S )Nr{  r„  r   ©r­   rœ   r  Zuint64rD  ©rq   rÊ   Zarray_shapeÚindicesZk_listrÎ   r[  rP   rP   rQ   rs  t  s    z0TestParfors.test_tuple_concat.<locals>.test_implrº   r,  r¢  rP   rP   rQ   Útest_tuple_concatr  s    
zTestParfors.test_tuple_concatc                 C   s&   dd„ }t  ddg¡}|  ||¡ d S )Nc                 S   sb   t | ƒ}||f}tjd| d d d… tjd�}|dd d …f }t| ƒD ]\}}||||f< qH|S )Nr{  rH   r„  r   r¶  r·  rP   rP   rQ   rs  ƒ  s    ÿzCTestParfors.test_tuple_concat_with_reverse_slice.<locals>.test_implrº   r,  r¢  rP   rP   rQ   Ú$test_tuple_concat_with_reverse_slice�  s    z0TestParfors.test_tuple_concat_with_reverse_slicec                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s   | f| | f }|d   ¡ S rM  ©r  )rq   ÚSrP   rP   rQ   rs  “  s    z6TestParfors.test_array_tuple_concat.<locals>.test_impl©rÕ   rÕ   r±  r¢  rP   rP   rQ   Útest_array_tuple_concat‘  s    
z#TestParfors.test_array_tuple_concatc                 C   s"   dd„ }t  d¡}|  ||¡ d S )Nc                 S   s   | d S )Nr&  rP   r  rP   rP   rQ   rs  œ  s    z3TestParfors.test_high_dimension1.<locals>.test_impl)rÆ   rÆ   rÆ   rÆ   rÆ   é   r±  r¢  rP   rP   rQ   Útest_high_dimension1š  s    
z TestParfors.test_high_dimension1c                 C   s$   dd„ }d}|   |t |¡|¡ d S )Nc                 S   s   t  |¡D ]}d| |< q
| S r‚  ©rŠ   Zpndindex©r�   ÚszrÎ   rP   rP   rQ   rs  ¢  s    
z-TestParfors.test_tuple_arg.<locals>.test_impl©rÓ   rk   )r´   rœ   rZ  ©rO   rs  rÃ  rP   rP   rQ   Útest_tuple_arg¡  s    zTestParfors.test_tuple_argc                 C   s$   dd„ }d}|   |t |¡d¡ d S )Nc                 S   s   t  |¡D ]}d| |< q
| S r‚  rÁ  rÂ  rP   rP   rQ   rs  ª  s    
z=TestParfors.test_tuple_arg_not_whole_array.<locals>.test_implrÄ  ©rÓ   rÕ   ©r´   rœ   r  rÅ  rP   rP   rQ   Útest_tuple_arg_not_whole_array©  s    z*TestParfors.test_tuple_arg_not_whole_arrayc                 C   s"   dd„ }d}|   |t |¡¡ d S )Nc                 S   s    d}t  |¡D ]}d| |< q| S )NrÄ  rº   rÁ  rÂ  rP   rP   rQ   rs  ²  s    
z6TestParfors.test_tuple_for_pndindex.<locals>.test_implrÄ  rÈ  rÅ  rP   rP   rQ   Útest_tuple_for_pndindex±  s    z#TestParfors.test_tuple_for_pndindexc                 C   s$   dd„ }d}|   |t |¡d¡ d S )Nc                 S   s$   |df}t  |¡D ]}d| |< q| S r»  rÁ  )r�   ÚfirstrÃ  rÎ   rP   rP   rQ   rs  »  s    
z5TestParfors.test_tuple_arg_literal.<locals>.test_implrÄ  rÓ   rÈ  rÅ  rP   rP   rQ   Útest_tuple_arg_literalº  s    z"TestParfors.test_tuple_arg_literalc                    sX   dd„ ‰dd„ ‰ dd„ ‰ˆ ˆƒ ˆƒ‰‡ ‡‡‡‡fdd„}t t d	d
�fD ]}||ƒ qFd S )Nc                 S   s   t  |¡D ]}d| |< q
| S r‚  rÁ  rÂ  rP   rP   rQ   rs  Ç  s    
z?TestParfors.test_tuple_of_literal_nonliteral.<locals>.test_implc                 S   s
   || dƒS )NrÇ  rP   )r�   rê   rP   rP   rQ   r÷   Ì  s    z:TestParfors.test_tuple_of_literal_nonliteral.<locals>.callc                   S   s
   t  d¡S )Nr�  ©rœ   r  rP   rP   rP   rQ   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_inputrO   rs  rP   rQ   r´   Ò  s    z;TestParfors.test_tuple_of_literal_nonliteral.<locals>.checkTr0  ©r   )rO   r´   rr  rP   rÓ  rQ   Ú test_tuple_of_literal_nonliteralÃ  s    z,TestParfors.test_tuple_of_literal_nonliteralc                 C   s$   dd„ }d}|   |t |¡|¡ d S )Nc                 S   s   t  |¡D ]}d| |< q
| S r‚  rÁ  rÂ  rP   rP   rQ   rs  Ü  s    
z0TestParfors.test_tuple_arg_1d.<locals>.test_impl©rÓ   rÈ  rÅ  rP   rP   rQ   Útest_tuple_arg_1dÛ  s    zTestParfors.test_tuple_arg_1dc                 C   s"   dd„ }d}|   |t |¡¡ d S )Nc                 S   s    d}t  |¡D ]}d| |< q| S ©Nr×  rº   rÁ  rÂ  rP   rP   rQ   rs  ä  s    
z8TestParfors.test_tuple_arg_1d_literal.<locals>.test_implr×  rÈ  rÅ  rP   rP   rQ   Útest_tuple_arg_1d_literalã  s    z%TestParfors.test_tuple_arg_1d_literalc                 C   s    dd„ }|   |t d¡d¡ d S )Nc                 S   s   t  |¡D ]}d| |< q
| S r‚  rÁ  rÂ  rP   rP   rQ   rs  í  s    
z4TestParfors.test_int_arg_pndindex.<locals>.test_implr�  rÕ   rÈ  r}  rP   rP   rQ   Útest_int_arg_pndindexì  s    z!TestParfors.test_int_arg_pndindexc                    sl   t dd„ ƒ‰ ‡ fdd„}d}t ||f¡}tjd d …d d d…f tjf}|  t||ƒd¡ |  	|||¡ d S )Nc                 S   sF   t || d d d |d dƒD ] }| |d |f d | ||f< q d S ©Nrº   rÆ   r  )ÚurÎ   Zevenré  r  rP   rP   rQ   Úissue7854_procô  s    $z=TestParfors.test_prange_unknown_call1.<locals>.issue7854_procc                    sL   t  d|d ¡D ]}ˆ | |d|ƒ qt  d|d ¡D ]}ˆ | |d|ƒ q4| S r‚  ©rŠ   r   )rÝ  ré  rÎ   ©rÞ  rP   rQ   rs  û  s
    z8TestParfors.test_prange_unknown_call1.<locals>.test_implrÚ   rº   rÆ   )
rB   rœ   r  rŠ   r¼  r   r¸  r«   r¼   r´   ©rO   rs  ré  rÝ  ÚcptypesrP   rà  rQ   Útest_prange_unknown_call1ó  s    
z%TestParfors.test_prange_unknown_call1c                 C   s\   dd„ }d}t  ||f¡}tjd d …d d d…f tjf}|  t||ƒd¡ |  |||¡ d S )Nc                 S   s¨   t  d|d ¡D ]B}t|d d d |d dƒD ] }| |d |f d | ||f< q0qt  d|d ¡D ]>}t|d d |d dƒD ] }| |d |f d | ||f< q€qd| S rÜ  rV  )rÝ  ré  rÎ   r  rP   rP   rQ   rs    s       z6TestParfors.test_prange_index_calc1.<locals>.test_implrÚ   rº   rÆ   ©	rœ   r  rŠ   r¼  r   r¸  r«   r¼   r´   rá  rP   rP   rQ   Útest_prange_index_calc1  s    	z#TestParfors.test_prange_index_calc1c                 C   s‚   dd„ }d}t  ||f¡}t  ||f¡}tjd d …d d d…f tjd d …d d d…f tjf}|  t||ƒd¡ |  ||||¡ d S )Nc                 S   sp   t  |¡D ]*}t|ƒD ]}|||f d | ||f< qq
t  |¡D ]}t|ƒD ]}d|||f< qLq@| d |d  S )Nrº   rÕ   rŒ  rV  )rq   rr   ré  rÎ   r  rP   rP   rQ   rs    s    z9TestParfors.test_prange_reverse_order1.<locals>.test_implrÓ   rº   rÆ   rä  ©rO   rs  ré  rq   rr   râ  rP   rP   rQ   Ú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   rk   rß  )rq   ré  rr   rÎ   rP   rP   rQ   rs  0  s    
z@TestParfors.test_prange_parfor_index_then_not.<locals>.test_implrÓ   rÆ   rä  )rO   rs  ré  rq   râ  rP   rP   rQ   Ú!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 rC  rß  )rq   Útupré  rc  rÎ   rP   rP   rQ   rs  A  s    zJTestParfors.test_prange_parfor_index_const_tuple_fusion.<locals>.test_implrÓ   rº   )rœ   r  r�   rŠ   r¼  r   Ú
containersZUniTupler¹  r«   r¼   r´   ræ  rP   rP   rQ   Ú+test_prange_parfor_index_const_tuple_fusion>  s    
þz7TestParfors.test_prange_parfor_index_const_tuple_fusionc                 C   sf   dd„ }d}t  |¡}t  |¡}tjd d … tjd d … tjf}|  t||ƒd¡ |  ||||¡ d S )Nc                 S   sL   t  |¡D ]}| d ||< q
t  |¡D ]}|| |< q&|d  | d 7  < |S )Nrk   r   rß  )rq   rr   ré  rÎ   rP   rP   rQ   rs  U  s    
zITestParfors.test_prange_non_parfor_index_then_opposite.<locals>.test_implrÓ   rÆ   rä  ræ  rP   rP   rQ   Ú*test_prange_non_parfor_index_then_oppositeR  s    	

 z6TestParfors.test_prange_non_parfor_index_then_oppositec                 C   sF   ddd„}t  d¡}| j||d t jjdd„ gd� |  | ¡ d¡ d S )	Nc                 S   s"   t dƒD ]}|d k	rd| |< qd S )Nrº   rø  ri  )ÚarrÚpredrÎ   rP   rP   rQ   rs  f  s    z3TestParfors.test_prange_optional.<locals>.test_implrÓ   c                 S   s   | |kS rS   rP   ©r�   r¥  rP   rP   rQ   rë  n  rì  z2TestParfors.test_prange_optional.<locals>.<lambda>r°  r*  )N)rœ   rr  r´   r©   rª   r«   r  ©rO   rs  rí  rP   rP   rQ   Útest_prange_optionale  s    


ÿÿz TestParfors.test_prange_optionalc              	   C   s>   dd„ }|   t¡�}|  |¡ W 5 Q R X |  dt|jƒ¡ d S )Nc                  S   s   d} | d S )N©g333333ó?gÍÌÌÌÌÌô?r   rP   r­  rP   rP   rQ   rs  s  s    z8TestParfors.test_untraced_value_tuple.<locals>.test_implrt  ru  rx  rP   rP   rQ   Útest_untraced_value_tupleq  s    z%TestParfors.test_untraced_value_tuplec              	   C   s>   dd„ }|   t¡�}|  |¡ W 5 Q R X |  dt|jƒ¡ d S )Nc                  S   s   d} | d d S )N)rò  r   rP   r­  rP   rP   rQ   rs  }  s    zBTestParfors.test_recursive_untraced_value_tuple.<locals>.test_implrt  ru  rx  rP   rP   rQ   Ú#test_recursive_untraced_value_tuple{  s    z/TestParfors.test_recursive_untraced_value_tuplec                 C   sL   dd„ }t  t jdd¡f}|  t||ƒd¡ tjdtjd�}|  ||¡ d S )Nc                 S   s¦   d}t | ƒ}t |tj¡}t|ƒD ]}| | |d  ||< q"t |ƒ}t |tj¡}t|ƒD ]}|| |d  ||< qZd}t |ƒ}	t|	ƒD ]}
|||
 7 }qˆ||d  S )Nrò  r   rº   rø  ©r­   rœ   rZ  r¼  r   )rí  rq   Zn1Zarr2rÎ   Zn2Zarr3r  ÚtotalZn3rš   rP   rP   rQ   rs  ‡  s    z9TestParfors.test_untraced_value_parfor.<locals>.test_implrº   rÁ  rÓ   r„  )r   rÃ  r¸  r«   r¼   rœ   rn  r´   )rO   rs  rÞ  rí  rP   rP   rQ   Útest_untraced_value_parfor…  s
    z&TestParfors.test_untraced_value_parforc                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s<   d}t | jd ƒD ]$}|r| d| |d d …f< |d7 }q| S rC  )rÐ   r#  )r�   rû   rÊ   rP   rP   rQ   rs  Ÿ  s    
z;TestParfors.test_setitem_2d_one_replaced.<locals>.test_impl)rÕ   rº   rÈ  r}  rP   rP   rQ   Ú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œ   rn  ré  r  r¼  )rí  Zflag1Zflag2ÚinvÚretrP   rP   rQ   rs  ­  s    
z7TestParfors.test_1array_control_flow.<locals>.test_implrç  TFr›  rð  rP   rP   rQ   Útest_1array_control_flow«  s
    

z$TestParfors.test_1array_control_flowc                 C   s6   dd„ }t  d¡}|  ||dd¡ |  ||dd¡ d S )Nc                 S   s@   t  | j¡}t  || j| ¡}|r,|| }n||d  }|| S r‚  ©rœ   rn  ré  )rí  r'  ÚflagÚinv1Úinv2rú  rP   rP   rQ   rs  ¾  s    
z9TestParfors.test_2array_1_control_flow.<locals>.test_implrç  rÓ   TFr›  rð  rP   rP   rQ   Útest_2array_1_control_flow¼  s    	
z&TestParfors.test_2array_1_control_flowc                 C   s6   dd„ }t  d¡}|  ||dd¡ |  ||dd¡ d S )Nc                 S   sT   t  | j¡}t  || j| ¡}|r4|| }|| }n||d  }||d  }|| S r‚  rü  )rí  r'  rý  rþ  rÿ  Zret1Zret2rP   rP   rQ   rs  Í  s    
z9TestParfors.test_2array_2_control_flow.<locals>.test_implrç  rÓ   TFr›  rð  rP   rP   rQ   Útest_2array_2_control_flowË  s    
z&TestParfors.test_2array_2_control_flowc                 C   s.   dd„ }|   |d¡ |  t|tjfƒd¡ d S )Nc                 S   sˆ   t j| t jd�}t j| t jd�}t| ƒD ]"}t|ƒD ]}||  d7  < q4q(t| ƒD ]&}|dkrbqT|| ||d   ||< qT|dd … S )Nr„  rº   r   )rœ   r  r¹  r   rÐ   )rÊ   ÚrÚcrÎ   r  rP   rP   rQ   rs  à  s    z-TestParfors.test_issue8515.<locals>.test_implr¿  rÆ   )r´   r«   r¼   r   r¸  r}  rP   rP   rQ   Útest_issue8515Ü  s    zTestParfors.test_issue8515N)Lrc   rK   rd   r  rD  rI  rK  rO  rS  rU  rY  r`  rg  rj  rk  rl  ro  rq  r=   rt  rv  rx  r?   rz  r{  r|  r  r�  r‡  rˆ  r’  r”  r•  r˜  r™  rš  rœ  r�  rŸ  r¡  r£  r¦  r¨  r©  rª  r­  r°  r³  rµ  r¹  rº  r¾  rÀ  rÆ  rÉ  rÊ  rÌ  rÖ  rØ  rÚ  rÛ  rã  rå  rç  rè  rë  rì  rñ  ró  rô  r÷  rø  rû  r   r  r  rP   rP   rP   rQ   rB    s”   0
&





						

rB  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestParforsLeaksc                 O   s.   | j |f|žŽ \}}| j|||f|ž|Ž d S rS   r²   r³   rP   rP   rQ   r´   ó  s    zTestParforsLeaks.checkc                 C   s4   t dd�dd„ ƒ}t d¡ tj¡}|  ||¡ d S )NTr0  c                 S   s   |   ¡ S rS   r»  )rí  rP   rP   rQ   rs  ù  s    z2TestParforsLeaks.test_reduction.<locals>.test_implrÓ   ©r   rœ   rn  r  r¼  r´   rð  rP   rP   rQ   Útest_reduction÷  s    
zTestParforsLeaks.test_reductionc                 C   s4   t dd�dd„ ƒ}t d¡ tj¡}|  ||¡ d S )NTr0  c                 S   s@   d}d}t | jƒD ]$}|| | 7 }|d| | d  7 }q|| S )Nrø  r  rº   )r   ré  )rí  rq   rr   rÎ   rP   rP   rQ   rs  	  s    z@TestParforsLeaks.test_multiple_reduction_vars.<locals>.test_implrÓ   r  rð  rP   rP   rQ   Útest_multiple_reduction_vars 	  s    
z-TestParforsLeaks.test_multiple_reduction_varsN)rc   rK   rd   r´   r  r  rP   rP   rP   rQ   r  ñ  s   	r  c                   @   sü   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze
dd „ ƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚTestParforsSlicec                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s,   | j \}| d|d … | d|d …  }|S ©Nr   rÆ   rº   ©r#  ©rq   rÊ   rr   rP   rP   rQ   rs  	  s     z6TestParforsSlice.test_parfor_slice1.<locals>.test_implrÓ   ©r´   rœ   rr  r}  rP   rP   rQ   Útest_parfor_slice1	  s    z#TestParforsSlice.test_parfor_slice1c              	   C   sb   dd„ }|   |t d¡d¡ |  t¡� }tdd�|ƒt d¡dƒ W 5 Q R X |  dt|jƒ¡ d S )Nc                 S   s(   | j \}| d|d … | d|…  }|S r
  r  ©rq   rõ   rÊ   rr   rP   rP   rQ   rs  	  s    z6TestParforsSlice.test_parfor_slice2.<locals>.test_implrÓ   rT  Tr0  údo not match©	r´   rœ   rr  rv  r®   r   rÀ   rá   rw  rx  rP   rP   rQ   Útest_parfor_slice2	  s
    $z#TestParforsSlice.test_parfor_slice2c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s>   | j \}}| d|d …d|d …f | d|…d|…f  }|S rC  r  r  rP   rP   rQ   rs  &	  s    
0z6TestParforsSlice.test_parfor_slice3.<locals>.test_impl©rÚ   rÕ   r  r}  rP   rP   rQ   Útest_parfor_slice3%	  s    z#TestParforsSlice.test_parfor_slice3c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s:   | j \}}| d d …d|d …f | d d …d|…f  }|S rC  r  r  rP   rP   rQ   rs  .	  s    
,z6TestParforsSlice.test_parfor_slice4.<locals>.test_implr  r  r}  rP   rP   rQ   Útest_parfor_slice4-	  s    z#TestParforsSlice.test_parfor_slice4c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s:   | j \}}| d|d …d d …f | d|…d d …f  }|S rC  r  r  rP   rP   rQ   rs  6	  s    
,z6TestParforsSlice.test_parfor_slice5.<locals>.test_implr  r  r}  rP   rP   rQ   Útest_parfor_slice55	  s    z#TestParforsSlice.test_parfor_slice5c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s,   |   ¡ }| dd d …f |d d …df  }|S r‚  ©Ú	transpose©rq   rr   r  rP   rP   rQ   rs  >	  s     z6TestParforsSlice.test_parfor_slice6.<locals>.test_implr  r  r}  rP   rP   rQ   Útest_parfor_slice6=	  s    z#TestParforsSlice.test_parfor_slice6c              	   C   s^   dd„ }|   |t d¡¡ |  t¡�}tdd�|ƒt d¡ƒ W 5 Q R X |  dt|jƒ¡ d S )Nc                 S   s,   |   ¡ }| dd d …f |dd d …f  }|S r‚  r  r  rP   rP   rQ   rs  F	  s     z6TestParforsSlice.test_parfor_slice7.<locals>.test_implr½  Tr0  rk  r  r  rx  rP   rP   rQ   Útest_parfor_slice7E	  s
    "z#TestParforsSlice.test_parfor_slice7c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s:   | j \}}|  ¡ }| d|…d|…f |d|…d|…f< |S r‚  ©r#  r  r  rP   rP   rQ   rs  T	  s    
$z6TestParforsSlice.test_parfor_slice8.<locals>.test_implrT  r½  ©r´   rœ   rn  r×   r}  rP   rP   rQ   Útest_parfor_slice8R	  s    z#TestParforsSlice.test_parfor_slice8c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s:   | j \}}|  ¡ }| d d …d|…f |d|…d|…f< |S r‚  r  r  rP   rP   rQ   rs  ^	  s    
$z6TestParforsSlice.test_parfor_slice9.<locals>.test_implrF  rk  r  r}  rP   rP   rQ   Útest_parfor_slice9\	  s    z#TestParforsSlice.test_parfor_slice9c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s2   | j \}}|  ¡ }| dd|…f |dd|…f< |S r¾  r  r  rP   rP   rQ   rs  h	  s    
z7TestParforsSlice.test_parfor_slice10.<locals>.test_implrT  r½  r  r}  rP   rP   rQ   Útest_parfor_slice10f	  s    z$TestParforsSlice.test_parfor_slice10c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s@   | j \}}}|  ¡ }| d d …dd|…f |d d …dd|…f< |S r¾  ©r#  rž   )rq   rõ   rÊ   r'  rr   rP   rP   rQ   rs  q	  s    (z7TestParforsSlice.test_parfor_slice11.<locals>.test_implé   )rÕ   rÕ   rÕ   r  r}  rP   rP   rQ   Útest_parfor_slice11p	  s    z$TestParforsSlice.test_parfor_slice11c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s2   | j \}}|  ¡ }| dd d…f |ddd…f< |S )Nr   éþÿÿÿrº   rH   r!  r  rP   rP   rQ   rs  z	  s    
z7TestParforsSlice.test_parfor_slice12.<locals>.test_implrF  rk  r  r}  rP   rP   rQ   Útest_parfor_slice12y	  s    z$TestParforsSlice.test_parfor_slice12c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s<   | j \}}|  ¡ }d}| d| |d …f |dd|…f< |S )NrH   r   rº   r!  )rq   rõ   rÊ   rr   r  rP   rP   rQ   rs  ƒ	  s
    
"z7TestParforsSlice.test_parfor_slice13.<locals>.test_implrF  rk  r  r}  rP   rP   rQ   Útest_parfor_slice13‚	  s    z$TestParforsSlice.test_parfor_slice13c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s2   | j \}}|  ¡ }| ddd…f |dd d…f< |S )Nr   éýÿÿÿrÚ   rº   rH   r!  r  rP   rP   rQ   rs  �	  s    
z7TestParforsSlice.test_parfor_slice14.<locals>.test_implrF  rk  r  r}  rP   rP   rQ   Útest_parfor_slice14Œ	  s    z$TestParforsSlice.test_parfor_slice14c                 C   s$   dd„ }|   |t d¡ d¡¡ d S )Nc                 S   s8   | j \}}|  ¡ }| ddd…f |d|d  d …f< |S )Nr   r'  rÚ   rº   r!  r  rP   rP   rQ   rs  –	  s    
"z7TestParforsSlice.test_parfor_slice15.<locals>.test_implrF  rk  r  r}  rP   rP   rQ   Útest_parfor_slice15•	  s    z$TestParforsSlice.test_parfor_slice15c                 C   sZ   dd„ }|   |t d¡t d¡d¡ tjdd… tjdd… tjf}|  t||ƒd¡ dS )zÞ This test is disabled because if n is larger than the array size
            then n and n-1 will both be the end of the array and thus the
            slices will in fact be of different sizes and unable to fuse.
        c                 S   s4   | j |j kst‚d| d|…< d|d|d …< | | S ©NrÓ   rº   r   )r#  r®   )rq   rr   rÊ   rP   rP   rQ   rs  ¤	  s    z7TestParforsSlice.test_parfor_slice16.<locals>.test_implrÓ   é   NrÆ   )	r´   rœ   rr  r  rŠ   r¼  r¸  r«   r¼   ©rO   rs  r}   rP   rP   rQ   Ú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œ   r  r­   )rõ   r  rÉ  rÊ   rP   rP   rQ   rs  ¯	  s    
z7TestParforsSlice.test_parfor_slice17.<locals>.test_implrÓ   r  r}  rP   rP   rQ   Útest_parfor_slice17®	  s    z$TestParforsSlice.test_parfor_slice17c                 C   s   dd„ }|   |¡ d S )Nc                  S   s*   t  d¡} t  dd¡| dd…< | d }|S )NrÓ   r   r6  rº   r+  rÕ   )rœ   r  rn  )rq   r¥  rP   rP   rQ   rs  ¹	  s    
z7TestParforsSlice.test_parfor_slice18.<locals>.test_implr|  r}  rP   rP   rQ   Útest_parfor_slice18·	  s    z$TestParforsSlice.test_parfor_slice18c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s   | d d…  d7  < | S rC  rP   r   rP   rP   rQ   rs  Ã	  s    z7TestParforsSlice.test_parfor_slice19.<locals>.test_implrÓ   r  r}  rP   rP   rQ   Útest_parfor_slice19Á	  s    z$TestParforsSlice.test_parfor_slice19c                 C   s   dd„ }| j |dd� d S )Nc                  S   s"   t  d¡} | dd … }t|ƒ}|S )NrÓ   rº   )rœ   rr  r­   )rq   r  rÕ  rP   rP   rQ   rs  Ë	  s    
z7TestParforsSlice.test_parfor_slice20.<locals>.test_implFr7  r|  r}  rP   rP   rQ   Ú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º   rH   )r×   ré  )Úx1Úx2rP   rP   rQ   rs  Ô	  s    z7TestParforsSlice.test_parfor_slice21.<locals>.test_implrk   rØ   )rœ   r´  rX  r´   ©rO   rs  r3  r4  rP   rP   rQ   Útest_parfor_slice21Ó	  s    z$TestParforsSlice.test_parfor_slice21c                 C   s.   dd„ }t  d¡}t  d¡}|  |||¡ d S )Nc                 S   s0   t  d¡}tdƒD ]}|| d d …|f 7 }q|S rÙ  )rœ   r  r   )r3  r4  rr   rÎ   rP   rP   rQ   rs  Þ	  s    
z7TestParforsSlice.test_parfor_slice22.<locals>.test_impl)rÓ   r6  rÚ   )rœ   r  r$  r´   r5  rP   rP   rQ   Útest_parfor_slice22Ý	  s    

z$TestParforsSlice.test_parfor_slice22c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s   d| d d…< | S )NrÆ   r   rP   r  rP   rP   rQ   rs  ê	  s    z7TestParforsSlice.test_parfor_slice23.<locals>.test_implrÓ   r  r}  rP   rP   rQ   Útest_parfor_slice23è	  s    z$TestParforsSlice.test_parfor_slice23c                 C   s2   dd„ }t ddƒD ]}|  |dt d¡|¡ qd S )Nc                 S   s*   t  | ¡}||d … }|d t|ƒ… }|S rS   r.  ©rõ   r  rÊ   rÉ  rÁ  rP   rP   rQ   rs  ñ	  s    
z7TestParforsSlice.test_parfor_slice24.<locals>.test_impléñÿÿÿr¿  rÓ   ©rÐ   r´   rœ   rr  ©rO   rs  rÎ   rP   rP   rQ   Útest_parfor_slice24ð	  s    z$TestParforsSlice.test_parfor_slice24c                 C   s2   dd„ }t ddƒD ]}|  |dt d¡|¡ qd S )Nc                 S   s*   t  | ¡}|d |… }|d t|ƒ… }|S rS   r.  r9  rP   rP   rQ   rs  û	  s    
z7TestParforsSlice.test_parfor_slice25.<locals>.test_implr:  r¿  rÓ   r;  r<  rP   rP   rQ   Útest_parfor_slice25ú	  s    z$TestParforsSlice.test_parfor_slice25c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s.   | j \}|  ¡ }| dd… ||d  d …< |S )Nr'  rÚ   rº   r!  r  rP   rP   rQ   rs  
  s    z7TestParforsSlice.test_parfor_slice26.<locals>.test_implrÚ   ©r´   rœ   rn  r}  rP   rP   rQ   Útest_parfor_slice26
  s    z$TestParforsSlice.test_parfor_slice26c                 C   s   dd„ }|   |t d¡¡ d S )Nc                 S   s@   d}t | jd ƒD ](}| | dkr*|d7 }|r| d |… }qdS rC  rƒ  )rq   Zn_valid_valsrÎ   ZunusedrP   rP   rQ   rs  
  s    z7TestParforsSlice.test_parfor_slice27.<locals>.test_implrÕ   r?  r}  rP   rP   rQ   Útest_parfor_slice27
  s    z$TestParforsSlice.test_parfor_slice27c                    sŒ   t ddd ƒt dd d ƒt d ddƒt d d d ƒt d d dƒfD ]P‰ ‡ fdd„}d}|  ||¡ t |d	 ¡ |d	f¡}‡ fd
d„}|  ||¡ q6d S )Nrº   rÕ   rÆ   rH   r$  c                    sD   t  | d ¡ | df¡}d}t | ¡D ]}|||ˆ f  ¡ 7 }q&|S ©NrÚ   r   )rœ   rn  r×   rŠ   r   r  rw  ©ÚtsrP   rQ   rs  "
  s
    zHTestParforsSlice.test_parfor_array_access_lower_slice.<locals>.test_implrÓ   rÚ   c                    s2   d}t  | jd ¡D ]}|| |ˆ f  ¡ 7 }q|S rM  )rŠ   r   r#  r  )r  r¥  rÎ   rC  rP   rQ   rs  .
  s    )Úslicer´   rœ   rn  r×   ©rO   rs  rÊ   r  rP   rC  rQ   Ú$test_parfor_array_access_lower_slice
  s    
 
ÿz5TestParforsSlice.test_parfor_array_access_lower_sliceN) rc   rK   rd   r  r  r  r  r  r  r  r?   r  r  r   r#  r%  r&  r(  r)  r-  r/  r0  r1  r2  r6  r7  r8  r=  r>  r@  rA  rG  rP   rP   rP   rQ   r	  	  s@   
	
	
			
		
	




	r	  c                   @   s   e Zd Zdd„ ZdS )ÚTestParforsOptionsc                 C   sâ   dd„ }|   |t d¡¡ tjd d … f}|  t||ƒd¡ |  t||dd�d¡ |  t||ddd�d	¡ |  t||dddd
�d¡ |  t||ddddd�d¡ |  t||dddddd�d¡ |  t||ddddddd�d¡ d S )Nc                 S   sr   | j d }t |¡}t dd„ t|ƒD ƒ¡}| ||  |d |…< t|ƒD ]}|| | |  ||< qHtdd„ |dƒS )Nr   c                 S   s   g | ]}|‘qS rP   rP   rÍ   rP   rP   rQ   rŽ   >
  s     zMTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<listcomp>c                 S   s   | | S rS   rP   rï  rP   rP   rQ   rë  B
  rì  zKTestParforsOptions.test_parfor_options.<locals>.test_impl.<locals>.<lambda>)r#  rœ   rr  r$  rÐ   r   r   )rq   rÊ   rr   r  rÎ   rP   rP   rQ   rs  ;
  s    

z9TestParforsOptions.test_parfor_options.<locals>.test_implrÓ   rº   F)ÚfusionrØ   )rI  Úcomprehensionrk   )rI  rJ  ÚsetitemrÚ   )rI  rJ  rK  r   rÕ   )rI  rJ  rK  r   Ú	reductionrÆ   )rI  rJ  rK  r   rL  r[  r   )r´   rœ   rr  rŠ   r¼  r«   r¼   r,  rP   rP   rQ   Útest_parfor_options:
  sP    	ÿÿ ÿÿ  ÿÿ  þþ   þþz&TestParforsOptions.test_parfor_optionsN)rc   rK   rd   rM  rP   rP   rP   rQ   rH  7
  s   rH  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestParforsBitMaskc                 C   s    dd„ }|   |t d¡d¡ d S )Nc                 S   s   | |k}d| |< | S rM  rP   r  rP   rP   rQ   rs  a
  s    z:TestParforsBitMask.test_parfor_bitmask1.<locals>.test_implrÓ   rk   r?  r}  rP   rP   rQ   Útest_parfor_bitmask1`
  s    z'TestParforsBitMask.test_parfor_bitmask1c                 C   s,   dd„ }t  d¡}|dk}|  |||¡ d S )Nc                 S   s   d| |< | S rM  rP   rp   rP   rP   rQ   rs  i
  s    z:TestParforsBitMask.test_parfor_bitmask2.<locals>.test_implrÓ   rk   r›  r-  rP   rP   rQ   Útest_parfor_bitmask2h
  s    
z'TestParforsBitMask.test_parfor_bitmask2c                 C   s,   dd„ }t  d¡}|dk}|  |||¡ d S )Nc                 S   s   | | | |< | S rS   rP   rp   rP   rP   rQ   rs  r
  s    z:TestParforsBitMask.test_parfor_bitmask3.<locals>.test_implrÓ   rk   r›  r-  rP   rP   rQ   Útest_parfor_bitmask3q
  s    
z'TestParforsBitMask.test_parfor_bitmask3c                 C   s,   dd„ }t  d¡}|dk}|  |||¡ d S )Nc                 S   s   d|  | | |< | S r  rP   rp   rP   rP   rQ   rs  {
  s    z:TestParforsBitMask.test_parfor_bitmask4.<locals>.test_implrÓ   rk   r›  r-  rP   rP   rQ   Útest_parfor_bitmask4z
  s    
z'TestParforsBitMask.test_parfor_bitmask4c                 C   s,   dd„ }t  d¡}|dk}|  |||¡ d S )Nc                 S   s   | | | |  | |< | S rS   rP   rp   rP   rP   rQ   rs  „
  s    z:TestParforsBitMask.test_parfor_bitmask5.<locals>.test_implrÓ   rk   r›  r-  rP   rP   rQ   Útest_parfor_bitmask5ƒ
  s    
z'TestParforsBitMask.test_parfor_bitmask5c              	   C   sd   dd„ }t  d¡}|dk}t  t|ƒ¡}|  t¡�}|  ||||¡ W 5 Q R X |  dt|j	ƒ¡ d S )Nc                 S   s   || |< | S rS   rP   r  rP   rP   rQ   rs  �
  s    z:TestParforsBitMask.test_parfor_bitmask6.<locals>.test_implrÓ   rk   rt  )
rœ   rn  r  r  rv  r®   r´   rÀ   rá   rw  )rO   rs  rq   rr   r  ry  rP   rP   rQ   Útest_parfor_bitmask6Œ
  s    
z'TestParforsBitMask.test_parfor_bitmask6N)	rc   rK   rd   rO  rP  rQ  rR  rS  rT  rP   rP   rP   rQ   rN  ]
  s   				rN  c                   @   sÐ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zed(d)„ ƒZd*d+„ Zd,d-„ Zd.d/„ Zd0S )1ÚTestParforsMiscz?
    Tests miscellaneous parts of ParallelAccelerator use.
    c              	   C   sš   dd„ }t ddd�|ƒ}tjdd��:}t d¡ tjddd	� tjdd
tjjdd� |ƒ  W 5 Q R X |  t	|ƒd¡ dd„ |j
 ¡ D ƒ}|  |dg¡ d S )Nc                  S   s.   t  d¡} t| jƒD ]}| |  |7  < q| S ©Nrç  )rœ   rr  r   ré  )rí  rÎ   rP   rP   rQ   r�   ¢
  s    
z9TestParforsMisc.test_no_warn_if_cache_set.<locals>.pyfuncT)r1  Ú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 rP   )rÁ   Úhas_dynamic_globals)rŒ   rÃ   rP   rP   rQ   rŽ   ¸
  s   ÿz=TestParforsMisc.test_no_warn_if_cache_set.<locals>.<listcomp>F)r   ÚwarningsÚcatch_warningsÚsimplefilterÚfilterwarningsrŠ   r   ZNumbaWarningr«   r­   Z	overloadsrW  )rO   r�   r“   Úraised_warningsr`  rP   rP   rQ   Útest_no_warn_if_cache_set 
  s$    
ÿýÿz)TestParforsMisc.test_no_warn_if_cache_setc              	   C   sP   dd„ }|   |d¡}tƒ �}| ¡  W 5 Q R X | ¡  ¡ D ]}|  d|¡ q:d S )Nc                  S   s>   t  d¡} t  dd¡| dd…< td| d ƒ td| d ƒ | S )NrÓ   r   r6  rº   r+  za[3]:rÕ   )rœ   r  rn  Úprintr­  rP   rP   rQ   r·   ½
  s
    
zITestParforsMisc.test_statement_reordering_respects_aliasing.<locals>.implrP   z	a[3]: 2.0)r†   r6   r¨   Úgetvaluerñ   r«   )rO   r·   rÃ   ÚstdoutÚlinerP   rP   rQ   Ú+test_statement_reordering_respects_aliasing¼
  s    z;TestParforsMisc.test_statement_reordering_respects_aliasingc                 C   sf   dd„ }t  t jdg¡}tdd�|ƒ}tjjj}z$dtjj_t j 	||ƒ||ƒ¡ W 5 |tjj_X d S )Nc                 S   s
   t  | ¡S rS   )rœ   Úisinfræ  rP   rP   rQ   rs  Ë
  s    z;TestParforsMisc.test_parfor_ufunc_typing.<locals>.test_implrø  Tr0  )
rœ   r$  r
  r   rŠ   r8  r9  Úsequential_parfor_loweringr©   Zassert_array_equal)rO   rs  r  r“   Zold_seq_flagrP   rP   rQ   Útest_parfor_ufunc_typingÊ
  s    

z(TestParforsMisc.test_parfor_ufunc_typingc                 C   s   dd„ }|   t|dƒd¡ d S )Nc                  S   sJ   d} dddddg}t jj ¡  |}t  d¡D ]}| || 7 } q,| |d  S )Nr   rº   rÆ   rÕ   rÚ   rk   )rŠ   r8  r9  Zinit_pranger   )Úresrí  ÚdummyrÎ   rP   rP   rQ   rs  Û
  s    z6TestParforsMisc.test_init_block_dce.<locals>.test_implrP   r   )r«   rO  r}  rP   rP   rQ   Útest_init_block_dceÙ
  s    	z#TestParforsMisc.test_init_block_dcec                 C   s   dd„ }|   |¡ d S )Nc                  S   s*   d} t dƒD ]}| d7 } qt | f¡}|S )Nr   rÚ   rº   ©rÐ   rœ   r  )rc  rI   r¤  rP   rP   rQ   rs  ç
  s
    
zBTestParforsMisc.test_alias_analysis_for_parfor1.<locals>.test_implr|  r}  rP   rP   rQ   Útest_alias_analysis_for_parfor1æ
  s    z/TestParforsMisc.test_alias_analysis_for_parfor1c              	      s    d‰ t ddd�G ‡ fdd„dtƒƒ‰G ‡fdd„dtƒ}td|d	�d
d„ ƒ}|  tjjj¡ |  	t
j¡�}|ƒ  W 5 Q R X |  ˆ t|jƒ¡ |  tjjj¡ d S )NÚ
BROKEN_MSGTF)Zmutates_CFGZanalysis_onlyc                       s$   e Zd ZdZdd„ Z‡ fdd„ZdS )zVTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsZbreak_parforsc                 S   s   t  | ¡ d S rS   )r3   r{   rU   rP   rP   rQ   r{   ü
  s    z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.__init__c                    sR   |j j ¡ D ]@}|jD ]0}t|tjjjƒrG ‡ fdd„dt	ƒ}|ƒ |_
q dS d S )Nc                       s   e Zd Z‡ fdd„ZdS )zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Brokenc                    s   t  ˆ ¡‚d S rS   )r   ÚLoweringError)rO   Úother©rt  rP   rQ   Ú
difference  s    zzTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_pass.<locals>.Broken.differenceN)rc   rK   rd   rx  rP   rw  rP   rQ   ÚBroken	  s   ry  T)r*  r<  rW  rE  r›   rŠ   r8  r9  rF  r£   Zraces)rO   r2  Zblkrc  ry  rw  rP   rQ   Úrun_passÿ
  s    

z_TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParfors.run_passN)rc   rK   rd   Ú_namer{   rz  rP   rw  rP   rQ   ÚBreakParforsø
  s   r|  c                       s   e Zd Z‡ fdd„ZdS )z^TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompilerc                    s&   t  | j¡}| ˆ t¡ | ¡  |gS rS   )r1   Zdefine_nopython_pipeliner2  Zadd_pass_afterr4   Úfinalize)rO   Úpm©r|  rP   rQ   Údefine_pipelines  s    zoTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.BreakParforsCompiler.define_pipelinesN)rc   rK   rd   r€  rP   r  rP   rQ   ÚBreakParforsCompiler  s   r�  )r1  Zpipeline_classc                  S   s   d} t dƒD ]}| d7 } q| S r‚  ri  )r�   rI   rP   rP   rQ   Úfoo  s    
zMTestParforsMisc.test_no_state_change_in_gufunc_lowering_on_error.<locals>.foo)r2   r3   r0   r   ÚassertFalserŠ   r8  r9  rm  rv  r   ru  rÀ   rá   rw  )rO   r�  r‚  ry  rP   )rt  r|  rQ   Ú0test_no_state_change_in_gufunc_lowering_on_errorñ
  s    
	

z@TestParforsMisc.test_no_state_change_in_gufunc_lowering_on_errorc                    sØ   G dd„ dt jƒ}|dƒ‰t|ƒtjƒ G dd„ dtƒ}t |¡‡fdd„ƒ}t|ƒdd	„ ƒ}t	|d
ddid�dd„ ƒ}t
dd„ ƒ‰ t
‡ fdd„ƒ}tjjj}|  |¡ z||ƒ ƒ |  tjjj¡ W 5 |tjj_X d S )Nc                   @   s   e Zd ZdS )z2TestParforsMisc.test_issue_5098.<locals>.DummyTypeN©rc   rK   rd   rP   rP   rP   rQ   Ú	DummyType.  s   r†  Zmy_dummyc                   @   s   e Zd ZdS )z.TestParforsMisc.test_issue_5098.<locals>.DummyNr…  rP   rP   rP   rQ   ÚDummy4  s   r‡  c                    s   ˆ S rS   rP   )Úvalr  )Ú
dummy_typerP   rQ   Útypeof_Dummy7  s    z5TestParforsMisc.test_issue_5098.<locals>.typeof_Dummyc                 S   s   t |j ¡ ƒS rS   )r!   ÚcontextZget_dummy_value)ÚtypÚobjr  rP   rP   rQ   Úunbox_index;  s    z4TestParforsMisc.test_issue_5098.<locals>.unbox_indexÚmethod1r1  T)Zjit_optionsc                 S   s   dd„ }|S )Nc                 S   sp   dd„ }t |ƒ}tj|tjd�}t|ƒD ]}||| |ƒ||< q(t|d ƒD ]}||  ||| |ƒ7  < qL|S )Nc                 S   s    |   ¡ }tj|t | ¡< ||ƒS rS   )rž   rœ   r  rl  )rq   Úfr  rP   rP   rQ   ÚbazB  s    zPTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foo.<locals>.bazr„  rº   rõ  )r�  rí  r‚   r‘  ÚlengthZ
output_arrrÎ   rP   rP   rQ   Ú_fooA  s    zCTestParforsMisc.test_issue_5098.<locals>._get_method1.<locals>._foorP   )r�  rí  r‚   r“  rP   rP   rQ   Ú_get_method1?  s    z5TestParforsMisc.test_issue_5098.<locals>._get_method1c                 S   s   |   ¡ S rS   rå  )re  rP   rP   rQ   ÚbarP  s    z,TestParforsMisc.test_issue_5098.<locals>.barc                    s"   |   t dddgdddgg¡ˆ ¡S )Nr  r  rl  rm  r&  r'  )r�  rœ   r$  )rr  )r•  rP   rQ   Útest1T  s    z.TestParforsMisc.test_issue_5098.<locals>.test1)r   ZOpaquer   r"   ZOpaqueModelÚobjectr   Úregisterr    r   r   rŠ   r8  r9  rm  rƒ  )rO   r†  r‡  rŠ  rŽ  r”  r–  Z
save_staterP   )r•  r‰  rQ   Útest_issue_5098-  s(    





zTestParforsMisc.test_issue_5098c              
   C   sn   t dd�dd„ ƒ}tddƒ�& |  tj¡�}|dƒ W 5 Q R X W 5 Q R X t|jƒ}|  d|¡ |  d	|¡ d S )
NTr0  c                 S   s&   d}d}t dƒD ]}|||  7 }q|S )N)rº   rÆ   rÕ   rÚ   r   rÓ   ri  )ÚidxZbig_tupr$  r�   rP   rP   rQ   Úoversize_tupled  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   r8   rv  r   r>  rá   rw  rÀ   )rO   r›  ry  ZerrstrrP   rP   rQ   Ú%test_oversized_tuple_as_arg_to_kernelb  s    

z5TestParforsMisc.test_oversized_tuple_as_arg_to_kernelc                 C   sB   dd„ }d}t jjdd|d�}t jjdd|d�}|  |||¡ d S )Nc                 S   s~   d}t j| j|| jd�}| j}t|d ƒD ]N}t|d ƒD ]<}| ||f |||f  | ||f |||f   |||f< q:q*|S ©Nr   r„  rº   )rœ   Úfullr#  r…  r   )Zimg_nirZimg_redÚ	fillvalueZout_imgZdimsr¥  r�   rP   rP   rQ   Ú	ndvi_njitv  s    ÿz1TestParforsMisc.test_issue5167.<locals>.ndvi_njit)rÚ   rÚ   r  g     ˆÃ@)Úlowrù  ré  )rœ   r´  Úuniformr´   )rO   r¡  Z
tile_shapeZarray1Zarray2rP   rP   rQ   Útest_issue5167t  s
    
zTestParforsMisc.test_issue5167c                 C   s^   dd„ }t dd„ ƒ}tjjdd�}t dd�|ƒ| ¡ |d	ƒ}|| ¡ |d	ƒ}tj ||¡ d S )
Nc                 S   s‚   t j| jd | jd ft jd�}t| jd ƒD ]N}t|d | jd ƒD ]4}|| | | | f|žŽ }||||f< ||||f< qFq.|S rž  )rœ   r  r#  r–  r   rÐ   )rq   r  Ú	dist_argsr“  rÎ   r  rr  rP   rP   rQ   Ú
reproducer‡  s     z2TestParforsMisc.test_issue5065.<locals>.reproducerc                 S   s:   d}t | jd ƒD ]}|| | ||  d 7 }qt |¡S )Nrø  r   rÆ   )rÐ   r#  rœ   r   )r�   r¥  r“  rÎ   rP   rP   rQ   Ú	euclidean�  s    z1TestParforsMisc.test_issue5065.<locals>.euclidean)rk   rÆ   rè  Tr0  rP   )r   rœ   r´  rž   r©   r  )rO   r¦  r§  rq   rÒ  rÔ  rP   rP   rQ   Ú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 rM  )r­   r   )Úmyarrayr“  rÎ   rP   rP   rQ   Útest_numba_parallel   s    z;TestParforsMisc.test_issue5001.<locals>.test_numba_parallelrç  é2   )rœ   rZ  r´   )rO   rª  r©  rP   rP   rQ   Ú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   rP   )ÚgridsrP   rP   rQ   r‚  «  s    z+TestParforsMisc.test_issue3169.<locals>.fooTr0  c                    s   t dƒD ]}ˆ | ƒ qd S r‚  ri  )r­  r�   ©r‚  rP   rQ   r•  ¯  s    z+TestParforsMisc.test_issue3169.<locals>.barrº   rÆ   rÕ  )rO   r•  rP   r®  rQ   Ú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Úmytyperp   c                    s   t dƒD ]}ˆ || ƒ q| jS rC  )r   rq   )Úmydatarš   ©ÚinnerrP   rQ   Úouter¼  s    z-TestParforsMisc.test_issue4846.<locals>.outerT)Znogilc                 S   s   | |j f}| |jf}d S rS   rp   )rš   r±  r�  r[  rP   rP   rQ   r³  Á  s    
z-TestParforsMisc.test_issue4846.<locals>.innerrq   rr   )r   r   r´   )rO   r°  r´  r±  rP   r²  rQ   Útest_issue4846·  s    

zTestParforsMisc.test_issue4846c                 C   s   dd„ }|   |¡ d S )Nc                  S   s*   d} d}t t| ƒƒD ]}|| | 7 }q|S )N)rº   rÆ   rÕ   rÚ   rk   r   )r   r­   )r�   rq   rÎ   rP   rP   rQ   Útest1bÌ  s
    z.TestParforsMisc.test_issue3748.<locals>.test1br|  )rO   r¶  rP   rP   rQ   Ú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      @ri  )ré  rí  r�   r¥  rP   rP   rQ   Úparallel_test×  s    z5TestParforsMisc.test_issue5277.<locals>.parallel_testr�  r„  )rœ   r  Úintr´   )rO   r¸  ré  rí  rP   rP   rQ   Útest_issue5277Õ  s    zTestParforsMisc.test_issue5277c                 C   sL   t dd�dd„ ƒ}t d¡}d}t d¡}|  ||||ƒ| |||¡¡ d S )NTr0  c                 S   s8   t dƒD ]}tdƒD ]}d|||f< qq|r4|d7 }|S r‚  )r   rÐ   )rÏ   Úmethodry  rÎ   r  rP   rP   rQ   r‚  ã  s    z5TestParforsMisc.test_issue5570_ssa_races.<locals>.foo)rk   rk   é9   r  )r   rœ   r  rÎ  Úpy_func)rO   r‚  rÏ   r»  ry  rP   rP   rQ   Ú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 )NTr0  c                 S   s4   | }t ddƒD ]}||d d …d d …f }qt |¡S )Nr   rÓ   )rÐ   rœ   rÎ  )r}   Úpackagerg  Zz_stackrP   rP   rQ   Úfind_maxima_3D_jitö  s    zDTestParforsMisc.test_issue6095_numpy_max.<locals>.find_maxima_3D_jitr   )rÓ   rÓ   rÓ   )r   rœ   r´  rÂ  rÎ  r½  )rO   rÀ  r}   rP   rP   rQ   Útest_issue6095_numpy_maxõ  s    
þz(TestParforsMisc.test_issue6095_numpy_maxc                 C   sJ   dd„ }d}d}t j||ft jd�}t j||ft jd�}|  |||¡ d S )Nc                 S   sP   | j }|d }t|ƒD ]4}| |d d …f ||d d …f< ||df  d7  < q|S rC  )r#  r   )ÚggÚgg_nextÚgsrr  Úi_ggrP   rP   rQ   rs    s    z3TestParforsMisc.test_issue5942_1.<locals>.test_implrÚ   rÆ   r„  )rœ   r  r	  r´   )rO   rs  rr  rš   rÂ  rÃ  rP   rP   rQ   Útest_issue5942_1  s    	z TestParforsMisc.test_issue5942_1c                 C   s"   dd„ }d}d}|   |||¡ d S )Nc                 S   s„   t j| |ft jd�}t j| |ft jd�}t| ƒD ]N}t|ƒD ]}||||f< q<||d d …f ||d d …f< ||df  d7  < q0|S )Nr„  r   rº   )rœ   r  r	  r   rÐ   )rr  rš   rÂ  rÃ  rÅ  rÊ   rP   rP   rQ   rs    s    z3TestParforsMisc.test_issue5942_2.<locals>.test_implrÚ   rÆ   r|  )rO   rs  rr  rš   rP   rP   rQ   Útest_issue5942_2  s    z TestParforsMisc.test_issue5942_2c                 C   sF   t dd�dd„ ƒ}t dddgdddgg¡}|  ||ƒ| |¡¡ d S )NTr0  c                 S   s”   t | jd ƒD ]€}tj}tjdddgtjd�}dD ]B}tj | |d d …f | ¡}||k r2|}tj|||gtjd�}q2| |d d …f  |7  < q| S )Nr   r„  )rº   r   rH   )r   r#  rœ   r
  r$  r–  rž  Znorm)r  r   r  ÚtrrÎ   Zdist_trP   rP   rQ   r�  .  s    z)TestParforsMisc.test_issue6102.<locals>.frø  r  )r   rœ   r$  rÎ  r½  )rO   r�  r  rP   rP   rQ   Útest_issue6102*  s    
zTestParforsMisc.test_issue6102c                 C   s    t dd�dd„ ƒ}|  |¡ d S )NTr0  c                  S   sP   d} t  | f¡}t  | d f¡}tt|ƒƒD ]}t  |||d … ¡||< q,|S r»  )rœ   rr  rZ  r   r­   r  )rÊ   Zna_maskr“  rÎ   rP   rP   rQ   rs  ?  s    z1TestParforsMisc.test_issue6774.<locals>.test_impl)r   r´   r}  rP   rP   rQ   Útest_issue6774>  s    
zTestParforsMisc.test_issue6774c                 C   s   dd„ }|   |¡ d S )Nc                  S   s   t  ttf¡} | S rS   )rœ   r  Ú_GLOBAL_INT_FOR_TESTING1Ú_GLOBAL_INT_FOR_TESTING2©ÚbufrP   rP   rQ   rs  K  s    z9TestParforsMisc.test_issue4963_globals.<locals>.test_implr|  r}  rP   rP   rQ   Útest_issue4963_globalsJ  s    z&TestParforsMisc.test_issue4963_globalsc                    s$   d‰ d‰‡ ‡fdd„}|   |¡ d S )Nrj   rk   c                     s   t  ˆ ˆf¡} | S rS   rÍ  rÍ  ©Z_FREEVAR_INT_FOR_TESTING1Z_FREEVAR_INT_FOR_TESTING2rP   rQ   rs  S  s    z:TestParforsMisc.test_issue4963_freevars.<locals>.test_implr|  r}  rP   rÐ  rQ   Útest_issue4963_freevarsP  s    z'TestParforsMisc.test_issue4963_freevarsN)rc   rK   rd   r  rf  rk  rn  rq  rs  r„  r™  r�  r¤  r¨  r¬  r¯  r?   rµ  r·  rº  r¾  rÁ  rÆ  rÇ  r@   rÉ  rÊ  rÏ  rÑ  rP   rP   rP   rQ   rU  ›
  s4   <5

rU  c                   @   sn   e Zd Zdd„ Zdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestParforsDiagnosticsc                 O   s.   | j |f|žŽ \}}| j|||f|ž|Ž d S rS   r²   r³   rP   rP   rQ   r´   \  s    zTestParforsDiagnostics.checkc                 C   s$   |   |¡}|   |¡}|  ||¡ d S rS   )Ú_fusion_equivalentr«   )rO   rÒ  rÔ  rq   rr   rP   rP   rQ   Úassert_fusion_equivalence`  s    

z0TestParforsDiagnostics.assert_fusion_equivalencec                    sH   t tƒ}t| ¡ ƒ‰ t| ¡ ƒD ]"}‡ fdd„|| D ƒ||ˆ  < q |S )Nc                    s   g | ]}|ˆ  ‘qS rP   rP   r‹   ©Zmin_keyrP   rQ   rŽ   p  s     z=TestParforsDiagnostics._fusion_equivalent.<locals>.<listcomp>)r   r£   rÍ  ÚkeysÚsorted)rO   ÚthingÚnewrš   rP   rÕ  rQ   rÓ  e  s
     z)TestParforsDiagnostics._fusion_equivalentNc              	   C   sÞ   |d k	r|   || ¡ ¡ |d k	r.|  ||j¡ |d k	rD|  ||j¡ |d k	rŽ|j ¡ }|D ]2}|D ]}	|	d |krb qZqbd||f }
t|
ƒ‚qZ|d k	r®| ¡ }|   |t	|ƒ¡ t
ƒ �  tddƒD ]}| |¡ qÀW 5 Q R X d S )Nr   z(Replacement for %s was not found. Had %srº   rk   )r«   Zcount_parforsrÔ  Úfusion_infoÚnested_fusion_infor:  rW  r®   Úhoisted_allocationsr­   r6   rÐ   Údump)rO   r.  Úparfors_countrÚ  rÛ  r:  rÜ  Úreplr�   ZreplacedrÄ   Úhoisted_allocsrP   rP   rQ   Úassert_diagnosticss  s,    ÿ

z)TestParforsDiagnostics.assert_diagnosticsc                 C   sD   dd„ }|   |¡ |  |d¡}|jd }| j|ddddgid	� d S )
Nc                  S   s    d} t  | ¡}t  | ¡}|| S ©NrÓ   rL  ©rÊ   rq   rr   rP   rP   rQ   rs  ‘  s    

z9TestParforsDiagnostics.test_array_expr.<locals>.test_implrP   Úparfor_diagnosticsrº   rÕ   rÚ   rk   )rÞ  rÚ  ©r´   r†   r;  rá  ©rO   rs  r’   r.  rP   rP   rQ   Útest_array_expr�  s    


ÿz&TestParforsDiagnostics.test_array_exprc                 C   s:   dd„ }|   |¡ |  |d¡}|jd }| j|dd� d S )Nc                  S   s,   d} t  | ¡}t| ƒD ]}|d ||< q|S râ  ©rœ   rZ  r   )rÊ   rq   rÎ   rP   rP   rQ   rs  ž  s
    
z5TestParforsDiagnostics.test_prange.<locals>.test_implrP   rä  rº   ©rÞ  rå  ræ  rP   rP   rQ   Útest_prange�  s
    

z"TestParforsDiagnostics.test_prangec                 C   sF   dd„ }|   |¡ |  |d¡}|jd }|  tdd„ |jD ƒƒ¡ dS )zEmake sure original user variable name is used in fusion info
        c                  S   sj   d} t  | ¡}t  |¡}t  || ¡}d}t| d ƒD ].}t| d ƒD ]}||| ||d   7 }qFq6|S )NrÓ   r   rÆ   rº   )rœ   rr  ÚsinÚcosr   )rÊ   r�   rq   rr   rc  rÎ   r  rP   rP   rQ   rs  ­  s    

z;TestParforsDiagnostics.test_user_varname.<locals>.test_implrP   rä  c                 s   s   | ]}d |j kV  qdS )zslice(0, n, 1)N)r^  )rŒ   r  rP   rP   rQ   rf  ¾  s     z;TestParforsDiagnostics.test_user_varname.<locals>.<genexpr>N)r´   r†   r;  rø   ÚanyZfusion_reportsræ  rP   rP   rQ   Útest_user_varnameª  s    

ÿz(TestParforsDiagnostics.test_user_varnamec                 C   sB   dd„ }|   |¡ |  |d¡}|jd }| j|dddgid� d S )Nc                  S   sF   d} t  | | f¡}t| ƒD ]&}t| ƒD ]}|d | |||f< q&q|S râ  rè  )rÊ   rq   rÎ   r  rP   rP   rQ   rs  Á  s    z<TestParforsDiagnostics.test_nested_prange.<locals>.test_implrP   rä  rÆ   rº   )rÞ  rÛ  rå  ræ  rP   rP   rQ   Útest_nested_prangeÀ  s    

ÿz)TestParforsDiagnostics.test_nested_prangec                 C   sF   dd„ }|   |¡ |  |d¡}|jd }| j|dddgidgd	� d S )
Nc                  S   s   d} t  | ¡}t  |¡}|S râ  )rœ   rr  r  rã  rP   rP   rQ   rs  Ð  s    

zCTestParforsDiagnostics.test_function_replacement.<locals>.test_implrP   rä  rº   rÆ   rÕ   )r  r[  )rÞ  rÚ  r:  rå  ræ  rP   rP   rQ   Útest_function_replacementÏ  s    

þz0TestParforsDiagnostics.test_function_replacementc                 C   s:   dd„ }|   |¡ |  |d¡}|jd }| j|dd� d S )Nc                  S   s4   d} t  | d ¡}d}t| ƒD ]}||| 7 }q|S r*  )rœ   rr  r   )rÊ   rq   rc  rÎ   rP   rP   rQ   rs  Þ  s    z8TestParforsDiagnostics.test_reduction.<locals>.test_implrP   rä  rÆ   ré  rå  ræ  rP   rP   rQ   r  Ý  s
    

z%TestParforsDiagnostics.test_reductionc                 C   s:   dd„ }|   |¡ |  |d¡}|jd }| j|dd� d S )Nc                  S   s   d} t  | ¡}d|d d …< |S )NrÓ   r6  rq  )rÊ   rq   rP   rP   rQ   rs  ì  s    
z6TestParforsDiagnostics.test_setitem.<locals>.test_implrP   rä  rº   ré  rå  ræ  rP   rP   rQ   Útest_setitemë  s
    

z#TestParforsDiagnostics.test_setitemc                 C   s:   dd„ }|   |¡ |  |d¡}|jd }| j|dd� d S )Nc                  S   sL   d} d}d}t | ƒD ]2}t |f¡}t|ƒD ]}|||< q,||d 7 }q|S )NrÓ   rk   r   rH   )r   rœ   r  rÐ   )rÊ   rõ   rc  rÎ   Útempr  rP   rP   rQ   rs  ø  s    
zBTestParforsDiagnostics.test_allocation_hoisting.<locals>.test_implrP   rä  rº   )rÜ  rå  ræ  rP   rP   rQ   Útest_allocation_hoisting÷  s
    

z/TestParforsDiagnostics.test_allocation_hoisting)NNNNN)rc   rK   rd   r´   rÔ  rÓ  rá  rç  rê  rî  rï  rð  r  rñ  ró  rP   rP   rP   rQ   rÒ  Y  s"          þ
rÒ  c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestPrangeBasec                 C   s"  |j }t|jƒ}|dkrFd|jks&t‚tdd„ |jD ƒƒ}t|jƒ}n¼|j d¡}g }t 	|¡D ],}|j
dkr`t|jƒ|kr`| |jd ¡ q`| d¡ t|ƒ}t|ƒd }	tjdkrÂd|	d>  }	t|jƒ}t|ƒt|ƒksàt‚|D ]}
||
 }|	||< qät|ƒ}|j||d	�}t |tƒ ¡}|S )
z�
        This function does the actual code augmentation to enable the explicit
        testing of `prange` calls in place of `range`.
        NrÐ   c                 S   s   g | ]}|d kr|nd‘qS )rÐ   r   rP   r‹   rP   rP   rQ   rŽ     s   ÿz7TestPrangeBase.generate_prange_func.<locals>.<listcomp>ÚLOAD_GLOBALrº   r   )rÕ   rÙ  )Úco_codeÚco_names)Ú__code__r£   r÷  r®   r�   Úbytesrö  rg  ÚdisÚBytecodeÚopnamerC   rÞ  r�   Úoffsetr­   rD   Z	PYVERSIONÚ	bytearrayÚreplaceÚpytypesÚFunctionTypeÚglobals)rO   r�   Úpatch_instanceZpyfunc_codeZprange_namesZnew_codeZ	range_idxZrange_locationsÚinstrZ
prange_idxrÎ   rš  Zprange_codeÚpfuncrP   rP   rQ   Úgenerate_prange_func  s<    
ÿ




ÿz#TestPrangeBase.generate_prange_funcc              	   O   sÆ   |  dd¡}|  dd¡}|  dd¡}|  ||¡}tdd„ |D ƒƒ}|  ||¡}	tjdd	��}
t d
¡ |  ||¡}W 5 Q R X |rŒ|  ||¡ |r¬|  	||¡}t
d|if|Ž}| j||	|f|ž|Ž |
S )aÔ
  
        The `prange` tester
        This is a hack. It basically switches out range calls for prange.
        It does this by copying the live code object of a function
        containing 'range' then copying the .co_names and mutating it so
        that 'range' is replaced with 'prange'. It then creates a new code
        object containing the mutation and instantiates a function to contain
        it. At this point three results are created:
        1. The result of calling the original python function.
        2. The result of calling a njit compiled version of the original
            python function.
        3. The result of calling a njit(parallel=True) version of the mutated
           function containing `prange`.
        The three results are then compared and the `prange` based function's
        llvm_ir is inspected to ensure the scheduler code is present.

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

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


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

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

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

        r  Nr–   FÚcheck_fastmath_resultc                 S   s   g | ]}t  |¡‘qS rP   r‰   r‹   rP   rP   rQ   rŽ   †  s     z0TestPrangeBase.prange_tester.<locals>.<listcomp>TrX  rZ  r—   )r§   r  r�   rˆ   ra  rb  rc  r†   r  r‡   ré   r±   )rO   r�   r}   r‘   r  r–   r  r  rƒ   r“   re  r’   Z
fastcpfuncrP   rP   rQ   Úprange_tester=  s     A
zTestPrangeBase.prange_testerN)rc   rK   rd   r  r  rP   rP   rP   rQ   rô  	  s   2rô  c                   @   s*  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze d¡dd „ ƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9d:„ Z!d;d<„ Z"d=d>„ Z#d?d@„ Z$dAdB„ Z%dCdD„ Z&dEdF„ Z'dGS )HÚTestPrangeBasicz Tests Prange c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s,   d} t  | ¡}t| ƒD ]}d| ||< q|S )NrÚ   r  ©rœ   r  rÐ   r~  rP   rP   rQ   rs  ¡  s
    
z0TestPrangeBasic.test_prange01.<locals>.test_implr¿   T©r•   r–   ©r  r}  rP   rP   rQ   Útest_prange01   s    ÿzTestPrangeBasic.test_prange01c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s6   d} t  | d ¡}td| ƒD ]}d| ||d < q|S )NrÚ   rº   r  r
  r~  rP   rP   rQ   rs  «  s
    z0TestPrangeBasic.test_prange02.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange02ª  s    ÿzTestPrangeBasic.test_prange02c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s   d} t dƒD ]}| d7 } q| S ©NrÓ   rÆ   r  ©rÕ  rÎ   rP   rP   rQ   rs  µ  s    
z0TestPrangeBasic.test_prange03.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange03´  s    ÿzTestPrangeBasic.test_prange03c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s   d} t dƒD ]}| d9 } q| S )NrÕ   rÓ   rÆ   r  r  rP   rP   rQ   rs  ¾  s    
z3TestPrangeBasic.test_prange03mul.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange03mul½  s    ÿz TestPrangeBasic.test_prange03mulc                 C   s   dd„ }| j |ddd� d S )Nc                  S   s   d} t dƒD ]}| d8 } q| S )Nrç  rÓ   rÆ   r  r  rP   rP   rQ   rs  Ç  s    
z3TestPrangeBasic.test_prange03sub.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange03subÆ  s    ÿz TestPrangeBasic.test_prange03subc                 C   s   dd„ }| j |ddd� d S )Nc                  S   s   d} t dƒD ]}| d } q| S r  r  r  rP   rP   rQ   rs  Ð  s    
z3TestPrangeBasic.test_prange03div.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange03divÏ  s    ÿz TestPrangeBasic.test_prange03divc                 C   s   dd„ }| j |ddd� d S )Nc                  S   s>   d} d}t  d¡}tdƒD ]}|| kr0|||< qd||< q|S )NrÆ   rÕ   rÚ   r   ©rœ   rZ  rÐ   ©rq   rr   r  rÎ   rP   rP   rQ   rs  Ù  s    


z0TestPrangeBasic.test_prange04.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange04Ø  s    
ÿzTestPrangeBasic.test_prange04c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s>   d} t j| t jd�}d}td| d dƒD ]}||| 7 }q(|S ©NrÚ   r„  r   rº   ©rœ   rr  r¼  rÐ   ©rÊ   r  rÕ  rÎ   rP   rP   rQ   rs  ç  s    z0TestPrangeBasic.test_prange05.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange05æ  s    ÿzTestPrangeBasic.test_prange05c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s:   d} t j| t jd�}d}tdddƒD ]}||| 7 }q$|S r  r  r  rP   rP   rQ   rs  ò  s    z0TestPrangeBasic.test_prange06.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange06ñ  s    ÿzTestPrangeBasic.test_prange06c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s8   d} t j| t jd�}d}t| dƒD ]}||| 7 }q"|S r  r  r  rP   rP   rQ   rs  ý  s    z0TestPrangeBasic.test_prange07.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange07ü  s    ÿzTestPrangeBasic.test_prange07c                 C   s   dd„ }| j |ddd� d S )Nc                  S   sF   d} t  | ¡}d}tt|ƒƒD ]"}tt|ƒƒD ]}||| 7 }q.q|S rB  ©rœ   rr  rÐ   r­   ©rÊ   r  rc  rÎ   r  rP   rP   rQ   rs    s    
z0TestPrangeBasic.test_prange08.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange08  s    ÿzTestPrangeBasic.test_prange08c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s>   d} t  | ¡}d}tdƒD ]}tdƒD ]}||| 7 }q&q|S rB  ©rœ   rr  rÐ   r  rP   rP   rQ   rs    s    
z2TestPrangeBasic.test_prange08_1.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange08_1  s    ÿzTestPrangeBasic.test_prange08_1c                 C   s    dd„ }| j |dgddd� d S )Nc                  S   s0   d} d}t | ƒD ]}t | ƒD ]}|d7 }qq|S ©NrÚ   r   rº   r  )rÊ   rc  rÎ   r  rP   rP   rQ   rs     s    z0TestPrangeBasic.test_prange09.<locals>.test_implrº   r¿   T©r  r•   r–   r  r}  rP   rP   rQ   Útest_prange09  s
    
þzTestPrangeBasic.test_prange09c                 C   s    dd„ }| j |dgddd� d S )Nc                  S   s<   d} d}t | ƒD ]&}d}t | ƒD ]}|d7 }q ||7 }q|S r#  r  )rÊ   Zacc2r  Zacc1rÎ   rP   rP   rQ   rs  -  s    

z0TestPrangeBasic.test_prange10.<locals>.test_implr   r¿   Tr$  r  r}  rP   rP   rQ   Útest_prange10,  s
    

þzTestPrangeBasic.test_prange10z1list append is not thread-safe yet (#2391, #2408)c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s   d} dd„ t | ƒD ƒS )NrÚ   c                 S   s   g | ]}t  |¡‘qS rP   )rœ   rë  r  rP   rP   rQ   rŽ   ?  s     zDTestPrangeBasic.test_prange11.<locals>.test_impl.<locals>.<listcomp>r  rÉ   rP   rP   rQ   rs  =  s    z0TestPrangeBasic.test_prange11.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange11;  s    ÿzTestPrangeBasic.test_prange11c                 C   s   dd„ }| j |ddd� d S )Nc                  S   s6   d} d}t  |¡}tt|ƒ ƒD ]}| || 7 } q | S ru  r  )rc  rÊ   r  rÎ   rP   rP   rQ   rs  D  s    
z0TestPrangeBasic.test_prange12.<locals>.test_implr¿   Tr  r  r}  rP   rP   rQ   Útest_prange12C  s    ÿzTestPrangeBasic.test_prange12c                 C   s$   dd„ }| j |t d¡ddd� d S )Nc                 S   s   d}t | ƒD ]}|d7 }q|S rC  r  r€  rP   rP   rQ   rs  O  s    
z0TestPrangeBasic.test_prange13.<locals>.test_implrÚ   r¿   Tr  )r  rœ   r	  r}  rP   rP   rQ   Útest_prange13N  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Î   rP   rP   rQ   rs  X  s    z0TestPrangeBasic.test_prange14.<locals>.test_implrÚ   r¿   Tr  )r  rœ   r´  rµ  r}  rP   rP   rQ   Útest_prange14W  s
    þzTestPrangeBasic.test_prange14c                 C   s   dd„ }| j |dddd� d S )Nc                 S   s,   d}t | ƒD ]}t d¡}||d 7 }q|S )Nr   rŠ  rŒ  )rÐ   rœ   rr  )r&  rc  rÎ   r�   rP   rP   rQ   rs  g  s
    
z0TestPrangeBasic.test_prange15.<locals>.test_implrÀ  r¿   Tr  r  r}  rP   rP   rQ   Útest_prange15d  s    
ÿzTestPrangeBasic.test_prange15c                 C   s   dd„ }| j |dddd� d S )Nc                 S   s"   d}t |  | ƒD ]}|d7 }q|S rp  r  ©r&  rc  rÎ   rP   rP   rQ   rs  r  s    
z0TestPrangeBasic.test_prange16.<locals>.test_implrÀ  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange16q  s    
ÿzTestPrangeBasic.test_prange16c                 C   s   dd„ }| j |dddd� d S )Nc                 S   s0   d}t  | ¡}t|  | ƒD ]}||| 7 }q|S rM  r!  ©r&  rc  r  rÎ   rP   rP   rQ   rs  {  s
    
z0TestPrangeBasic.test_prange17.<locals>.test_implrT  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange17z  s    
ÿzTestPrangeBasic.test_prange17c                 C   s   dd„ }| j |dddd� d S )Nc                 S   sL   d}t  | ¡}t|  dƒD ],}||| 7 }td| ƒD ]}||| 7 }q4q|S )Nr   rk   éüÿÿÿr!  )r&  rc  r  rÎ   r  rP   rP   rQ   rs  …  s    
z0TestPrangeBasic.test_prange18.<locals>.test_implrT  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange18„  s    
ÿzTestPrangeBasic.test_prange18c                 C   s   dd„ }| j |dddd� d S )Nc                 S   sR   d}| d }t  | |f¡}t|  | ƒD ]&}t| |ƒD ]}||||f 7 }q6q&|S ru  r!  )r&  rc  ÚMr  rÎ   r  rP   rP   rQ   rs  ‘  s    z0TestPrangeBasic.test_prange19.<locals>.test_implrT  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange19�  s    
ÿzTestPrangeBasic.test_prange19c                 C   s   dd„ }| j |dddd� d S )Nc                 S   s.   d}t  | ¡}td| ƒD ]}||| 7 }q|S )Nr   rH   r!  r/  rP   rP   rQ   rs  �  s
    
z0TestPrangeBasic.test_prange20.<locals>.test_implrT  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange20œ  s    
ÿzTestPrangeBasic.test_prange20c                 C   s   dd„ }| j |dddd� d S )Nc                 S   s    d}t ddƒD ]}|d7 }q|S )Nr   r'  rH   rÕ   r  r-  rP   rP   rQ   rs  §  s    
z0TestPrangeBasic.test_prange21.<locals>.test_implrT  r¾   Tr  r  r}  rP   rP   rQ   Útest_prange21¦  s    
ÿzTestPrangeBasic.test_prange21c                 C   s   dd„ }| j |dddd� d S )Nc                  S   sR   d} d}t  d¡}tddƒD ]0}|| kr2|||< q|dk rDd||< qd||< q|S )	Nr   rÕ   rÚ   r$  rÆ   rº   rH   r6  r  r  rP   rP   rQ   rs  °  s    



z0TestPrangeBasic.test_prange22.<locals>.test_implr¾   T©r•   r–   r  r  r}  rP   rP   rQ   Útest_prange22¯  s
     ÿzTestPrangeBasic.test_prange22c                 C   s4   dd„ }t  d¡d d d… }| j||dddd� d S )Nc                 S   s   t t| ƒƒD ]}|| |< q| S rS   r*  ©r  rÎ   rP   rP   rQ   rs  Á  s    
z0TestPrangeBasic.test_prange23.<locals>.test_implé    rÆ   r¿   Tr7  ©rœ   r  r  ©rO   rs  r  rP   rP   rQ   Útest_prange23¿  s    
 ÿzTestPrangeBasic.test_prange23c                 C   s4   dd„ }t  d¡d d d… }| j||dddd� d S )Nc                 S   s"   t t| ƒ dƒD ]}|| |< q| S rM  r*  r9  rP   rP   rQ   rs  Ë  s    
z0TestPrangeBasic.test_prange24.<locals>.test_implr:  rÆ   r¾   Tr7  r;  r<  rP   rP   rQ   Útest_prange24É  s    
 ÿzTestPrangeBasic.test_prange24c                 C   sd   dd„ }t  d¡}| j||dgdddd� |  |t |¡f¡}|jd }| ¡ }|  t	|ƒd	¡ d S )
Nc                    s<   t ˆ ƒ}‡ fdd„t|ƒD ƒ}t|ƒD ]}ˆ | ||< q&|S )Nc                    s   g | ]}t  ˆ ¡‘qS rP   )rœ   Z
zeros_like)rŒ   rI   ræ  rP   rQ   rŽ   Ö  s     zDTestPrangeBasic.test_prange25.<locals>.test_impl.<locals>.<listcomp>)r­   rÐ   )r  rÊ   rÎ  rÎ   rP   ræ  rQ   rs  Ô  s
    z0TestPrangeBasic.test_prange25.<locals>.test_implr×  rº   r¿   T)r  r•   r–   r  rä  r   )
rœ   rr  r  r†   rŠ   r   r;  rÜ  r«   r­   )rO   rs  r  r’   r.  rà  rP   rP   rQ   Útest_prange25Ó  s    
 þ
zTestPrangeBasic.test_prange25c                 C   s4   dd„ }t  d¡d d d… }| j||dddd� d S )Nc                 S   s,   | d d d… }t t|ƒƒD ]}|||< q| S rC  r*  )r  rÉ  rÎ   rP   rP   rQ   rs  å  s    
z0TestPrangeBasic.test_prange26.<locals>.test_implr:  rÆ   r¿   Tr7  r;  r<  rP   rP   rQ   Útest_prange26ä  s    
 ÿzTestPrangeBasic.test_prange26c                 C   sF   dd„ }| j |t d¡t ddddddddddg
¡ddgddd	� d S )
Nc                 S   sB   t |d d ƒD ],}t dƒD ]}t | |d |d … ¡}qqdS rÅ   )rÐ   rœ   Úabs)rq   rr   r  r  rš   r$  rP   rP   rQ   rs  ð  s    z0TestPrangeBasic.test_prange27.<locals>.test_implr“  rÚ   r   rº   r¿   Tr$  )r  rœ   rn  Zasarrayr}  rP   rP   rQ   Útest_prange27î  s    úzTestPrangeBasic.test_prange27c              	   C   sx   dd„ }t  ddgddgddgddgddgddgg¡}t  ddgddgdd	gd	d
gd
dgg¡}| j|||dddd� d S )Nc           
      S   sn   t  t|ƒ¡}tdt|ƒƒD ]L}||df }||df }| | }| | }|| }|d |d  }	|	||< q|S rC  )rœ   r  r­   rÐ   )
r�   r¥  ry  rš  Zi0Úi1ZPt1ZPt2re  Zvl2rP   rP   rQ   rs    s    
z0TestPrangeBasic.test_prange28.<locals>.test_implç      ð¿r  rø  r   rº   rÆ   rÕ   rÚ   rk   r¿   Tr7  )rœ   r$  r  r´  rP   rP   rQ   Útest_prange28ÿ  s$    
û
ü ÿzTestPrangeBasic.test_prange28c                 C   s$   dd„ }|   |d¡ |   |d¡ d S )Nc                 S   s:   d}| r t dƒD ]}|d7 }qnt dƒD ]}|d8 }q(|S )Nr   rº   rÕ   r  )rý  r“  rÎ   rP   rP   rQ   rs    s    
z0TestPrangeBasic.test_prange29.<locals>.test_implTFr  r}  rP   rP   rQ   Útest_prange29  s    
zTestPrangeBasic.test_prange29c                 C   s@   dd„ }t  t  ddd¡¡}t  dddg¡}|  |||d¡ d S )	Nc           
      S   sˆ   |j d }t| ƒ}tj||ftjd�}t| ƒ| d | }t|ƒD ]@}|| }|d | }	| ||	… |d d …  |d d …||	…f< qB|S rž  )r#  r­   rœ   r  r¼  rÐ   )
r�   ÚparZ
numthreadsZn_parZn_xr“  ZchunklenrÎ   rà  rá  rP   rP   rQ   rs  .  s    
*z0TestPrangeBasic.test_prange30.<locals>.test_implr   rØ   r  r  rl  rÆ   )rœ   r$  rn  r  )rO   rs  r�   rG  rP   rP   rQ   Útest_prange30,  s    zTestPrangeBasic.test_prange30N)(rc   rK   rd   r  r  r  r  r  r  r  r  r  r  r  r   r"  r%  r&  r@  Úskipr'  r(  r)  r+  r,  r.  r0  r2  r4  r5  r6  r8  r=  r>  r?  r@  rB  rE  rF  rH  rP   rP   rP   rQ   r	  œ  sH   

				
		

	


r	  c                   @   sà   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zed
d„ ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zed2d3„ ƒZd4S )5ÚTestPrangeSpecificz4 Tests specific features/problems found under prangec                 C   s   dd„ }|   |d¡ d S )Nc                 S   s.   d}t | ƒD ]}|d7 }|dkr|d7 }q|S ©Nr   rº   rÓ   r  ©rÊ   r  rÎ   rP   rP   rQ   rs  G  s    
zRTestPrangeSpecific.test_prange_two_instances_same_reduction_var.<locals>.test_implrT  r  r}  rP   rP   rQ   Ú,test_prange_two_instances_same_reduction_varE  s    z?TestPrangeSpecific.test_prange_two_instances_same_reduction_varc              	   C   sF   dd„ }|   tj¡�}|  |d¡ W 5 Q R X d}|  |t|jƒ¡ d S )Nc                 S   s.   d}t | ƒD ]}|d7 }|dkr|d9 }q|S rK  r  rL  rP   rP   rQ   rs  Q  s    
zKTestPrangeSpecific.test_prange_conflicting_reduction_ops.<locals>.test_implrT  zBReduction variable c has multiple conflicting reduction operators.)rv  r   ZUnsupportedErrorr  rÀ   rá   rw  ©rO   rs  ry  rÄ   rP   rP   rQ   Ú%test_prange_conflicting_reduction_opsP  s
    z8TestPrangeSpecific.test_prange_conflicting_reduction_opsc                 C   s   dd„ }|   |¡ d S )Nc                  S   sJ   d } }t dƒD ]0}|dkr&| d7 } qt d¡}|d r|d7 }q| |fS )Nr   rº   rÆ   rŠ  rŒ  rr  )r  rÉ  rš   r�   rP   rP   rQ   rs  a  s    


zLTestPrangeSpecific.test_prange_two_conditional_reductions.<locals>.test_implr  r}  rP   rP   rQ   Ú&test_prange_two_conditional_reductions_  s    
z9TestPrangeSpecific.test_prange_two_conditional_reductionsc                 C   s   dd„ }|   |¡ d S )Nc                  S   s4   d} t dƒD ]"}t dƒD ]}|dkr| d7 } qq| S rC  r  )r  rš   rÎ   rP   rP   rQ   rs  n  s    zCTestPrangeSpecific.test_prange_nested_reduction1.<locals>.test_implr  r}  rP   rP   rQ   Útest_prange_nested_reduction1m  s    z0TestPrangeSpecific.test_prange_nested_reduction1c              	   C   s„   dd„ }|   t¡�}|ƒ  W 5 Q R X |  |d ¡}|  |d¡}|  |d¡}|   t¡�}| ¡  W 5 Q R X | ¡ }|  |d tj¡ d S )Nc                  S   s,   d} t  | ¡}t| ƒD ]}d| ||< q|S )Nr:  rº   r
  r~  rP   rP   rQ   rs  y  s
    
z<TestPrangeSpecific.test_check_error_model.<locals>.test_implrP   r   )	rv  ÚZeroDivisionErrorr  r†   r‡   r¨   r«   rœ   r
  )rO   rs  ry  r  ZpcresZpfcresr“  rP   rP   rQ   Útest_check_error_modelw  s    z)TestPrangeSpecific.test_check_error_modelc           
      C   sª   dd„ }t  d¡ dd¡}| j||dddd� |  |d ¡}tt |¡gƒ}|  ||¡}|  	|¡}| 
¡ D ]<\}}| ¡ D ]*}	d	|	krx||	krx|  |	 d
¡d¡  qhqxqhd S )Nc                 S   s*   t t| ƒƒD ]}| | }d|d d …< q| S r‚  r*  )r  rÎ   rÉ  rP   rP   rQ   rs  ’  s    z?TestPrangeSpecific.test_check_alias_analysis.<locals>.test_implr:  rÚ   r+  r¿   Tr7  ZdefineZnoaliasrÆ   )rœ   r  r×   r  r  r�   rŠ   r   r‡   rì   rÿ   rñ   r«   rû   )
rO   rs  r  r  rƒ   rÃ   r   rš   re  rj  rP   rP   rQ   Útest_check_alias_analysis�  s    
 ÿ
z,TestPrangeSpecific.test_check_alias_analysisc              	   C   sF   dd„ }|   tj¡�}|  |d¡ W 5 Q R X d}|  |t|jƒ¡ d S )Nc                 S   s"   d}t d| dƒD ]}|d7 }q|S rp  r  r-  rP   rP   rQ   rs  ©  s    
zJTestPrangeSpecific.test_prange_raises_invalid_step_size.<locals>.test_implrÀ  z4Only constant step size of 1 is supported for prange)rv  r   r2  r  rÀ   rá   rw  rN  rP   rP   rQ   Ú$test_prange_raises_invalid_step_size¨  s
    z7TestPrangeSpecific.test_prange_raises_invalid_step_sizec                 C   s¾   dd„ }| j |ddd� |  |d ¡}|  |d¡}|  |¡}d}d}t |||f ¡}t d	|||f ¡}| ¡ D ]H\}	}
|
 ¡ }t|ƒD ]\}}| 	|¡rˆ q qˆ|  
| 	||d
  ¡¡ qpd S )Nc                  S   s&   d} d}t | ƒD ]}||d 7 }q|S )NrÚ  r   r  r  r~  rP   rP   rQ   rs  ¸  s
    zFTestPrangeSpecific.test_prange_fastmath_check_works.<locals>.test_implr¿   Tr  rP   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ñ   rD  rý   rø   )rO   rs  r  rÃ   r   Z_idZ
recipr_strZreciprocal_instZ	fadd_instrÞ   Zkernelrô   rÎ   r�   rP   rP   rQ   Ú test_prange_fastmath_check_works´  s&    ÿ
ÿ
z3TestPrangeSpecific.test_prange_fastmath_check_worksc                 C   s   dd„ }|   |d¡ d S )Nc                 S   s8   t  | | f¡}|d }t| ƒD ]}|d ||< q| ¡ S rC  ©rœ   r  rÐ   r  )rÊ   rr   rq   r  rP   rP   rQ   rs  Ó  s
    z8TestPrangeSpecific.test_parfor_alias1.<locals>.test_implrÚ   r  r}  rP   rP   rQ   Útest_parfor_alias1Ò  s    z%TestPrangeSpecific.test_parfor_alias1c                 C   s   dd„ }|   |d¡ d S )Nc                 S   sF   t  | | f¡}t| ƒD ]&}|| }t| ƒD ]}|| ||< q*q| ¡ S rS   rX  )rÊ   rr   rÎ   rq   r  rP   rP   rQ   rs  Ü  s    z8TestPrangeSpecific.test_parfor_alias2.<locals>.test_implrÚ   r  r}  rP   rP   rQ   Útest_parfor_alias2Û  s    z%TestPrangeSpecific.test_parfor_alias2c                 C   s   dd„ }|   |d¡ d S )Nc                 S   sb   t  | | | f¡}t| ƒD ]@}|| }t| ƒD ]*}|| }t| ƒD ]}|| | ||< q@q,q| ¡ S rS   rX  )rÊ   rr   rÎ   rq   r  r  rš   rP   rP   rQ   rs  æ  s    z8TestPrangeSpecific.test_parfor_alias3.<locals>.test_implrÚ   r  r}  rP   rP   rQ   Útest_parfor_alias3å  s    	z%TestPrangeSpecific.test_parfor_alias3c                 C   s8   dd„ }|   |dd¡}|d }d}|  |t|jƒ¡ d S )Nc                 S   s   t |ƒD ]}| }q|S rS   r  )r�   r¥  r  rš   rP   rP   rQ   rs  ò  s    z8TestPrangeSpecific.test_parfor_race_1.<locals>.test_implrÓ   r“  r   z�Variable 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^  )rO   rs  re  Zwarning_objZexpected_msgrP   rP   rQ   Útest_parfor_race_1ñ  s
    z%TestPrangeSpecific.test_parfor_race_1c                 C   s   dd„ }|   |¡ dS )až   issue 3686: if a prange has something inside it that causes
            a nested parfor to be generated and both the inner and outer
            parfor use the same call variable defined outside the parfors
            then ensure that when that call variable is pushed into the
            parfor that the call variable isn't duplicated with the same
            name resulting in a redundant type lock.
        c                  S   sf   d} t j}tdƒD ]"}|dƒ}| |t  d¡ƒd 7 } qtdƒD ]"}|dƒ}| |t  d¡ƒd 7 } q>| S )Nr   rº   r  rÆ   )rœ   ÚnegativerÐ   r  )rÉ  r�  rÎ   Úthis_mattersrP   rP   rQ   rs    s    zGTestPrangeSpecific.test_nested_parfor_push_call_vars.<locals>.test_implNr  r}  rP   rP   rQ   Ú!test_nested_parfor_push_call_varsý  s    z4TestPrangeSpecific.test_nested_parfor_push_call_varsc                 C   sD   dd„ }d}t  |||f¡}t j|t jd�}| j|||dgd� dS )a+   issue4903: a global is copied next to a parfor so that
            it can be inlined into the parfor and thus not have to be
            passed to the parfor (i.e., an unsupported function type).
            This global needs to be renamed in the block into which
            it is copied.
        c                 S   s‚   t  t|ƒ¡}t  t|ƒ¡}tdƒD ]T}|| }t|ƒD ]}|t  | ||f ¡7 }q8t|ƒD ]}|t  | ||f ¡7 }q\q$||fS r‚  )rœ   r  r­   rÐ   r  )ÚzzÚtcZlhÚlcrÎ   Úntr×  rP   rP   rQ   rs    s    zATestPrangeSpecific.test_copy_global_for_parfor.<locals>.test_implrÆ   r„  r   )r  N)rœ   rr  r�  r  )rO   rs  rõ   r`  ra  rP   rP   rQ   Útest_copy_global_for_parfor  s
    z.TestPrangeSpecific.test_copy_global_for_parforc                 C   s   dd„ }|   |d¡ d S )Nc                 S   s0   d}t j}tdƒD ]}|dƒ}||| ƒ7 }q|S )Nr   rº   r  )rœ   r]  rÐ   )rÊ   rÉ  r�  rÎ   r^  rP   rP   rQ   rs  *  s    zGTestPrangeSpecific.test_multiple_call_getattr_object.<locals>.test_implr  r  r}  rP   rP   rQ   Ú!test_multiple_call_getattr_object)  s    z4TestPrangeSpecific.test_multiple_call_getattr_objectc                 C   sÊ   dd„ }t jddtfdtfgd�}t jddtfdtfgd�}t jddtfdtfgd�}| t j¡}| t j¡}| t j¡}t||ƒƒ}tt|ƒ|ƒƒ}	t|dd�}
t|
|ƒƒ}|  ||	¡ |  ||¡ d S )	Nc                 S   s    t t| ƒƒD ]}d| j|< q| S r  )rÐ   r­   r�   )rÊ   rÎ   rP   rP   rQ   rs  6  s    zHTestPrangeSpecific.test_argument_alias_recarray_field.<locals>.test_implrÓ   r�   r¥  r„  Tr0  )	rœ   r  r¥  r¹  ÚviewZrecarrayr£   r   r«   )rO   rs  ZX1ZX2ZX3r–  r—  Zv3Ú
python_resÚnjit_resÚpa_funcÚpa_resrP   rP   rQ   Ú"test_argument_alias_recarray_field4  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.
            rH   rº   )r�   )r  rú  rq   rP   rP   rQ   Ú
list_checkO  s    
z>TestPrangeSpecific.test_mutable_list_param.<locals>.list_checkc                    s    t | ƒD ]}dg}ˆ |ƒ}q|S rV  ri  )rÊ   rÎ   r  rq   ©rl  rP   rQ   rs  Y  s    
z=TestPrangeSpecific.test_mutable_list_param.<locals>.test_implrÓ   Tr0  N©r   r«   )rO   rs  rg  rh  ri  rj  rP   rm  rQ   Útest_mutable_list_paramJ  s    
	z*TestPrangeSpecific.test_mutable_list_paramc                 C   s>   dd„ }t jdddgtd�t jddgtd�g}|  ||¡ d S )Nc                    s    t  ‡ fdd„ttˆ ƒƒD ƒ¡S )Nc                    s   g | ]}t ˆ | ƒ‘qS rP   )r­   rÍ   r  rP   rQ   rŽ   h  s     zXTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_impl.<locals>.<listcomp>)rœ   r$  rÐ   r­   r  rP   r  rQ   rs  g  s    zDTestPrangeSpecific.test_list_comprehension_prange.<locals>.test_implrº   rÆ   rÕ   r„  )rœ   r$  r¹  r  r¢  rP   rP   rQ   Útest_list_comprehension_prangee  s    &z1TestPrangeSpecific.test_list_comprehension_prangec                 C   s,   dd„ }t jdt jd�}|  ||dd¡ d S )Nc                 S   sZ   t  | j¡}t| jd ƒD ]:}| | d d }|dkr:d}|dkrFd}|||g||< q|S )Nr   g     ào@)rœ   r  r#  rÐ   )Úimagerq   rr   rZ  rÎ   r  ÚhrP   rP   rQ   rs  r  s    z>TestPrangeSpecific.test_ssa_false_reduction.<locals>.test_implr½  r„  r   )rœ   r  r	  r  )rO   rs  rq  rP   rP   rQ   Útest_ssa_false_reductionl  s    z+TestPrangeSpecific.test_ssa_false_reductionc                 C   s   dd„ }|   |¡ d S )Nc                  S   s@   d} t j| t jd�}tdƒD ]}dg}d|d< |d ||< q|S )Nrk   r„  r   rº   )rœ   rZ  r¸  rÐ   )rÊ   rq   rš   r  rP   rP   rQ   rs  ƒ  s    z@TestPrangeSpecific.test_list_setitem_hoisting.<locals>.test_implr  r}  rP   rP   rQ   Ú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Î   rP   rP   rQ   rs  ’  s    z?TestPrangeSpecific.test_record_array_setitem.<locals>.test_implc                 S   s    | d d |d d kst ‚d S )Nr   rñ  )r®   rp   rP   rP   rQ   r¯  –  s    z>TestPrangeSpecific.test_record_array_setitem.<locals>.comparerrº   )r#  r…  r°  )rœ   r…  r	  r  r  )rO   Ústate_dtypers  r¯  rP   rP   rQ   Ú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 )Nr6  r�   )ré  rÐ   )ru  rÊ   rÎ   rP   rP   rQ   rs     s    zKTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.test_implrÓ   r„  c                 S   s   t j | |¡ d S rS   r®  rp   rP   rP   rQ   r¯  ¨  s    zJTestPrangeSpecific.test_record_array_setitem_yield_array.<locals>.comparerr°  )rœ   r…  r¹  r  r  )rO   rv  rs  ru  r¯  rP   rP   rQ   Ú%test_record_array_setitem_yield_array�  s    þz8TestPrangeSpecific.test_record_array_setitem_yield_arrayc                 C   s   dd„ }|   |dd¡ d S )Nc                 S   sZ   t  | f¡}|dkr4t| ƒD ]}||  d7  < qnt| ƒD ]}||  d7  < q<|d S )Nrº   rÆ   r   r
  )ré  Úcaser“  rÎ   rP   rP   rQ   rs  °  s    z4TestPrangeSpecific.test_issue7501.<locals>.test_implrÕ   rº   r  r}  rP   rP   rQ   Útest_issue7501¯  s    
z!TestPrangeSpecific.test_issue7501c                 C   s(   dd„ }d}t j |¡}|  ||¡ d S )Nc           
      S   sš   d}t  dddg¡}|jd }| jd }d}t|ƒD ]`}| | }|| d  d|d   }t  |¡}	||	t  || ¡ t  t  t  ||	 ¡¡¡ 7 }q4|S )Nr  rD  r  r&  r   rÆ   )rœ   r$  r#  rÐ   rÍ  r  r  r  )
r  rr   Zpointsr&  rÊ   ZexpsrÎ   Úprr  rõ   rP   rP   rQ   rs  ½  s    


2z6TestPrangeSpecific.test_kde_example.<locals>.test_implrÚ  )rœ   r´  rµ  r  rF  rP   rP   rQ   Ú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ã  )rJ   ÚstderrzTEST PASSED)ÚsubpÚcheck_outputÚsysÚ
executableÚSTDOUTrÀ   Údecode)rO   ry  rP   rP   rQ   Útest_issue_due_to_max_labelÏ  s    
ýz.TestPrangeSpecific.test_issue_due_to_max_labelN)rc   rK   rd   r  rM  rO  rP  rQ  r?   rS  rT  rU  rW  rY  rZ  r[  r\  r_  rd  re  rk  ro  rp  rs  rt  rw  rx  rz  r|  r;   r„  rP   rP   rP   rQ   rJ  A  s8   

	
rJ  c                   @   sl   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestParforChunksizingz:
    Tests chunksize handling in ParallelAccelerator.
    Fc                 C   s   t dƒ d S rM  ©r   rU   rP   rP   rQ   ÚsetUpâ  s    zTestParforChunksizing.setUpc                 C   s   t dƒ d S rM  r†  rU   rP   rP   rQ   ÚtearDownå  s    zTestParforChunksizing.tearDownc                 C   s>   |   tƒ d¡ tdƒ |   tƒ d¡ tdƒ |   tƒ d¡ d S ©Nr   r+  )r«   r   r   rU   rP   rP   rQ   Ú$test_python_parallel_chunksize_basicè  s
    z:TestParforChunksizing.test_python_parallel_chunksize_basicc              	   C   sB   |   tƒ d¡ tdƒ� |   tƒ d¡ W 5 Q R X |   tƒ d¡ d S r‰  )r«   r   r   rU   rP   rP   rQ   Ú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   rP   rP   rP   rQ   Úget_csù  s    zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.get_csc                 S   s   t | ƒS rS   r†  r  rP   rP   rQ   Úset_csý  s    zHTestParforChunksizing.test_njit_parallel_chunksize_basic.<locals>.set_csr   r+  rn  )rO   rŒ  r�  rP   rP   rQ   Ú"test_njit_parallel_chunksize_basic÷  s    

z8TestParforChunksizing.test_njit_parallel_chunksize_basicc                 C   sB   t dd„ ƒ}|dƒ\}}}|  |d¡ |  |d¡ |  |d¡ d S )Nc              	   S   s0   t ƒ }tdƒ� t ƒ }W 5 Q R X t ƒ }|||fS )Nr+  )r   r   )r�   Úcs1Úcs2Úcs3rP   rP   rQ   rs  	  s
    
zATestParforChunksizing.test_njit_with_chunksize.<locals>.test_implr+  r   rn  )rO   rs  r�  r�  r‘  rP   rP   rQ   Útest_njit_with_chunksize  s    
z.TestParforChunksizing.test_njit_with_chunksizec                 C   sh   t dd�dd„ ƒ}dD ]L}tdƒD ]>}||d |ƒ\}}|  t |dk¡¡ |  t |d	k¡¡ q"qd
S )z© Test that all the iterations get run if you set the
            chunksize.  Also check that the chunksize that each
            worker thread sees has been reset to 0. Tr0  c              	   S   sX   t  |¡}t  |d¡}t | ¡�* t |¡D ]}t ¡ ||< d||< q,W 5 Q R X ||fS )Nióÿÿÿr‹  )rœ   r  rŸ  rŠ   r   r   r   )ÚcsrÊ   ro  Úinner_csrÎ   rP   rP   rQ   rs    s    
zLTestParforChunksizing.test_all_iterations_reset_chunksize.<locals>.test_impl)iè  iå  i¯  iÁ  r¿  rº   r‹  r   N)r   rÐ   rø   rœ   Úall)rO   rs  r  rÎ   ro  r”  rP   rP   rQ   Ú#test_all_iterations_reset_chunksize  s    
z9TestParforChunksizing.test_all_iterations_reset_chunksizec              	   C   sB   |   t¡�}tdd„ ƒ}|ƒ  W 5 Q R X d}|  |t|jƒ¡ d S )Nc                   S   s   t dƒ d S )NrH   r†  rP   rP   rP   rQ   Úneg_test2  s    zMTestParforChunksizing.test_njit_parallel_chunksize_negative.<locals>.neg_testú/chunksize must be greater than or equal to zero)rv  r¤   r   rÀ   rá   rw  )rO   r3  r—  rÄ   rP   rP   rQ   Ú%test_njit_parallel_chunksize_negative/  s    
z;TestParforChunksizing.test_njit_parallel_chunksize_negativec              	   C   s8   |   t¡�}tdƒ W 5 Q R X d}|  |t|jƒ¡ d S )NrH   r˜  )rv  r¤   r   rÀ   rá   rw  ©rO   r3  rÄ   rP   rP   rQ   Ú'test_python_parallel_chunksize_negative;  s    z=TestParforChunksizing.test_python_parallel_chunksize_negativec              	   C   sD   |   tj¡�}tdd„ ƒ}|ƒ  W 5 Q R X d}|  |t|jƒ¡ d S )Nc                   S   s   t dƒ d S )NÚinvalid_typer†  rP   rP   rP   rQ   r·   E  s    zMTestParforChunksizing.test_njit_parallel_chunksize_invalid_type.<locals>.implú)The parallel chunksize must be an integer)rv  r   ZTypingErrorr   rÀ   rá   rw  )rO   r3  r·   rÄ   rP   rP   rQ   Ú)test_njit_parallel_chunksize_invalid_typeC  s    
z?TestParforChunksizing.test_njit_parallel_chunksize_invalid_typec              	   C   s8   |   t¡�}tdƒ W 5 Q R X d}|  |t|jƒ¡ d S )Nrœ  r�  )rv  Ú	TypeErrorr   rÀ   rá   rw  rš  rP   rP   rQ   Ú+test_python_parallel_chunksize_invalid_typeN  s    zATestParforChunksizing.test_python_parallel_chunksize_invalid_typeN)rc   rK   rd   r  re   r‡  rˆ  rŠ  r‹  rŽ  r’  r–  r™  r›  rž  r   rP   rP   rP   rQ   r…  Û  s   r…  c                   @   s<   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
S )ÚTestParforsVectorizerFc                 O   s:  |  dd¡}|  dd¡}|  dd¡}|  dd¡}||d	œ}	g }
|	 ¡ D ]\}}|
 t||ƒ¡ qF|
d
 �È |
d �´ tdd„ |D ƒƒ}|  |d ¡}|dkr¨|  ||¡}n|  ||¡}|  |¡}|�r
t	 
d¡}| |j ¡ ¡}|  t|ƒd¡ |  |d
 |¡ |  |i ¡ |W  5 Q R £ W  5 Q R £ S Q R X W 5 Q R X d S )Nry   FÚcpu_namezskylake-avx512Ú
assertionsTÚcpu_featuresz-prefer-256-bit)ZNUMBA_CPU_NAMEZNUMBA_CPU_FEATURESr   rº   c                 S   s   g | ]}t  |¡‘qS rP   r‰   r‹   rP   rP   rQ   rŽ   o  s     z8TestParforsVectorizer.get_gufunc_asm.<locals>.<listcomp>z%call\s+\w+\*\s+@do_scheduling_(\w+)\()r§   rÿ   r�   r8   r�   r  r‡   r†   rð   rò   rV  ÚfindallrÁ   rÂ   r»   r­   r«   ZassertNotEqual)rO   r‚   Zschedule_typer}   r‘   ry   r¢  r£  r¤  Zenv_optsZ	overridesrš   re  rƒ   Zpfunc_vectorizablerÃ   ÚasmZschedtyÚmatchesrP   rP   rQ   Úget_gufunc_asm]  s0    ÿ

z$TestParforsVectorizer.get_gufunc_asmc                 C   sÖ   dd„ }t  d¡}| j|d|dd�}| j|d|dd�}| ¡ D ]6}|  d|k¡ |  d	|kpbd
|k¡ |  d|k¡ q>| ¡ D ]R}|  d|k¡ |  d	|k¡ |  d|ko°d
|k¡ |  d|k¡ |  d|k¡ q~dS )úÐ This checks that if fastmath is set and the underlying hardware
        is suitable, and the function supplied is amenable to fastmath based
        vectorization, that the vectorizer actually runs.
        c                 S   s,   t | ƒ}d}t|ƒD ]}|t |¡7 }q|S rM  ©r­   rÐ   rœ   r   )r  rÊ   rc  rÎ   rP   rP   rQ   Úwill_vectorizeŒ  s
    zJTestParforsVectorizer.test_vectorizer_fastmath_asm.<locals>.will_vectorizerÓ   r¿   T©ry   FZvaddpdÚvsqrtpdÚ__svml_sqrtÚzmmÚvsqrtsdZvaddsdN)rœ   r  r¨  rW  rø   )rO   r«  rÞ  Zfast_asmZslow_asmre  rP   rP   rQ   Útest_vectorizer_fastmath_asm‚  s$    


ÿ
ÿz2TestParforsVectorizer.test_vectorizer_fastmath_asmc              	   C   sÐ   dd„ }dd„ }t  d¡}tddƒ�* | j|d|d	d
�}| j|d|d	d
�}W 5 Q R X | ¡ D ].}|  d|k¡ |  d|k¡ |  d|k¡ q\| ¡ D ]6}|  d|kpªd|k¡ |  d|k¡ |  d|k¡ q”dS )r©  c                 S   s0   t | ƒ}t| dƒD ]}t | | ¡| |< q| S rM  rª  ©r  rÊ   rÎ   rP   rP   rQ   Úwill_not_vectorize±  s    zTTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_not_vectorizec                 S   s,   t | ƒ}t|ƒD ]}t | | ¡| |< q| S rS   rª  r²  rP   rP   rQ   r«  ·  s    zPTestParforsVectorizer.test_unsigned_refusal_to_vectorize.<locals>.will_vectorizerÓ   ÚNUMBA_BOUNDSCHECKÚ0r¾   Tr¬  r¿   r­  r°  r¯  r®  ZvmovupdN)rœ   r  r8   r¨  rW  rø   )rO   r³  r«  rÞ  Z	novec_asmZvec_asmre  rP   rP   rQ   Ú"test_unsigned_refusal_to_vectorizeª  s$    

ÿ
ÿz8TestParforsVectorizer.test_unsigned_refusal_to_vectorizec              	   C   s  dd„ }dd„ }t ddƒ�& | j|ddd	�}| j|d
dd	�}W 5 Q R X dd„ }| ¡ D ]\}}||ƒ} qlqV| ¡ D ]\}}||ƒ}	 qŠqtddlm}
 |  t|ƒt|	ƒ¡ t||	ƒD ]^\}}||krÈq´q´|
dd„ ||ƒ}| ¡ }|D ],}|d dkrä|  ||d |d … d¡ qäq´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~  rP   rP   rQ   Ú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~  rP   rP   rQ   Úunsigned_variantæ  s
    
zOTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.unsigned_variantr´  rµ  r¾   Tr¬  r¿   c                 S   s`   g }|   ¡ D ]N}| ¡ }|dkr| d¡s| d¡s| d¡sd|ks| t dd|¡¡ q|S )NÚ rG   rI   ú"rè   z[	])rñ   ÚstripÚ
startswithr�   rò   Úsub)r¦  rc  r�   ZspdrP   rP   rQ   Ústrip_instrsô  s    ÿþýzKTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.strip_instrsr   )ÚSequenceMatcherc                 S   s   | dkS )Nú	rP   r  rP   rP   rQ   rë    rì  zGTestParforsVectorizer.test_signed_vs_unsigned_vec_asm.<locals>.<lambda>Úinsertr$  rH   rÝ  N)	r8   r¨  rÿ   ÚdifflibrÀ  r«   r­   r¯   Zget_opcodes)rO   r¸  r¹  Z
signed_asmZunsigned_asmr¿  rš   re  Zsigned_instrZunsigned_instrÚsmrq   rr   rÕ  rù   rü   rP   rP   rQ   Útest_signed_vs_unsigned_vec_asmÖ  s4    	ÿÿz5TestParforsVectorizer.test_signed_vs_unsigned_vec_asmN)	rc   rK   rd   re   r¨  r9   r±  r¶  rÅ  rP   rP   rP   rQ   r¡  V  s   %
'
+r¡  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú TestParforReductionSetNumThreadszCTest execution correctness on reductions with set_num_threads.
    c                    sP   t j}d| ‰ |d ‰tdd�‡ ‡fdd„ƒ}| ˆ¡}|ˆƒ}|  ||¡ d S )NrÆ   rº   Tr0  c                    s@   d}t | ƒ tˆ ƒD ]&}d|ˆ  }t |ƒ tƒ }||7 }q|S rC  ©r   r   r   ©Znthreadsrc  rÎ   Z
local_maskZgnt©r3  ÚmaskrP   rQ   Úudt"  s    
z6TestParforReductionSetNumThreads.test_add.<locals>.udt©r   ÚNUMBA_NUM_THREADSr   r½  rÎ  ©rO   r&  rË  ÚexpectrÒ  rP   rÉ  rQ   Útest_add  s    

z)TestParforReductionSetNumThreads.test_addc                    sV   t dtjƒ}d| ‰ |d ‰tdd�‡ ‡fdd„ƒ}| ˆ¡}|ˆƒ}|  ||¡ d S )NrÚ   rÆ   rº   Tr0  c                    s@   d}t | ƒ tˆ ƒD ]&}d|ˆ  }t |ƒ tƒ }||9 }q|S r‚  rÇ  rÈ  rÉ  rP   rQ   rË  8  s    
z6TestParforReductionSetNumThreads.test_mul.<locals>.udt)rÍ  r   rÍ  r   r½  rÎ  rÎ  rP   rÉ  rQ   Útest_mul1  s    

z)TestParforReductionSetNumThreads.test_mulc                    sP   t j}d| ‰ |d ‰tdd�‡ ‡fdd„ƒ}| ˆ¡}|ˆƒ}|  ||¡ d S )NrÆ   rº   Tr0  c                    sB   d}t | ƒ tˆ ƒD ](}d|ˆ  }t |ƒ tƒ }t||ƒ}q|S r‚  )r   r   r   rÎ  rÈ  rÉ  rP   rQ   rË  L  s    z6TestParforReductionSetNumThreads.test_max.<locals>.udtrÌ  rÎ  rP   rÉ  rQ   r  G  s    

z)TestParforReductionSetNumThreads.test_maxN)rc   rK   rd   r  rÐ  rÑ  r  rP   rP   rP   rQ   rÆ    s   rÆ  c                   @   s   e Zd Ze ¡ dd„ ƒZdS )ÚTestDiagnosticEnvVarc              	   C   sL   dt jd< tƒ �}tdd�dd„ ƒ}|ƒ  W 5 Q R X | ¡ }|  d|¡ d S )NÚ4ZNUMBA_PARALLEL_DIAGNOSTICSTr0  c                  S   s.   d} t j| t jd�}t| ƒD ]}d||< q|S )Nrç  r„  rº   )rœ   r  r¼  r   )rÊ   rr   rÎ   rP   rP   rQ   r·   b  s
    
z<TestDiagnosticEnvVar.test_diagnostics_env_var1.<locals>.implzParallel Accelerator Optimizing)ÚosÚenvironr6   r   rh  rÀ   )rO   ri  r·   Z
the_outputrP   rP   rQ   Útest_diagnostics_env_var1^  s    

z.TestDiagnosticEnvVar.test_diagnostics_env_var1N)rc   rK   rd   r5   Zrun_test_in_subprocessrÖ  rP   rP   rP   rQ   rÒ  \  s   rÒ  Ú__main__)N)‘Úmathr   rò   rú  r    rÔ  rf   r€  Ú
subprocessr   r   ra  Ú	functoolsr   r[  rœ   Znumpy.randomr   r©  Úcollectionsr   r   rž   Ú	itertoolsr	   r
   r~  Znumba.parfors.parforrŠ   r   r   r   r   r   r   r   r   Z
numba.corer   r   r   r   r   r   r   r   r   Znumba.extendingr   r   r   r    r!   r"   Znumba.core.registryr#   Znumba.core.annotationsr$   Znumba.core.ir_utilsr%   r&   r'   r(   r)   r*   r+   Znumba.np.unsafe.ndarrayr,   r}  Znumba.core.bytecoder-   Znumba.core.compilerr.   r/   r0   r1   Znumba.core.compiler_machineryr2   r3   Znumba.core.typed_passesr4   Znumba.tests.supportr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   Znumba.core.extendingrB   rC   rD   ra  r@  rE   rA  rg   Zx86_onlyrË  rÌ  rl   rs   rt   r  r  r(  rB  r¼   rL  rO  rJ  rY  rX  r_  r^  ra  r—  r0  ri  r³  rÅ  r<  rB  r  r	  rH  rN  rU  rÒ  rô  r	  rJ  r…  r¡  rÆ  rÒ  rc   ÚmainrP   rP   rP   rQ   Ú<module>   sô   (0 $<=
	  $B	
" ,*          ]  +%=   @ 0    '   z BB
