B
     \U                @   s   d dl mZmZ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mZ d dlmZ d dlZd dlmZ d dlmZmZm
Z
 d dlmZmZ d dlmZ d d	lmZ d
dlmZ d dlmZm Z  ej!dd dkZ"ej#$doe"Z%ej&dkZ'dZ(e'pe%Z)e*e)e(Z+edd Z,edddd Z-edddd Z.edd Z/edd Z0ed d!d"d# Z1ed d!d$d% Z2ed&d' Z3e)sed(d)d*d+ Z4G d,d- d-ej5Z6G d.d/ d/e6Z7G d0d1 d1Z8d8d3d4Z9e+G d5d6 d6e6Z:e;d7kre<  dS )9    )print_functiondivisionabsolute_importN)contextmanager)deepcopy)unittest_support)njitstenciltypes)compile_extraFlags)registry)ParallelOptions   )tag)LoweringErrorTypingError   )r      Zwin32l        zparfors not supportedc             C   s$   d| d | d  | d  | d   S )Ng      ?)r   r   )r   r   )r   )r   r    )ar   r   8lib/python3.7/site-packages/numba/tests/test_stencils.pystencil1_kernel$   s    r   ))r   )neighborhoodc             C   s0   | d }xt ddD ]}|| | 7 }qW d| S )Nr   r   g333333?)range)r   cumir   r   r   stencil2_kernel)   s    r    g      ?)cvalc             C   s   d| d  S )Ng      ?)r   r   )r   r   r   r   stencil3_kernel1   s    r#   c             C   sD   d| d | d  | d  | d  |d  |d  |d  |d   S )Ng      ?)r   r   )r   r   )r   r   )r   r   r   )r   br   r   r   stencil_multiple_input_kernel6   s    r%   c             C   sD   || d | d  | d  | d  |d  |d  |d  |d   S )N)r   r   )r   r   )r   r   )r   r   r   )r   r$   wr   r   r   !stencil_multiple_input_kernel_var<   s    r'   )r$   )standard_indexingc             C   s    | d |d  | d |d   S )Nr   r   r   r   )r   r$   r   r   r   !stencil_with_standard_indexing_1dB   s    r)   c             C   s@   | d |d  | d |d   | d |d   | d |d   S )N)r   r   )r   r   )r   r   )r   r   r   )r   r$   r   r   r   !stencil_with_standard_indexing_2dG   s    r*   c             C   s   | d S )Nr   r   )r   r   r   r   addone_njitM   s    r+   T)parallelc             C   s   | d S )Nr   r   )r   r   r   r   addone_pjitT   s    r-   c                   sH   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	  Z
S )TestStencilBaseFc                s(   t  | _| jd tt| j|  d S )Nnrt)r   cflagssetsuperr.   __init__)selfargs)	__class__r   r   r3   ]   s    zTestStencilBase.__init__c             C   s   t tjjtjj||d |i S )N)r   r   Z
cpu_targetZtyping_contextZtarget_context)r4   funcsigflagsr   r   r   _compile_thisd   s    
zTestStencilBase._compile_thisc             K   s:   t  }|d |sdn|}|dt| | |||S )Nr/   TZauto_parallel)r   r1   r   r:   )r4   r7   r8   Zkwsr9   optionsr   r   r   compile_paralleli   s
    
z TestStencilBase.compile_parallelc             C   s   | j ||| jdS )N)r9   )r:   r0   )r4   r7   r8   r   r   r   compile_njitp   s    zTestStencilBase.compile_njitc             O   s2   t dd |D }| ||}| ||}||fS )Nc             S   s   g | ]}t |qS r   )numbatypeof).0xr   r   r   
<listcomp>t   s    z/TestStencilBase.compile_all.<locals>.<listcomp>)tupler<   r=   )r4   pyfuncr5   kwargsr8   cpfunccfuncr   r   r   compile_alls   s    zTestStencilBase.compile_allc       
      G   s   | j |f| \}}|| }|| }|j| }|j| }	tjj||dd tjj||dd tjj|	|dd | d|j  d S )N   )decimalz@do_scheduling)rH   entry_pointnptestingassert_almost_equalassertInlibraryget_llvm_str)
r4   Zno_stencil_funcrD   r5   rG   rF   expectedZ	py_outputnjit_outputparfor_outputr   r   r   check{   s    

zTestStencilBase.check)__name__
__module____qualname__Z_numba_parallel_test_r3   r:   r<   r=   rH   rU   __classcell__r   r   )r6   r   r.   Y   s   r.   c                   s   e Zd Z fddZeeddd Zeeddd Zeeddd	 Zeedd
d Z	eeddd Z
eeddd Zeeddd Zeeddd Zeeddd Zeeddd Zedd Z  ZS )TestStencilc                s   t t| j|| d S )N)r2   rZ   r3   )r4   r5   rE   )r6   r   r   r3      s    zTestStencil.__init__Z	importantc             C   s<   dd }dd }dd }d}|  ||| |  ||| dS )	zHTests whether the optional out argument to stencil calls works.
        c             S   s@   t | d | | f}t | d | | f}t||d}|S )Nr   )out)rL   arangereshapezerosr   )nABr   r   r   test_with_out   s    z0TestStencil.test_stencil1.<locals>.test_with_outc             S   s$   t | d | | f}t|}|S )Nr   )rL   r\   r]   r   )r_   r`   ra   r   r   r   test_without_out   s    z3TestStencil.test_stencil1.<locals>.test_without_outc             S   s   t | d | | f}t | d | | f}xztd| d D ]h}xbtd| d D ]P}d|||d f ||d |f  |||d f  ||d |f   |||f< qTW q@W |S )Nr   r   g      ?)rL   r\   r]   r^   r   )r_   r`   ra   r   jr   r   r   test_impl_seq   s    Rz0TestStencil.test_stencil1.<locals>.test_impl_seqd   N)rU   )r4   rb   rc   re   r_   r   r   r   test_stencil1   s    	zTestStencil.test_stencil1c       	      C   s8  dd }dd }d}|  ||| dd }dd }d}d}| |tjtjf}|||}|||}tjj||d	d
 | d|j	
  dd }d}| |tjtjtjf}||||}tjj||d	d
 | d|j	
  dd }d}| |tjtjtjf}||||}tjj||d	d
 | d|j	
  dS )z`Tests whether the optional neighborhood argument to the stencil
        decorate works.
        c             S   s   t | }t|}|S )N)rL   r\   r    )r_   r`   ra   r   r   r   test_seq   s    
z+TestStencil.test_stencil2.<locals>.test_seqc             S   sP   t | }t | }x6tdt|D ]$}dt||d |d   ||< q$W |S )N   g333333?r   )rL   r\   r^   r   lensum)r_   r`   ra   r   r   r   r   re      s
    

$z0TestStencil.test_stencil2.<locals>.test_impl_seqrf   c             S   s2   t | }dd }tj|| |ffd||}|S )Nc             S   s<   | |  }x(t | d |d D ]}|| | 7 }q W d| S )Nr   g333333?)r   )r   r&   r   r   r   r   r   r       s    
zDTestStencil.test_stencil2.<locals>.test_seq.<locals>.stencil2_kernel)r   )rL   r\   r>   r	   )r_   r&   r`   r    ra   r   r   r   rh      s    
c             S   sX   t | }t | }x>t|t|| D ](}dt||| || d   ||< q(W |S )Ng333333?r   )rL   r\   r^   r   rj   rk   )r_   r&   r`   ra   r   r   r   r   re      s
    

(ri   rI   )rJ   z@do_schedulingc             S   s8   t | }dd }tj|| |ff| fd||}|S )Nc             S   sD   | | d  }x,t | d |d D ]}|| |d  7 }q$W d| S )Nr   g333333?)r   )r   r&   r   r   r   r   r   r       s    zDTestStencil.test_stencil2.<locals>.test_seq.<locals>.stencil2_kernel)r   index_offsets)rL   r\   r>   r	   )r_   r&   offsetr`   r    ra   r   r   r   rh      s
    
r   c             S   s8   t | }dd }tj|| |ff| fd||}|S )Nc             S   s    dt | | d |d   S )Ng333333?r   r   )rL   rk   )r   r&   r   r   r   r       s    zDTestStencil.test_stencil2.<locals>.test_seq.<locals>.stencil2_kernel)r   rl   )rL   r\   r>   r	   )r_   r&   rm   r`   r    ra   r   r   r   rh      s
    
N)rU   r<   r
   intprK   rL   rM   rN   rO   rP   rQ   )	r4   rh   re   r_   r&   rF   rR   rT   rm   r   r   r   test_stencil2   s6    

	
zTestStencil.test_stencil2c             C   s   dd }t |}t |dd}d}||}||}||}| |d dkoR|d dk | |d dkop|d dk | |d dko|d dk d	S )
zTests whether a non-zero optional cval argument to the stencil
        decorator works.  Also tests integer result type.
        c             S   s$   t | d | | f}t|}|S )Nr   )rL   r\   r]   r#   )r_   r`   ra   r   r   r   rh     s    z+TestStencil.test_stencil3.<locals>.test_seqT)r,   ri   )r   r   g      ?)   rp   N)r   Z
assertTrue)r4   rh   Z	test_njitZtest_parr_   Zseq_resZnjit_resZpar_resr   r   r   test_stencil3  s    zTestStencil.test_stencil3c             C   s&   dd }dd }d}|  ||| dS )z1Tests standard indexing with a 1d array.
        c             S   s    t | }ddg}t||}|S )Ng      @g      @)rL   r\   r)   )r_   r`   ra   Cr   r   r   rh   $  s    

z?TestStencil.test_stencil_standard_indexing_1d.<locals>.test_seqc             S   s\   t | }ddg}t | }x:td| D ],}||d  |d  || |d   ||< q(W |S )Ng      @g      @r   r   )rL   r\   r^   r   )r_   r`   ra   rr   r   r   r   r   re   *  s    

,zDTestStencil.test_stencil_standard_indexing_1d.<locals>.test_impl_seqrf   N)rU   )r4   rh   re   r_   r   r   r   !test_stencil_standard_indexing_1d  s    	z-TestStencil.test_stencil_standard_indexing_1dc             C   s&   dd }dd }d}|  ||| dS )zLTests standard indexing with a 2d array and multiple stencil calls.
        c             S   s:   t | d | | f}t d}t||}t||}|S )Nr   )rI   rI   )rL   r\   r]   onesr*   )r_   r`   ra   rr   Dr   r   r   rh   ;  s
    


z?TestStencil.test_stencil_standard_indexing_2d.<locals>.test_seqc             S   s  t | d | | f}t d}t | d | | f}t | d | | f}xtd| d D ]}x~td| d D ]l}|||d f |d  ||d |f |d   |||d f |d   ||d |f |d   |||f< qvW qbW xtd| d D ]}xtd| d D ]n}|||d f |d  ||d |f |d   |||d f |d   ||d |f |d   |||f< qW qW |S )Nr   )rI   rI   r   )r   r   )r   r   )r   r   )r   r   )rL   r\   r]   rt   r^   r   )r_   r`   ra   rr   ru   r   rd   r   r   r   re   B  s    
przDTestStencil.test_stencil_standard_indexing_2d.<locals>.test_impl_seqri   N)rU   )r4   rh   re   r_   r   r   r   !test_stencil_standard_indexing_2d6  s    z-TestStencil.test_stencil_standard_indexing_2dc             C   s<   dd }dd }d}|  ||| dd }|  ||| dS )z=Tests whether multiple inputs of the same size work.
        c             S   s>   t | d | | f}t | d | | f}t||}|S )Nr   )rL   r\   r]   r%   )r_   r`   ra   rr   r   r   r   rh   Z  s    
z:TestStencil.test_stencil_multiple_inputs.<locals>.test_seqc             S   s  t | d | | f}t | d | | f}t | d | | f}xtd| d D ]}xtd| d D ]}d|||d f ||d |f  |||d f  ||d |f  |||d f  ||d |f  |||d f  ||d |f   |||f< qlW qXW |S )Nr   r   g      ?)rL   r\   r]   r^   r   )r_   r`   ra   rr   r   rd   r   r   r   re   `  s    z?TestStencil.test_stencil_multiple_inputs.<locals>.test_impl_seqrI   c             S   sD   t | d | | f}t | d | | f}d}t|||}|S )Nr   g      ?)rL   r\   r]   r'   )r_   r`   ra   r&   rr   r   r   r   rh   q  s
    N)rU   )r4   rh   re   r_   r   r   r   test_stencil_multiple_inputsU  s    z(TestStencil.test_stencil_multiple_inputsc             C   s<   dd }dd }dd }d}|  ||| |  ||| dS )	z&Tests 2D numba.stencil calls.
        c             S   sJ   t | d | | f}t | d | | f}tdd ||d |S )Nr   c             S   s$   d| d | d  | d  | d   S )Ng      ?)r   r   )r   r   )r   r   )r   r   r   )r   r   r   r   <lambda>  s   zCTestStencil.test_stencil_call.<locals>.test_impl1.<locals>.<lambda>)r[   )rL   r\   r]   r^   r>   r	   )r_   r`   ra   r   r   r   
test_impl1~  s
    
z1TestStencil.test_stencil_call.<locals>.test_impl1c             S   sJ   t | d | | f}t | d | | f}dd }t||}|S )Nr   c             S   s$   d| d | d  | d  | d   S )Ng      ?)r   r   )r   r   )r   r   )r   r   r   )r   r   r   r   sf  s    z=TestStencil.test_stencil_call.<locals>.test_impl2.<locals>.sf)rL   r\   r]   r^   r>   r	   )r_   r`   ra   rz   r   r   r   
test_impl2  s
    z1TestStencil.test_stencil_call.<locals>.test_impl2c             S   s   t | d | | f}t | d | | f}xztd| d D ]h}xbtd| d D ]P}d|||d f ||d |f  |||d f  ||d |f   |||f< qTW q@W |S )Nr   r   g      ?)rL   r\   r]   r^   r   )r_   r`   ra   r   rd   r   r   r   re     s    Rz4TestStencil.test_stencil_call.<locals>.test_impl_seqrf   N)rU   )r4   ry   r{   re   r_   r   r   r   test_stencil_cally  s    		zTestStencil.test_stencil_callc             C   s&   dd }dd }d}|  ||| dS )z&Tests 1D numba.stencil calls.
        c             S   s.   t | }t | }tdd ||d |S )Nc             S   s   d| d | d  | d   S )Ng333333?r   r   r   r   )r   r   r   r   rx     s    zETestStencil.test_stencil_call_1D.<locals>.test_impl.<locals>.<lambda>)r[   )rL   r\   r^   r>   r	   )r_   r`   ra   r   r   r   	test_impl  s    

z3TestStencil.test_stencil_call_1D.<locals>.test_implc             S   sX   t | }t | }x>td| d D ],}d||d  ||  ||d    ||< q$W |S )Nr   g333333?)rL   r\   r^   r   )r_   r`   ra   r   r   r   r   re     s
    

,z7TestStencil.test_stencil_call_1D.<locals>.test_impl_seqrf   N)rU   )r4   r}   re   r_   r   r   r   test_stencil_call_1D  s    z TestStencil.test_stencil_call_1Dc          	   C   sL  dd }dd }dd }dd }d	d
 }d}|  |tjf}|  |tjf}|  |tjf}	|  |tjf}
||}||}||}|	|}|
|}tjj||dd tjj||dd tjj||dd tjj||dd | t}|d W dQ R X | 	dt
|j | t}t|d W dQ R X | 	dt
|j dS )zTests numba.stencil call that has an index that can be inferred as
        constant from a unary expr. Otherwise, this would raise an error since
        neighborhood length is not specified.
        c             S   s4   t | }t | }d}tdd |||d |S )Nr   c             S   s   d| |  | d  | |   S )Ng333333?r   r   )r   cr   r   r   rx     s    zITestStencil.test_stencil_call_const.<locals>.test_impl1.<locals>.<lambda>)r[   )rL   r\   r^   r>   r	   )r_   r`   ra   r   r   r   r   ry     s    

z7TestStencil.test_stencil_call_const.<locals>.test_impl1c             S   s4   t | }t | }d}tdd |||d |S )Nr   c             S   s$   d| d|  | d  | |d    S )Ng333333?r   r   r   )r   r   r   r   r   rx     s    zITestStencil.test_stencil_call_const.<locals>.test_impl2.<locals>.<lambda>)r[   )rL   r\   r^   r>   r	   )r_   r`   ra   r   r   r   r   r{     s    

z7TestStencil.test_stencil_call_const.<locals>.test_impl2c             S   s4   t | }t | }d}tdd |||d |S )Nr   c             S   s&   d| | d  | d  | |d    S )Ng333333?r   r   r   )r   r   r   r   r   rx     s    zITestStencil.test_stencil_call_const.<locals>.test_impl3.<locals>.<lambda>)r[   )rL   r\   r^   r>   r	   )r_   r`   ra   r   r   r   r   
test_impl3  s    

z7TestStencil.test_stencil_call_const.<locals>.test_impl3c             S   s:   t | }t | }d}d}tdd ||||d |S )Nr   r   c             S   s&   d| | |  | d  | ||    S )Ng333333?r   r   )r   r   dr   r   r   rx     s    zITestStencil.test_stencil_call_const.<locals>.test_impl4.<locals>.<lambda>)r[   )rL   r\   r^   r>   r	   )r_   r`   ra   r   r   r   r   r   
test_impl4  s    

z7TestStencil.test_stencil_call_const.<locals>.test_impl4c             S   s\   t | }t | }d}x>td| d D ],}d|||  ||  |||    ||< q(W |S )Nr   g333333?)rL   r\   r^   r   )r_   r`   ra   r   r   r   r   r   re     s    

,z:TestStencil.test_stencil_call_const.<locals>.test_impl_seqrf   rI   )rJ   rp   NzDstencil kernel index is not constant, 'neighborhood' option required)r<   r
   rn   rK   rL   rM   rN   assertRaises
ValueErrorrO   str	exceptionr   r   )r4   ry   r{   r   r   re   r_   Zcpfunc1Zcpfunc2Zcpfunc3Zcpfunc4rR   Zparfor_output1Zparfor_output2Zparfor_output3Zparfor_output4er   r   r   test_stencil_call_const  s6    			



z#TestStencil.test_stencil_call_constc             C   s:   dd }| j |tjdd fdd}| d|j  dS )zYTests 1D numba.stencil calls without parallel translation
           turned off.
        c             S   s   t dd | S )Nc             S   s   d| d | d  | d   S )Ng333333?r   r   r   r   )r   r   r   r   rx     s    zJTestStencil.test_stencil_parallel_off.<locals>.test_impl.<locals>.<lambda>)r>   r	   )r`   r   r   r   r}     s    z8TestStencil.test_stencil_parallel_off.<locals>.test_implNF)r	   z@do_scheduling)r<   r>   float64ZassertNotInrP   rQ   )r4   r}   rF   r   r   r   test_stencil_parallel_off  s    z%TestStencil.test_stencil_parallel_offc                s  ddg}dd }x|D ]}t j||d  fdd}tdd	}t|d
}||dddf< t|} ||d tj|| | 	|}x"|D ]}	|	
 }
tj|
| qW qW t j|dd  fdd}tdd	}t|}| t} ||d W dQ R X d}| |t|j xf| j| jgD ]V}y||d W n8 ttfk
rz } z| |t| W dd}~X Y n
X tdq0W dS )z/ Issue #3518, out kwarg did not work with cval.r   g      @c             S   s   | d | d  S )N)r   r   )r   r   r   )r   r   r   r   kernel  s    z1TestStencil.test_out_kwarg_w_cval.<locals>.kernel)r!   c                 s*   t dd} t | } | |d |S )N   )rI   rp   )r[   )rL   r\   r]   	ones_like)r`   ret)
stencil_fnr   r   wrapped  s    
z2TestStencil.test_out_kwarg_w_cval.<locals>.wrappedr   )rI   rp   r   r   N)r[   y              ?c                 s*   t dd} t | } | |d |S )Nr   )rI   rp   )r[   )rL   r\   r]   r   )r`   r   )r   r   r   r   0  s    
z-cval type does not match stencil return type.r   zExpected error was not raised)r>   r	   rL   r\   r]   Z	full_liker   rM   rN   rH   rK   r   r   rO   r   r   r=   r<   r   AssertionError)r4   Z
const_valsr   Z	const_valr   r`   rR   r   implsimplZgotr   msgZcompilerr   )r   r   test_out_kwarg_w_cval  s:    




"z!TestStencil.test_out_kwarg_w_cval)rV   rW   rX   r3   skip_unsupportedr   rg   ro   rq   rs   rv   rw   r|   r~   r   r   r   rY   r   r   )r6   r   rZ      s,   U#!PrZ   c               @   s   e Zd ZdZG dd dZG dd dejeZG dd dejeZG dd	 d	ejeZ	G d
d dejeZ
G dd dejeZG dd dejZdd ZdS )pyStencilGeneratorz
    Holds the classes and methods needed to generate a python stencil
    implementation from a kernel purely using AST transforms.
    c               @   s~   e Zd ZdZdd Zdd dD Zdd Zdd
dZdd ZdddZ	dd Z
dd Zdd ZdddZdd Zd ddZdS )!zpyStencilGenerator.Builderz
        Provides code generation for the AST manipulation pipeline.
        The class methods largely produce AST nodes/trees.
        c             C   s
   d| _ d S )Nr   )_Builder__state)r4   r   r   r   r3   R  s    z#pyStencilGenerator.Builder.__init__c             C   s*   g | ]"}t d D ]}tt|| qqS )   )r   chrord)r@   vrA   r   r   r   rB   U  s    z%pyStencilGenerator.Builder.<listcomp>)r   r`   c             C   s   | j }| j d | _ |S )zZ
            a monotonically increasing index for use in labelling variables.
            r   )r   )r4   Ztmpr   r   r   varidxW  s    z!pyStencilGenerator.Builder.varidxr   c             C   s   t jt j|t  dgt jt jt jdt  ddt  dt jt j|t  ddt  d| |gt jd| 	d|j
gjdgd	d	d
d}|S )z
            Generates an AST equivalent to:
                `var = np.full(orig.shape, init_val, dtype = dtype_var)`
            )idctxrL   Zfull)valueattrr   shapedtypetype)argr   N)r7   r5   keywordsstarargsrE   )targetsr   )astAssignNameStoreCall	AttributeLoadgen_numkeywordgen_callr   r   )r4   ZorigvarZ	dtype_varZinit_valnewr   r   r   gen_alloc_return`  s.    




z+pyStencilGenerator.Builder.gen_alloc_returnc             C   sV   dd |D }t jt jt j|t  dt jt j|t  ddt  dg|d}|S )z
            Generates an AST equivalent to:
                `retvar[(*index_names,)] = value[<already present indexing>]`
            c             S   s   g | ]}t j|t  d qS ))r   r   )r   r   r   )r@   rA   r   r   r   rB     s    z9pyStencilGenerator.Builder.gen_assign.<locals>.<listcomp>)r   r   )eltsr   )r   )r   slicer   )r   r   )r   r   	Subscriptr   r   IndexTupler   )r4   r   r   Zindex_namesZ	elts_infor   r   r   r   
gen_assign  s    
z%pyStencilGenerator.Builder.gen_assignNc          	   C   sz   t |trtj|d}n|}t |tr4tj|d}n|}tjtj|t dtjtjdt d||gg ddd|g dS )z}
            Generates an AST equivalent to a loop in `var` from
            `start` to `stop` with body `body`.
            )r_   )r   r   r   N)r7   r5   r   r   rE   )targetiterbodyZorelse)	
isinstanceintr   NumZForr   r   r   r   )r4   r   startstopr   Z	start_valZstop_valr   r   r   gen_loop  s    

z#pyStencilGenerator.Builder.gen_loopc             C   s   t jt j|t  ddS )zE
            Generates an AST equivalent to `return var`
            )r   r   )r   )r   ZReturnr   r   )r4   r   r   r   r   
gen_return  s    z%pyStencilGenerator.Builder.gen_returnc             C   s   t jt j|ddS )z'Generates an Index with the given value)r_   )r   )r   r   r   )r4   r   r   r   r   	gen_slice  s    z$pyStencilGenerator.Builder.gen_slicec             C   s"   t jt j|t  d|t  dS )zA
            Generates AST equivalent to `name.attr`
            )r   r   )r   r   r   )r   r   r   r   )r4   namer   r   r   r   gen_attr  s    z#pyStencilGenerator.Builder.gen_attrc       	      C   sf   |  ||}| |}tj||t d}|rb|dkr>t nt }tj||tjt	|dd}|S )z
            Generates an AST equivalent to a subscript, something like:
                name.attr[slice(index) +/- offset]
            )r   r   r   r   )r_   )leftopright)
r   r   r   r   r   AddSubBinOpr   abs)	r4   r   r   indexrm   Z	attributeZsliseZssZpmr   r   r   gen_subscript  s    
z(pyStencilGenerator.Builder.gen_subscriptc             C   sJ   t |trtt|S t|dkr.t|S tt t| S dS )z?
            Generates an ast.Num of value `value`
            r   N)r   boolr   r   r   r   UnaryOpZUSub)r4   r   r   r   r   r     s
    

z"pyStencilGenerator.Builder.gen_numc             C   s^   dd |D }|dk	r&dd |D }ng }t j|t  d}t jt j|||dddt  dS )z|
            Generates an AST equivalent to a call, something like:
                `call_name(*args, **kwargs)
            c             S   s"   g | ]}t jd | t  dqS )z%s)r   r   )r   r   r   )r@   rA   r   r   r   rB     s    z7pyStencilGenerator.Builder.gen_call.<locals>.<listcomp>Nc             S   s0   g | ](}t jd | t t|jd jdqS )z%sr   )r   r   )r   r   parser   r   r   )r@   rA   r   r   r   rB     s   )r   r   )r7   r5   r   r   rE   )r   r   )r   r   r   ZExprr   )r4   Z	call_namer5   rE   Z
fixed_argsr   r7   r   r   r   r     s    
z#pyStencilGenerator.Builder.gen_call)r   )r   r   N)N)N)rV   rW   rX   __doc__r3   idsr   r   r   r   r   r   r   r   r   r   r   r   r   r   BuilderL  s   	
 

r   c               @   s4   e Zd ZdZejejejej	ej
ejiZdd ZdS )zpyStencilGenerator.FoldConstzn
        Folds const expr, this is so const expressions in the relidx are
        more easily handled
        c             C   sz   |  |}| j|jj}t|dd }t|dd }|r>|r>|sB|S t|tjrrt|tjrrt||j	j
|jj
S |S d S )Nr   r   )generic_visitsupported_opsgetr   r6   getattrr   r   r   r   r_   r   )r4   noder   ZlhsZrhsr   r   r   visit_BinOp  s    
z(pyStencilGenerator.FoldConst.visit_BinOpN)rV   rW   rX   r   r   r   operatoraddr   subZMultmulr   r   r   r   r   r   	FoldConst  s
   r   c               @   sX   e Zd Z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S )zpyStencilGenerator.FixRelIndexza Fixes the relative indexes to be written in as
        induction index + relative index
        c             O   s   t jj| f|| tjj| f|| || _|| _d| _d | _d | _	t
tj| _t
tj| _|rj|ng | _|| _|r~dnd| _d S )Nr   z__%snz__%s)r   NodeTransformerr3   r   r   	_argnames_const_assigns_idx_len_mins_maxesrL   Ziinfor   min_iminmax_imax_standard_indexing_neighborhood_id_pat)r4   argnamesconst_assignsr(   r   r5   rE   r   r   r   r3     s    z'pyStencilGenerator.FixRelIndex.__init__c             C   s4   t |tjr|jS t |tjr(|jj S tddS )zF
            Gets the literal value from a Num or UnaryOp
            z,get_val_from_num: Unknown indexing operationN)r   r   r   r_   r   Zoperandr   )r4   r   r   r   r   get_val_from_num  s    
z/pyStencilGenerator.FixRelIndex.get_val_from_numc          	   C   s\  |  |}|jj| jkrT|jj| jkrTt|jjtjrhg }xbt	|jjj
D ]P\}}| j||}|tjtj| j| j|  t dt |t d qPW | jdkrt|| _n| jt|krtdt|jtjrd}t|t }tj|jtjtj|t dt d|d}t|| t| | jd	krn| jd	krn| jg| j | _| j g| j | _| j!s"xt	|jjj
D ]\}}	t|	tj"st|	tj#r| $|	}
n0t%|	d
r|	j| jkr| j|	j }
ntd|
| j| k r |
| j|< |
| j| kr|
| j|< qW nBx@t	| j!D ]2\}}	| j!| d | j|< | j!| d | j|< q.W |S t|jtjrJ| j|jj|jj}tjtj| j| jd  t dt |t d}| jdkrd| _n| jdkrtdt|jtjrd}t|t }tj|jtj|t d|d}t|| t| | jd	krp| jd	krp| jg| _| j g| _| j!st|jjtj"st|jjtj#r| $|jj}
n<t%|jjd
r|jjj| jkr| j|jjj }
ntd|
| jd k r|
| jd< |
| jd krF|
| jd< n(| j!d d | jd< | j!d d | jd< |S tdn|S d	S )z
            Transforms subscripts of the form `a[x]` and `a[x, y, z, ...]`
            where `x, y, z` are relative indexes, to forms such as:
            `a[x + i]` and `a[x + i, y + j, z + k]` for use in loop induced
            indexing.
            )r   r   )r   r   r   r   r   z#Relative indexing mismatch detectedz=Assignments to array passed to stencil kernels is not allowed)r   r   )r   r   )r   r   r   Nr   zCannot interpret indexing valuer   r   zUnhandled subscript)&r   r   r   r   r   r   r   r   r   	enumerater   r   r   appendr   r   r   r   r   r   r   rj   r   r   r   r   r   copy_locationfix_missing_locationsr   r   r   r   r   r   r   r   hasattr)r4   r   idxrA   valZusevalr   contextZnewnodeZlnodeZrelvaluer   r   r   visit_Subscript(  s    















z.pyStencilGenerator.FixRelIndex.visit_Subscriptc             C   s   | j dkrtdn| j S d S )Nr   z+Transform has not been run/no indexes found)r   r   )r4   r   r   r   idx_len  s    
z&pyStencilGenerator.FixRelIndex.idx_lenc             C   s   | j S )N)r   )r4   r   r   r   maxes  s    z$pyStencilGenerator.FixRelIndex.maxesc             C   s   | j S )N)r   )r4   r   r   r   mins  s    z#pyStencilGenerator.FixRelIndex.minsc             C   s   | j S )N)r   )r4   r   r   r   
id_pattern  s    z)pyStencilGenerator.FixRelIndex.id_patternN)rV   rW   rX   r   r3   r   r   propertyr   r   r   r   r   r   r   r   FixRelIndex  s    r  c               @   s,   e Zd ZdZdd Zdd Zedd ZdS )	z#pyStencilGenerator.TransformReturnsz;
        Transforms return nodes into assignments.
        c             O   sL   t jj| f|| tjj| f|| || _|  | _d| j }|| _d S )Nz__b%s)	r   r   r3   r   r   _relidx_infor   Z_ret_var_idx_retvarname)r4   relidx_infor5   rE   retvarr   r   r   r3     s    

z,pyStencilGenerator.TransformReturns.__init__c                s@     |  jj} jj  j|j fddt|D S )Nc                s   g | ]} j |  qS r   )r   )r@   l)r4   var_patternr   r   rB     s    zDpyStencilGenerator.TransformReturns.visit_Return.<locals>.<listcomp>)r   r  r   r   r   r  r   r   )r4   r   nloopsr   )r4   r  r   visit_Return  s    
z0pyStencilGenerator.TransformReturns.visit_Returnc             C   s   | j S )N)r  )r4   r   r   r   ret_var_name  s    z0pyStencilGenerator.TransformReturns.ret_var_nameN)rV   rW   rX   r   r3   r	  r   r
  r   r   r   r   TransformReturns  s   r  c               @   s    e Zd ZdZdd Zdd ZdS )zpyStencilGenerator.FixFuncz The main function rewriter, takes the body of the kernel and generates:
         * checking function calls
         * return value allocation
         * loop nests
         * return site
         * Function definition as an entry point
        c       	         s   t jj f|| tjj f|| |j _|j _|j	 _
| _| _|rT|ng  _|rb|nt  _ fdd jD  _t|dr|  _n| _ jd  _d S )Nc                s   g | ]}| j kr|qS r   )r   )r@   rA   )r4   r   r   rB     s    z7pyStencilGenerator.FixFunc.__init__.<locals>.<listcomp>r   r   )r   r   r3   r   r   original_kernel_original_kernelr   r   retty_rettyr  	_ret_infor   rC   r   _relidx_argsr   tolistr!   stencil_arr)	r4   Zkpropsr  Zret_infor!   r(   r   r5   rE   r   )r4   r   r3     s    
z#pyStencilGenerator.FixFunc.__init__c          
   C   s  |  | dd }t|}t| jd }t| | jd| j	dgd}| j
j}dd }| j
j}|j}	d}
xnt|D ]b}|| j
j|
 | j
j|
 \}}|}| | jd	|
|}| j|| j|
  |||	d
}|g}	|
d7 }
qzW t|| | jjd }| jj}| | j||| j}t|| | |}t|| trPtdt g}ntddg}tjdt  dg}tj!|j"j"| |ddg g d}tj#d|j$ |||| j%| j|||gg d}t|| |S )z
            Transforms the kernel function into a function that will perform
            the stencil like behaviour on the kernel.
            c              _   sj   | d}| d j}|d k	r4t|t|kr4tdx0| dd  D ] }t|drB||jkrBtdqBW d S )Nr   r   zInvalid neighborhood suppliedr   r   z#Input stencil arrays do not commute)r   r   rj   r   r   )r5   rE   r   Z
init_shaperA   r   r   r   check_stencil_arrays  s    



zJpyStencilGenerator.FixFunc.visit_FunctionDef.<locals>.check_stencil_arraysr   r  r   )rE   c             S   s,   | dkrdn|  }|dkr | nd}||fS )Nr   r   )r   Zmaxsminlimmaxlimr   r   r   computebound  s    zBpyStencilGenerator.FixFunc.visit_FunctionDef.<locals>.computeboundr   )r   r   NNone)r   r   )r5   defaultsZvarargkwargZ
kwonlyargsZkw_defaultsz__%s)r   r5   r   Zdecorator_list)&r   inspect	getsourcer   r   stripr   r   r   r  r  r   r   r   r   r   r   r  r   r   r   r  r   r  r
  r   r!   r   _py27r   ZParamr   r   Z	argumentsr5   ZFunctionDefr   r  )r4   r   r  ZchecksrcZ
check_implZchecker_callr  r  r  Z	loop_bodyZ
loop_countr  r  r  ZminboundZmaxboundZloopsZ
_rettynamer  allocateZreturnerZ	add_kwargr  Znewargsr   r   r   r   visit_FunctionDef  sz    





z,pyStencilGenerator.FixFunc.visit_FunctionDefN)rV   rW   rX   r   r3   r   r   r   r   r   FixFunc  s   r!  c               @   sX   e Zd Z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S )z!pyStencilGenerator.GetKernelPropszV Gets the argument names and other properties
        of the original kernel.
        c             O   sJ   t jj| f|| tjj| f|| d | _d | _d | _d | _i | _	d S )N)
r   NodeVisitorr3   r   r   r   _kwargnamesr  r  r   )r4   r5   rE   r   r   r   r3   d  s    z*pyStencilGenerator.GetKernelProps.__init__c                s   | j d k	s| jd k	rtdtr&d nd  fdd|jjD | _ |jjr^dd |jjD | _| |j| j }tj	tj
dt dg|jd	| _tt|| _| | d S )
Nz%multiple definition of function/args?r   r   c                s   g | ]}t | qS r   )r   )r@   rA   )r   r   r   rB   v  s    zGpyStencilGenerator.GetKernelProps.visit_FunctionDef.<locals>.<listcomp>c             S   s   g | ]
}|j qS r   )r   )r@   rA   r   r   r   rB   x  s    Z
__retdtype)r   r   )r   r   )r   r#  RuntimeErrorr  r5   r  r   r   r   r   r   r   r   r  r   r   r  r   )r4   r   Zcompute_retdtyper   )r   r   r   m  s    z3pyStencilGenerator.GetKernelProps.visit_FunctionDefc             C   s   |  | |j}t|dkr|d }t|tjrt|jtjrP|jj| j	|j
< n@t|jtjrt|jtjr~|jj| j	|j
< n|jj | j	|j
< d S )Nr   r   )r   r   rj   r   r   r   r   r   r_   r   r   r   ZUAdd)r4   r   Ztgtr   r   r   r   visit_Assign  s    
z.pyStencilGenerator.GetKernelProps.visit_Assignc             C   s   | j S )zD
            The names of the arguments to the function
            )r   )r4   r   r   r   r     s    z*pyStencilGenerator.GetKernelProps.argnamesc             C   s   | j S )z{
            A map of variable name to constant for variables that are simple
            constant assignments
            )r   )r4   r   r   r   r     s    z/pyStencilGenerator.GetKernelProps.const_assignsc             C   s   | j S )z)
            The return type
            )r  )r4   r   r   r   r    s    z'pyStencilGenerator.GetKernelProps.rettyc             C   s   | j S )z7
            The original unmutated kernel
            )r  )r4   r   r   r   r    s    z1pyStencilGenerator.GetKernelProps.original_kernelN)rV   rW   rX   r   r3   r   r%  r   r   r   r  r  r   r   r   r   GetKernelProps_  s   	r&  c               @   s   e Zd ZdZdd ZdS )zpyStencilGenerator.FixCallsz3 Fixes call sites for astor (in case it is in use) c             C   s(   |  | tj|j|j|jd d d}|S )N)r7   r5   r   r   rE   )r   r   r   r7   r5   r   )r4   r   r   r   r   r   
visit_Call  s    
z&pyStencilGenerator.FixCalls.visit_CallN)rV   rW   rX   r   r'  r   r   r   r   FixCalls  s   r(  c       
         s   t |}t| }d}|r6td tt|  fdd}|| |rtd ttj|dd ydd	l}	t|	| W n t	k
r   Y nX |S )
z
        Generates the AST tree for a stencil from:
        func - a python stencil kernel
        cval, standard_indexing and neighborhood as per the @stencil decorator
        FZORIGINALc                s     }||  |j}|j}rDx D ]}||kr(d}t|q(W  }||  ||}||  |}||  ||| }	|	|  	 }
|
|  t
| jd  dS )z the pipeline of manipulations z4Non-existent variable specified in standard_indexingr   N)r&  Zvisitr   r   r   r   r  r  r!  r(  r   r   r   )treeZkernel_propsZargnmZ
const_asgnrA   r   Z
fold_constZrelidx_fixerZreturn_transformerZfixerZ	callFixer)r!   r   r4   r(   r   r   pipeline  s6    







z:pyStencilGenerator.generate_stencil_tree.<locals>.pipelinez


NEWT)Zinclude_attributesr   N)
r  r  r   r   r  printdumpastorZ	to_sourceImportError)
r4   r7   r!   r(   r   srcr)  DEBUGr*  r-  r   )r!   r   r4   r(   r   generate_stencil_tree  s"    
-z(pyStencilGenerator.generate_stencil_treeN)rV   rW   rX   r   r   r   r   r   r  r  r!  r"  r&  r(  r1  r   r   r   r   r   F  s     < Lr   constantc             K   s   t | tsd}| }nt | ts&td| }d}x |D ]}|dkr4td| q4W |dkrdtd| |dd}|d	d}|d
d}t }|||||}	t|	ddd}
|
jd }t	
|t }|S )zs
    A pure python implementation of (a large subset of) stencil functionality,
    equivalent to StencilFunc.
    r2  zWstencil mode should be
                                                        a stringN)r!   r(   r   zUnknown stencil option zUnsupported mode style r!   r   r(   r   z<ast>exec)filenamemode)r   r   r   r   r   r   r1  compile	co_constspytypesFunctionTypeglobals)func_or_moder;   r5  r7   Zoptionr!   r(   r   genr)  Zmod_codeZ	func_codeZ	full_funcr   r   r   	pyStencil  s,    



r=  c                   sh  e 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 Zdd Zd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%dGdH Z&dIdJ Z'e()dKdLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;dpdq Z<drds Z=e()dtdudv Z>dwdx Z?dydz Z@d{d| ZAd}d~ ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd ZdddĄ ZeddƄ ZfddȄ Zgddʄ Zhdd̄ Zidd΄ ZjddЄ Zkdd҄ Zl  ZmS )TestManyStencilsc                s   t t| j|| d S )N)r2   r>  r3   )r4   r5   rE   )r6   r   r   r3   /  s    zTestManyStencils.__init__c                s  | dt }| d}d}g  g td. fdd	}t|trd|d }|d }	|d	 }
|d
 }n|}|}	|}
|}d|i}|| d}y8tf d|i|}||d| di}|rtd| W nF tk
r } z&||d
 |W dQ R X |}d}W dd}~X Y nX d}||	d tf || }W dQ R X t	|dkrRfdd}nHt	|dkrnfdd}n,t	|dkrfdd}nt
dt	| tdd |D }d}||
d	 | ||}|j| }W dQ R X d}||d | ||}|j| }W dQ R X |r0td| td| td| |ry,|	s`tjj||dd | |j|j W nR tk
r } z2ddt|t|f f td t|  W dd}~X Y nX y,|
stjj||dd | |j|j W nR tk
r4 } z2d	dt|t|f f td!t|  W dd}~X Y nX yf|stjj||dd | |j|j y| d"|j  W n" tk
r   d#}t|Y nX W nR tk
r } z2ddt|t|f f td$t|  W dd}~X Y nX |rtd%  rd&d  D }td'| rbd(d D }d)d*d D }d+| }d,| }t|| |s||dkr|td-|dS )/a  
        For a given kernel:

        The expected result is computed from a pyStencil version of the
        stencil.

        The following results are then computed:
        * from a pure @stencil decoration of the kernel.
        * from the njit of a trivial wrapper function around the pure @stencil
          decorated function.
        * from the njit(parallel=True) of a trivial wrapper function around
           the pure @stencil decorated function.

        The results are then compared.
        r;   expected_exceptionFNc          
   3   s   y
d V  W n t k
r } zf| d k	r`t| dr2| n| g}d}x|D ]}|t||O }qBW |s~ n|dt|t|f f W d d }~X Y nX | d k	r | d S )N__iter__Fz%s: %s)	Exceptionr   r   r   r   r   )ZextyZusecaser   Zlextyfoundex)should_failshould_not_failr   r   errorhandlerN  s    

(z,TestManyStencils.check.<locals>.errorhandlerr=  r	   r   parforr;  Tr   z
Expected:
z@stencilr   c                s    | S )Nr   )arg0)stencil_func_implr   r   wrap_stencil  s    z,TestManyStencils.check.<locals>.wrap_stencilr   c                s
    | |S )Nr   )rH  arg1)rI  r   r   rJ    s    rI   c                s    | ||S )Nr   )rH  rK  Zarg2)rI  r   r   rJ    s    z+Up to 3 arguments can be provided, found %sc             S   s   g | ]}t |qS r   )r>   r?   )r@   rA   r   r   r   rB     s    z*TestManyStencils.check.<locals>.<listcomp>Zparforsz
@stencil_output:
z
njit_output:
z
parfor_output:
)rJ   z%s: %sz@stencil failed: %sz@njit failed: %sz@do_schedulingz*Could not find `@do_scheduling` in LLVM IRz@njit(parallel=True) failed: %sz

c             S   s   g | ]}d | qS )z%sr   )r@   rA   r   r   r   rB     s    zMThe following implementations should have raised an exception but did not:
%sc             S   s   g | ]}d |d  qS )z%sr   r   )r@   rA   r   r   r   rB     s     c             S   s   g | ]}d | qS )z%s: Message: %s

r   )r@   rA   r   r   r   rB     s   zNThe following implementations should not have raised an exception but did:
%s
zErrors were:

%sz)pyStencil failed, was not caught/expected)NN)r   dictr   r   updater=  r+  rA  r	   rj   r   rC   r=   rK   r<   rL   rM   rN   ZassertEqualr   r   r   r   rO   rP   rQ   r   r$  join)r4   rD   r5   rE   r;   r?  ZDEBUG_OUTPUTrF  Zpystencil_exZ
stencil_exZnjit_exZ	parfor_exZstencil_argsZexpected_presentZast_implrR   rC  ZpyStencil_unhandled_exZstencilfunc_outputrJ  r8   rS   Zwrapped_cfuncrT   Zwrapped_cpfuncr   r   r   ZerrsZstr1Zstr2r   )rD  rE  rI  r   rU   2  s    







"""


zTestManyStencils.checkc             K   sH   t  }d |d< d |d< d |d< d |d< x| D ]\}}|||< q0W |S )Nr=  r	   r   rG  )rM  items)r4   rE   r   kr   r   r   r   exception_dict  s    zTestManyStencils.exception_dictc             C   s*   dd }t ddd}| || dS )z	rel indexc             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic00.<locals>.kernelr   rI   rp   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic00  s    zTestManyStencils.test_basic00c             C   s*   dd }t ddd}| || dS )zrel index add constc             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic01.<locals>.kernelg      (@rI   rp   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic01  s    zTestManyStencils.test_basic01c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r      s    z-TestManyStencils.test_basic02.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic02  s    zTestManyStencils.test_basic02c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic03.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic03  s    zTestManyStencils.test_basic03c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic04.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic04  s    zTestManyStencils.test_basic04c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic05.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic05  s    zTestManyStencils.test_basic05c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r      s    z-TestManyStencils.test_basic06.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic06  s    zTestManyStencils.test_basic06c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r   (  s    z-TestManyStencils.test_basic07.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic07$  s    zTestManyStencils.test_basic07c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r   0  s    z-TestManyStencils.test_basic08.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic08,  s    zTestManyStencils.test_basic08c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d S )N)r"   r   r   )r   r   r   r   r   8  s    z-TestManyStencils.test_basic09.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic094  s    zTestManyStencils.test_basic09c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d | d  S )N)r   r   )r   r   r   )r   r   r   r   r   @  s    z-TestManyStencils.test_basic10.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic10<  s    zTestManyStencils.test_basic10c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d | d  S )N)r   r   )r   r   r   )r   r   r   r   r   H  s    z-TestManyStencils.test_basic11.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic11D  s    zTestManyStencils.test_basic11c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d | d  S )N)r   r   )r   r   r   )r   r   r   r   r   P  s    z-TestManyStencils.test_basic12.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic12L  s    zTestManyStencils.test_basic12c             C   s*   t ddd}dd }| || dS )zrel index add constg      (@rI   rp   c             S   s   | d | d  S )N)r   r   )r   r   r   )r   r   r   r   r   X  s    z-TestManyStencils.test_basic13.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic13T  s    zTestManyStencils.test_basic13c             C   s*   t ddd}dd }| || dS )z!rel index add domain change constr   rI   rp   c             S   s   | d d S )N)r   r   y              ?r   )r   r   r   r   r   `  s    z-TestManyStencils.test_basic14.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic14\  s    zTestManyStencils.test_basic14c             C   s*   t ddd}dd }| || dS )z!rel index add domain change constr   rI   rp   c             S   s   d}| d | S )Ny              ?)r   r   r   )r   tr   r   r   r   h  s    z.TestManyStencils.test_basic14b.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic14bd  s    zTestManyStencils.test_basic14bc             C   s*   t ddd}dd }| || dS )ztwo rel index, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )r   r   g      ?r   )r   r   r   r   r   q  s    z-TestManyStencils.test_basic15.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic15m  s    zTestManyStencils.test_basic15c             C   s:   t ddd}dd }| jtd}| j|||d dS )	ztwo rel index OOB, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )
   r   g      ?r   )r   r   r   r   r   y  s    z-TestManyStencils.test_basic16.<locals>.kernel)r=  )r?  N)rL   r\   r]   rR  
IndexErrorrU   )r4   r   r   rC  r   r   r   test_basic16u  s    zTestManyStencils.test_basic16c             C   s*   t ddd}dd }| || dS )z&two rel index boundary test, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )r   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic17.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic17  s    zTestManyStencils.test_basic17c             C   s*   t ddd}dd }| || dS )z&two rel index boundary test, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )r"   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic18.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic18  s    zTestManyStencils.test_basic18c             C   s*   t ddd}dd }| || dS )z&two rel index boundary test, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )r   rI   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic19.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic19  s    zTestManyStencils.test_basic19c             C   s*   t ddd}dd }| || dS )z&two rel index boundary test, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   )r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic20.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic20  s    zTestManyStencils.test_basic20c             C   s*   t ddd}dd }| || dS )zsame rel, add constr   rI   rp   c             S   s   | d | d  d S )N)r   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic21.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic21  s    zTestManyStencils.test_basic21c             C   s*   t ddd}dd }| || dS )z%rel idx const expr folding, add constg      (@rI   rp   c             S   s   | d | d  d S )N)r   r   )r   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic22.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic22  s    zTestManyStencils.test_basic22c             C   s*   t ddd}dd }| || dS )zrel idx, work in bodyg      (@rI   rp   c             S   s&   t d| d  }| d | d  | S )Nre  )r   r   )r   r   )r   r   )rL   sin)r   rA   r   r   r   r     s    z-TestManyStencils.test_basic23.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic23  s    zTestManyStencils.test_basic23c             C   s*   t ddd}dd }| || dS )z,rel idx, dead code should not impact rel idxg      (@rI   rp   c             S   s"   t d| d  }| d | d  S )Nre  )r   r   )r   r   )r   r   )rL   ro  )r   rA   r   r   r   r     s    z.TestManyStencils.test_basic23a.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic23a  s    zTestManyStencils.test_basic23ac             C   s2   t ddd}dd }| j||ttgd dS )z1d idx on 2d arrr   rI   rp   c             S   s   | d d S )Nr   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic24.<locals>.kernel)r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic24  s    zTestManyStencils.test_basic24c             C   s2   t ddd}dd }| j||ttgd dS )zno idx on 2d arrr   rI   rp   c             S   s   dS )Ng      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic25.<locals>.kernel)r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic25  s    zTestManyStencils.test_basic25c             C   s,   t dddd}dd }| || dS )z3d arr@   rp      r   c             S   s   | d | d  d S )N)r   r   r   )r   r   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic26.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic26  s    zTestManyStencils.test_basic26c             C   s.   t ddddd}dd }| || dS )z4d arr   rp   ru  r   c             S   s   | d | d  d S )N)r   r   r   r   )r   r   r   r   g      ?r   )r   r   r   r   r     s    z-TestManyStencils.test_basic27.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic27  s    zTestManyStencils.test_basic27c             C   s2   t dddt j}dd }| || dS )ztype widen r   rI   rp   c             S   s   | d t d S )N)r   r   g      $@)rL   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic28.<locals>.kernelN)rL   r\   r]   astypeZfloat32rU   )r4   r   r   r   r   r   test_basic28  s    zTestManyStencils.test_basic28c             C   s2   t ddd}dd }| j||ttgd dS )zconst index from func g      (@rI   rp   c             S   s   | dt tdf S )Nr   )r   rL   cos)r   r   r   r   r     s    z-TestManyStencils.test_basic29.<locals>.kernel)r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic29  s    zTestManyStencils.test_basic29c             C   s*   t ddd}dd }| || dS )zsigned zerosg      (@rI   rp   c             S   s   | d S )N)r   r   r   )r   r   r   r   r     s    z-TestManyStencils.test_basic30.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic30  s    zTestManyStencils.test_basic30c             C   s*   t ddd}dd }| || dS )zdoes a const propagate? 2Dg      (@rI   rp   c             S   s   d}| |df S )Nr   r   r   )r   rb  r   r   r   r     s    z-TestManyStencils.test_basic31.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic31  s    zTestManyStencils.test_basic31z constant folding not implementedc             C   s*   t ddd}dd }| || dS )zdoes a const propagate?g      (@rI   rp   c             S   s   d}d| }| |df S )Nr   r   r   )r   srb  r   r   r   r     s    z.TestManyStencils.test_basic31b.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic31b  s    zTestManyStencils.test_basic31bc             C   s"   t d}dd }| || dS )zdoes a const propagate? 1Dg      (@c             S   s   d}| | S )Nr   r   )r   rb  r   r   r   r     s    z.TestManyStencils.test_basic31c.<locals>.kernelN)rL   r\   rU   )r4   r   r   r   r   r   test_basic31c  s    
zTestManyStencils.test_basic31cc             C   s2   t ddd}dd }| j||ttgd dS )ztyped int indexg      (@rI   rp   c             S   s   | t ddf S )Nr   r   )rL   Zint8)r   r   r   r   r     s    z-TestManyStencils.test_basic32.<locals>.kernel)r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic32  s    zTestManyStencils.test_basic32c             C   s*   t ddd}dd }| || dS )zadd 0d arrayg      (@rI   rp   c             S   s   | d t d S )N)r   r   r   )rL   array)r   r   r   r   r   #  s    z-TestManyStencils.test_basic33.<locals>.kernelN)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic33  s    zTestManyStencils.test_basic33c             C   s*   dd }t ddd}| || dS )z<More complex rel index with dependency on addition rel indexc             S   s6   d| d  }|| d | d  | d  t | d   S )Ng      @)r   r   )r   r   )r   r   )r"   r   )rL   ro  )r   gr   r   r   r   )  s    z-TestManyStencils.test_basic34.<locals>.kernel   r   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic34'  s    zTestManyStencils.test_basic34c             C   sD   dd }t ddd}| jtttd}| j||ddi|d	 d
S )zsimple cval c             S   s   | d S )N)r   r   r   )r   r   r   r   r   1  s    z-TestManyStencils.test_basic35.<locals>.kernelg      (@rI   rp   )r	   rG  r   r!   ri   )r;   r?  N)rL   r\   r]   rR  r   r   rU   )r4   r   r   rC  r   r   r   test_basic35/  s    zTestManyStencils.test_basic35c             C   s2   dd }t ddd}| j||ddid d	S )
zmore complex with cvalc             S   s    | d | d  | d  | d  S )N)r   r   )r   r   )r   r   r   )r   r   r   r   r   <  s    z-TestManyStencils.test_basic36.<locals>.kernelg      (@rI   rp   r!   g      @)r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic36:  s    zTestManyStencils.test_basic36c             C   s2   dd }t ddd}| j||ddid d	S )
zcval is exprc             S   s    | d | d  | d  | d  S )N)r   r   )r   r   )r   r   r   )r   r   r   r   r   C  s    z-TestManyStencils.test_basic37.<locals>.kernelg      (@rI   rp   r!   g      Q@)r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic37A  s    zTestManyStencils.test_basic37c             C   sD   dd }t ddd}| jtttd}| j||ddi|d	 d
S )zcval is complexc             S   s    | d | d  | d  | d  S )N)r   r   )r   r   )r   r   r   )r   r   r   r   r   J  s    z-TestManyStencils.test_basic38.<locals>.kernelg      (@rI   rp   )r	   rG  r   r!   y              ?)r;   r?  N)rL   r\   r]   rR  r   r   rU   )r4   r   r   rC  r   r   r   test_basic38H  s    zTestManyStencils.test_basic38c             C   sB   dd }t ddd}| j||dt dt d id	 d
S )zcval is func exprc             S   s    | d | d  | d  | d  S )N)r   r   )r   r   )r   r   r   )r   r   r   r   r   U  s    z-TestManyStencils.test_basic39.<locals>.kernelg      (@rI   rp   r!   g      @r   )r;   N)rL   r\   r]   rU   ro  r{  )r4   r   r   r   r   r   test_basic39S  s    zTestManyStencils.test_basic39c             C   s>   dd }t ddd}t ddd}| ||| dS )z2 args!c             S   s   | d |d  S )N)r   r   )r   r"   r   )r   r$   r   r   r   r   \  s    z-TestManyStencils.test_basic40.<locals>.kernelg      (@rI   rp   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic40Z  s    zTestManyStencils.test_basic40c             C   sF   dd }t ddd}t ddd}| j|||ttgd d	S )
z(2 args! rel arrays wildly not same size!c             S   s   | d |d  S )N)r   r   )r   r"   r   )r   r$   r   r   r   r   d  s    z-TestManyStencils.test_basic41.<locals>.kernelg      (@rI   rp   g      ?r   )r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic41b  s    zTestManyStencils.test_basic41c             C   sF   dd }t ddd}t ddd}| j|||ttgd dS )	z%2 args! rel arrays very close in sizec             S   s   | d |d  S )N)r   r   )r   r"   r   )r   r$   r   r   r   r   n  s    z-TestManyStencils.test_basic42.<locals>.kernelg      (@rI   rp   g      "@)r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic42l  s    zTestManyStencils.test_basic42c             C   s>   dd }t ddd}t ddd}| ||| dS )z2 args more complexityc             S   s    | d | d  |d  |d  S )N)r   r   )r   r   )r"   r   )r   r   r   )r   r$   r   r   r   r   x  s    z-TestManyStencils.test_basic43.<locals>.kernelg      >@ri      N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic43v  s    zTestManyStencils.test_basic43c             C   sF   dd }t ddd}t ddd}| j|||ttgd dS )z!2 args, has assignment before usec             S   s   d| d< | d S )Nr   )r   r   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic44.<locals>.kernelg      (@rI   rp   )r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic44~  s    zTestManyStencils.test_basic44c             C   sF   dd }t ddd}t ddd}| j|||ttgd dS )z02 args, has assignment and then cross dependencyc             S   s   d| d< | d | d  S )Nr   )r   r   )r   r   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic45.<locals>.kernelg      (@rI   rp   )r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic45  s    zTestManyStencils.test_basic45c             C   sF   dd }t ddd}t ddd}| j|||ttgd dS )z#2 args, has cross relidx assignmentc             S   s   |d | d< | d | d  S )N)r   r   )r   r   )r   r   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic46.<locals>.kernelg      (@rI   rp   )r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic46  s    zTestManyStencils.test_basic46c             C   sR   dd }t ddd}t ddd}t ddd}| |||| dS )z3 argsc             S   s   | d |d  |d  S )N)r   r   )r   r   )r   r   r   )r   r$   r   r   r   r   r     s    z-TestManyStencils.test_basic47.<locals>.kernelg      (@rI   rp   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   r   test_basic47  s
    zTestManyStencils.test_basic47c             C   s*   dd }t ddd}| || dS )z22 args, has assignment before use via memory aliasc             S   s"   | j }d|d d d d f< | d S )Nre  )r   r   )T)r   r   r   r   r   r     s    z-TestManyStencils.test_basic48.<locals>.kernelg      (@rI   rp   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic48  s    zTestManyStencils.test_basic48c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z#2 args, standard_indexing on secondc             S   s   | d |d  S )N)r   r   )r   rI   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic49.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic49  s    zTestManyStencils.test_basic49z&dynamic range checking not implementedc             C   sH   dd }t ddd}t ddd}| j|||dditd d	S )
z2 args, standard_indexing OOBc             S   s   | d |d  S )N)r   r   )r      r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic50.<locals>.kernelg      (@rI   rp   r(   r$   )r;   r?  N)rL   r\   r]   rU   rf  )r4   r   r   r$   r   r   r   test_basic50  s    zTestManyStencils.test_basic50c             C   sP   dd }t ddd}t ddd}| j|||dddgittgd	 d
S )z$2 args, standard_indexing, no relidxc             S   s   | d |d  S )N)r   r   )r   r   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic51.<locals>.kernelg      (@rI   rp   r(   r   r$   )r;   r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r$   r   r   r   test_basic51  s    zTestManyStencils.test_basic51c             C   sZ   dd }t ddd}t ddd}t ddd}| j||||dd	id
 dS )z(3 args, standard_indexing on middle arg c             S   s   | d |d  |d  S )N)r   r   )r   r   r   )r   r$   r   r   r   r   r     s    z-TestManyStencils.test_basic52.<locals>.kernelg      (@rI   rp   g      @r   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   r   test_basic52  s
    zTestManyStencils.test_basic52c             C   sZ   dd }t ddd}t ddd}| jttttd}| j|||ddi|d	 d
S )z92 args, standard_indexing on variable that does not existc             S   s   | d |d  S )N)r   r   )r   r   r   )r   r$   r   r   r   r     s    z-TestManyStencils.test_basic53.<locals>.kernelg      (@rI   rp   )r=  r	   rG  r   r(   r   )r;   r?  N)rL   r\   r]   rR  r   rA  rU   )r4   r   r   r$   rC  r   r   r   test_basic53  s    zTestManyStencils.test_basic53c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z)2 args, standard_indexing, index from varc             S   s   d}| d |d|f  S )Nr   )r   r   r   r   )r   r$   rb  r   r   r   r     s    z-TestManyStencils.test_basic54.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic54  s    zTestManyStencils.test_basic54c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z62 args, standard_indexing, index from more complex varc             S   s    d}d| }| d |d|f  S )Nr   r   )r   r   r   r   )r   r$   r  rb  r   r   r   r     s    z-TestManyStencils.test_basic55.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic55  s    zTestManyStencils.test_basic55c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z,2 args, standard_indexing, added complexity c             S   sN   d}d}x |dd d f D ]}||7 }qW d| d }| d |d|f  | S )Nr   r   r   )r   r   r   )r   r$   r  ZaccrQ  rb  r   r   r   r     s    z-TestManyStencils.test_basic56.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic56  s    zTestManyStencils.test_basic56c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z12 args, standard_indexing, split index operation c             S   s   |d }| d |d  S )Nr   )r   r   r   r   )r   r$   r   r   r   r   r     s    z-TestManyStencils.test_basic57.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic57  s    zTestManyStencils.test_basic57c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z?2 args, standard_indexing, split index with broadcast mutation c             S   s   |d d }| d |d  S )Nr   r   )r   r   r   )r   r$   r   r   r   r   r     s    z-TestManyStencils.test_basic58.<locals>.kernelg      (@rI   rp   r(   r$   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic58  s    zTestManyStencils.test_basic58c             C   sP   dd }t ddd}t ddd}d}| j||||ddd	gid
 dS )z>3 args, mix of array, relative and standard indexing and constc             S   s   | d |d  | S )N)r   r   )r   r   r   )r   r$   r   r   r   r   r   &  s    z-TestManyStencils.test_basic59.<locals>.kernelg      (@rI   rp   re  r(   r$   r   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   r   test_basic59$  s
    zTestManyStencils.test_basic59c             C   s^   dd }t ddd}t ddd}d}| jtd}| j||||dd	d
gi|d dS )zP3 args, mix of array, relative and standard indexing,
        tuple pass throughc             S   s   | d |d  |d  S )N)r   r   )r   r   r   r   )r   r$   r   r   r   r   r   0  s    z-TestManyStencils.test_basic60.<locals>.kernelg      (@rI   rp   )re  )rG  r(   r$   r   )r;   r?  N)rL   r\   r]   rR  r   rU   )r4   r   r   r$   r   rC  r   r   r   test_basic60-  s    zTestManyStencils.test_basic60c             C   sH   dd }t ddd}t ddd}| j|||dditd d	S )
z"2 args, standard_indexing on firstc             S   s   | d |d  S )N)r   r   )r   r   r   )r   r$   r   r   r   r   >  s    z-TestManyStencils.test_basic61.<locals>.kernelg      (@rI   rp   r(   r   )r;   r?  N)rL   r\   r]   rU   rA  )r4   r   r   r$   r   r   r   test_basic61<  s    zTestManyStencils.test_basic61c             C   sH   dd }t ddd}t ddd}| j|||dddd	 d
S )z"2 args, standard_indexing and cvalc             S   s   | d |d  S )N)r   r   )r   r   r   )r   r$   r   r   r   r   L  s    z-TestManyStencils.test_basic62.<locals>.kernelg      (@rI   rp   r$   g      $@)r(   r!   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic62J  s    zTestManyStencils.test_basic62c             C   sZ   dd }t ddd}t ddd}| jttttd}| j|||dd	i|d
 dS )zQ2 args, standard_indexing applied to relative, should fail,
        non-const idxc             S   s   | d|d f S )Nr   )r   r   r   )r   r$   r   r   r   r   [  s    z-TestManyStencils.test_basic63.<locals>.kernelg      (@rI   rp   r   )r=  r	   rG  r   r(   r$   )r;   r?  N)rL   r\   r]   rR  r   r   rU   )r4   r   r   r$   rC  r   r   r   test_basic63X  s    zTestManyStencils.test_basic63c             C   s8   dd }t ddd}| j||ddittgd d	S )
z!1 arg that uses standard_indexingc             S   s   | d S )N)r   r   r   )r   r   r   r   r   o  s    z-TestManyStencils.test_basic64.<locals>.kernelg      (@rI   rp   r(   r   )r;   r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic64m  s    zTestManyStencils.test_basic64c             C   s*   dd }t d}| j||ddid dS )zbasic induced neighborhood testc             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   ir      )r   )r   cumulr   r   r   r   r   }  s    z-TestManyStencils.test_basic65.<locals>.kernelg      N@r   ))ir   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic65{  s    
zTestManyStencils.test_basic65c             C   s*   dd }t d}| j||ddid dS )zbasic const neighborhood testc             S   s,   d}xt ddD ]}|| d 7 }qW |d S )Nr   ir   r  )r   )r   r  r   r   r   r   r     s    z-TestManyStencils.test_basic66.<locals>.kernelg      N@r   ))ir   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic66  s    
zTestManyStencils.test_basic66c             C   s2   dd }t ddd}| j||ddid d	S )
z"basic 2d induced neighborhood testc             S   sD   d}x6t ddD ](}x"t ddD ]}|| ||f 7 }q W qW |d S )Nr   r   r   i2   )r   )r   r  r   rd   r   r   r   r     s
    z-TestManyStencils.test_basic67.<locals>.kernelg      i@re     r   ))r   r   )ir   )r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic67  s    zTestManyStencils.test_basic67c             C   s8   dd }t ddd}| j||ddittgd d	S )
z basic 2d induced 1D neighborhoodc             S   s0   d}x"t ddD ]}|| d|f 7 }qW |d S )Nr   ir   r  )r   )r   r  rd   r   r   r   r     s    z.TestManyStencils.test_basic67b.<locals>.kernelg      i@re  r  r   ))ir   )r;   r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic67b  s    zTestManyStencils.test_basic67bc             C   s2   dd }t ddd}| j||ddid d	S )
z0basic 2d one induced, one cost neighborhood testc             S   sD   d}x6t ddD ](}x"t ddD ]}|| |df 7 }q W qW |d S )Nr   r   r   ir  )r   )r   r  r   rd   r   r   r   r     s
    z-TestManyStencils.test_basic68.<locals>.kernelg      i@re  r  r   ))r   r   )ir   )r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic68  s    zTestManyStencils.test_basic68c             C   s2   dd }t ddd}| j||ddid d	S )
z#basic 2d two cost neighborhood testc             S   s@   d}x2t ddD ]$}xt ddD ]}|| d 7 }q W qW |d S )Nr   r   r   i)r   r   r  )r   )r   r  r   rd   r   r   r   r     s
    z-TestManyStencils.test_basic69.<locals>.kernelg      i@re  r  r   ))r   r   )ir   )r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic69  s    zTestManyStencils.test_basic69c             C   s2   dd }t ddd}| j||ddid d	S )
zneighborhood adding complexityc             S   sT   d}d}xBt ddD ]4}|| }x&t ddD ]}|| ||f | 7 }q,W qW |d S )Nr   g      (@r   r   ir  )r   )r   r  zzr   rb  rd   r   r   r   r     s    z-TestManyStencils.test_basic70.<locals>.kernelg      i@re  r  r   ))r   r   )ir   )r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic70  s    zTestManyStencils.test_basic70c             C   s*   dd }t d}| j||ddid dS )zneighborhood, type changec             S   s@   d}x2t ddD ]$}d}|dkr$d}|| | | 7 }qW |d S )Nr   ir   g        iy              ?r  )r   )r   r  r   rQ  r   r   r   r     s    z-TestManyStencils.test_basic71.<locals>.kernelg      N@r   ))ir   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic71  s    
zTestManyStencils.test_basic71c             C   s*   dd }t d}| j||ddid dS )z+neighborhood, narrower range than specifiedc             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   irk  r  )r   )r   r  r   r   r   r   r     s    z-TestManyStencils.test_basic72.<locals>.kernelg      N@r   ))ir   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic72  s    
zTestManyStencils.test_basic72c             C   s*   dd }t d}| j||ddid dS )zneighborhood, +ve rangec             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   ri      r  )r   )r   r  r   r   r   r   r     s    z-TestManyStencils.test_basic73.<locals>.kernelg      N@r   ))ri   re  )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic73  s    
zTestManyStencils.test_basic73c             C   s*   dd }t d}| j||ddid dS )zneighborhood, -ve rangec             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   ir   r  )r   )r   r  r   r   r   r   r     s    z.TestManyStencils.test_basic73b.<locals>.kernelg      N@r   ))ir   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic73b  s    
zTestManyStencils.test_basic73bc             C   s*   dd }t d}| j||ddid dS )z!neighborhood, -ve->+ve range spanc             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   r   r  r  )r   )r   r  r   r   r   r   r   	  s    z-TestManyStencils.test_basic74.<locals>.kernelg      N@r   ))r   re  )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic74  s    
zTestManyStencils.test_basic74c             C   s*   dd }t d}| j||ddid dS )z!neighborhood, -ve->-ve range spanc             S   s,   d}xt ddD ]}|| | 7 }qW |d S )Nr   ir   r  )r   )r   r  r   r   r   r   r   	  s    z-TestManyStencils.test_basic75.<locals>.kernelg      N@r   ))ir"   )r;   N)rL   r\   rU   )r4   r   r   r   r   r   test_basic75		  s    
zTestManyStencils.test_basic75c             C   s2   dd }t ddd}| j||ddid d	S )
zneighborhood, mixed range spanc             S   sT   d}d}xBt ddD ]4}|| }x&t ddD ]}|| ||f | 7 }q,W qW |d S )Nr   g      (@rk  rp   r  )r   )r   r  r  r   rb  rd   r   r   r   r   	  s    z-TestManyStencils.test_basic76.<locals>.kernelg      i@re  r  r   ))rk  r   )rk  rI   )r;   N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic76	  s    zTestManyStencils.test_basic76c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z neighborhood, two args c             S   sP   d}xBt ddD ]4}x.t ddD ] }|| ||f |||f  7 }q W qW |d S )Nr   rk  r   g      "@)r   )r   r$   r  r   rd   r   r   r   r   "	  s
    $z-TestManyStencils.test_basic77.<locals>.kernelg      i@re  r  r   ))rk  r   )rk  r   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic77 	  s    zTestManyStencils.test_basic77c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z. neighborhood, two args, -ve range, -ve range c             S   sP   d}xBt ddD ]4}x.t ddD ] }|| ||f |||f  7 }q W qW |d S )Nr   ir"   ir   g      "@)r   )r   r$   r  r   rd   r   r   r   r   .	  s
    $z-TestManyStencils.test_basic78.<locals>.kernelg     r@r  r  r   ))irk  )ir"   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic78,	  s    zTestManyStencils.test_basic78c             C   sF   dd }t ddd}t ddd}| j|||ddid d	S )
z. neighborhood, two args, -ve range, +ve range c             S   sP   d}xBt ddD ]4}x.t ddD ] }|| ||f |||f  7 }q W qW |d S )Nr   ir"   r   re  g      "@)r   )r   r$   r  r   rd   r   r   r   r   =	  s
    $z.TestManyStencils.test_basic78b.<locals>.kernelg     r@r  r  r   ))irk  )r   	   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic78b;	  s    zTestManyStencils.test_basic78bc             C   s\   dd }t ddd}t dddd}| jttttd}| j|||dd	i|d
 dS )z% neighborhood, two incompatible args c             S   sP   d}xBt ddD ]4}x.t ddD ] }|| ||f |||f  7 }q W qW |d S )Nr   rk  r   g      "@)r   )r   r$   r  r   rd   r   r   r   r   I	  s
    $z-TestManyStencils.test_basic79.<locals>.kernelg      i@re  r  r   )r=  r	   rG  r   r   ))rk  r   )rk  r   )r;   r?  N)rL   r\   r]   rR  r   r   rU   )r4   r   r   r$   rC  r   r   r   test_basic79G	  s    zTestManyStencils.test_basic79c             C   s8   dd }t ddd}d}| j|||ddid	 d
S )z neighborhood, type change c             S   sH   d}x:t ddD ],}x&t ddD ]}|| ||f | 7 }q W qW |d S )Nr   rk  r   g      "@)r   )r   r$   r  r   rd   r   r   r   r   ]	  s
    z-TestManyStencils.test_basic80.<locals>.kernelg      i@re  r  y              (@r   ))rk  r   )rk  r   )r;   N)rL   r\   r]   rU   )r4   r   r   r$   r   r   r   test_basic80[	  s    zTestManyStencils.test_basic80c             C   sT   dd }t ddd}|d  }| jttttd}| j|||dd	i|d
 dS )z1 neighborhood, dimensionally incompatible arrays c             S   sL   d}x>t ddD ]0}x*t ddD ]}|| ||f ||  7 }q W qW |d S )Nr   rk  r   g      "@)r   )r   r$   r  r   rd   r   r   r   r   i	  s
     z-TestManyStencils.test_basic81.<locals>.kernelg      i@re  r  r   )r=  r	   rG  r   r   ))rk  r   )rk  r   )r;   r?  N)	rL   r\   r]   copyrR  r   r   r   rU   )r4   r   r   r$   rC  r   r   r   test_basic81g	  s    zTestManyStencils.test_basic81c             C   s>   dd }t ddd}| }| j|||dddd	 d
S )z% neighborhood, with standard_indexingc             S   sL   d}x>t ddD ]0}x*t ddD ]}|| ||f |d  7 }q W qW |d S )Nr   rk  r   )r   rI   g      "@)r   )r   r$   r  r   rd   r   r   r   r   }	  s
     z-TestManyStencils.test_basic82.<locals>.kernelg      i@re  r  ))rk  r   )rk  r   r$   )r   r(   )r;   N)rL   r\   r]   r  rU   )r4   r   r   r$   r   r   r   test_basic82{	  s    zTestManyStencils.test_basic82c             C   s@   dd }t ddd}| }| j|||dddd	d
 dS )z. neighborhood, with standard_indexing and cvalc             S   sL   d}x>t ddD ]0}x*t ddD ]}|| ||f |d  7 }q W qW |d S )Nr   rk  r   )r   rI   g      "@)r   )r   r$   r  r   rd   r   r   r   r   	  s
     z-TestManyStencils.test_basic83.<locals>.kernelg      i@re  r  ))rk  r   )rk  r   r$   g      ?)r   r(   r!   )r;   N)rL   r\   r]   r  rU   )r4   r   r   r$   r   r   r   test_basic83	  s    zTestManyStencils.test_basic83c             C   s*   dd }t ddd}| || dS )z kernel calls njit c             S   s   | d t | d  S )N)r   r   )r   r   )r+   )r   r   r   r   r   	  s    z-TestManyStencils.test_basic84.<locals>.kernelg      i@re  r  N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic84	  s    zTestManyStencils.test_basic84c             C   s*   dd }t ddd}| || dS )z! kernel calls njit(parallel=True)c             S   s   | d t | d  S )N)r   r   )r   r   )r-   )r   r   r   r   r   	  s    z-TestManyStencils.test_basic85.<locals>.kernelg      i@re  r  N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic85	  s    zTestManyStencils.test_basic85c             C   s8   dd }t ddd}| j||ddittgd dS )	z bad kwarg c             S   s   | d S )N)r   r   r   )r   r   r   r   r   	  s    z-TestManyStencils.test_basic86.<locals>.kernelg      i@re  r  Zbad)r;   r?  N)rL   r\   r]   rU   r   r   )r4   r   r   r   r   r   test_basic86	  s    zTestManyStencils.test_basic86c             C   s*   dd }t ddd}| || dS )z reserved arg name in use c             S   s   | d S )N)r   r   r   )Z__sentinel__r   r   r   r   	  s    z-TestManyStencils.test_basic87.<locals>.kernelg      i@re  r  N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic87	  s    zTestManyStencils.test_basic87c             C   sD   dd }t ddd}| jttttd}| j||di |d d	S )
z use of reserved word c             S   s   || d  S )N)r   r   r   )r   r[   r   r   r   r   	  s    z-TestManyStencils.test_basic88.<locals>.kernelg      (@rI   rp   )r=  r	   rG  r   g      ?)r;   r?  N)rL   r\   r]   rR  r   r   rU   )r4   r   r   rC  r   r   r   test_basic88	  s    zTestManyStencils.test_basic88c             C   s*   dd }t ddd}| || dS )z basic multiple returnc             S   s,   | d dkrdS | d dk r$| d S dS d S )N)r   r   re  g      $@)r   rI   ru  )r   r   g      @r   )r   r   r   r   r   	  s
    z-TestManyStencils.test_basic89.<locals>.kernelg      i@re  r  N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic89	  s    zTestManyStencils.test_basic89c             C   s@   dd }t ddd}| }| j|||dddd	d
 dS )z@ neighborhood, with standard_indexing and cval, multiple returnsc             S   sd   d}x>t ddD ]0}x*t ddD ]}|| ||f |d  7 }q W qW |d }|dkr\|d S |S d S )Nr   rk  r   )r   rI   g      "@g      i@g      ?)r   )r   r$   r  r   rd   Zresr   r   r   r   	  s     z-TestManyStencils.test_basic90.<locals>.kernelg      i@re  r  ))rk  r   )rk  r   r$   g      ?)r   r(   r!   )r;   N)rL   r\   r]   r  rU   )r4   r   r   r$   r   r   r   test_basic90	  s    
zTestManyStencils.test_basic90c             C   s*   dd }t ddd}| || dS )z? Issue #3454, const(int) == const(int) evaluating incorrectly. c             S   s   d}ddkrd}| d | S )Nr   r   )r   r   r   )r   r$   r   r   r   r   	  s    z-TestManyStencils.test_basic91.<locals>.kernelg      i@re  r  N)rL   r\   r]   rU   )r4   r   r   r   r   r   test_basic91	  s    zTestManyStencils.test_basic91c             C   s<   dd }t t dd ddt j}| || dS )z7 Issue #3497, bool return type evaluating incorrectly. c             S   sH   | d | d A | d A | d A | d A | d A | d A | d A | d	 A S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   )r   r   r   r   r   	  s    z-TestManyStencils.test_basic92.<locals>.kernelr  r   rp   ri   N)rL   r  r\   r]   ry  bool_rU   )r4   r   r`   r   r   r   test_basic92	  s    $zTestManyStencils.test_basic92c             C   sD   dd }t t dd ddt j}| j||ddid	 d
S )z7 Issue #3497, bool return type evaluating incorrectly. c             S   sH   | d | d A | d A | d A | d A | d A | d A | d A | d	 A S )
N)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   )r   r   r   r   r   
  s    z-TestManyStencils.test_basic93.<locals>.kernelr  r   rp   ri   r!   T)r;   N)rL   r  r\   r]   ry  r  rU   )r4   r   r`   r   r   r   test_basic93
  s    $zTestManyStencils.test_basic93)nrV   rW   rX   r3   rU   rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r]  r^  r_  r`  ra  rc  rd  rg  rh  ri  rj  rl  rm  rn  rp  rq  rr  rs  rv  rx  rz  r|  r}  r~  unittestskipr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rY   r   r   )r6   r   r>  ,  s    3
					

			
			





		
r>  __main__)r2  )=Z
__future__r   r   r   sysZnumpyrL   r   r  r   r
   r8  
contextlibr   r  r   r>   r   r  r   r	   Znumba.compilerr   r   Znumba.targetsr   Znumba.targets.cpur   Zsupportr   Znumba.errorsr   r   version_infor  platform
startswithZ_windows_py27maxsizeZ_32bitZ_reasonZ_unsupportedZskipIfr   r   r    r#   r%   r'   r)   r*   r+   r-   ZTestCaser.   rZ   r   r=  r>  rV   mainr   r   r   r   <module>   sr   
7   9     D
'         g
