ó
\K]c           @  se   d  Z  d d l m Z d d l Z d d l m Z d d l m Z m	 Z	 d e e	 f d     YZ
 d S(	   s/   
Tests for practical lowering specific errors.
iĸĸĸĸ(   t   print_functionN(   t   njiti   (   t   MemoryLeakMixint   TestCaset   TestLoweringc           B  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C  s>   t  d    } | d  } | j d  } |  j | |  d S(   s  Test issues with zero-filling of refct'ed variables inside loops.

        Before the fix, the in-loop variables are always zero-filled at their
        definition location. As a result, their state from the previous
        iteration is erased. No decref is applied. To fix this, the
        zero-filling must only happen once after the alloca at the function
        entry block. The loop variables are technically defined once per
        function (one alloca per definition per function), but semantically
        defined once per assignment. Semantically, their lifetime stop only
        when the variable is re-assigned or when the function ends.
        c         S  se   t  j d  } xO t |   D]A } | d k r@ t  j d  } n  | d k r | | d 7} q q W| S(   Ni   i    i   (   t   npt   zerost   ranget   ones(   t   Nt   sum_vect   nt   vec(    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt   udt   s    i   N(   R   t   py_funct   assertPreciseEqual(   t   selfR   t   gott   expect(    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt   test_issue4156_loop_vars_leak   s    c         C  s>   t  d    } | d  } | j d  } |  j | |  d S(   sQ   Variant of test_issue4156_loop_vars_leak.

        Adding an outer loop.
        c         S  s   t  j d  } xp t |   D]b } xY t |   D]K } | | } | d k r] t  j d  } n  | d k r/ | | d 7} q/ q/ Wq W| S(   Ni   i    i   (   R   R   R   R   (   R	   R
   t   xt   yR   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyR   0   s    
i   N(   R   R   R   (   R   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt&   test_issue4156_loop_vars_leak_variant1+   s    c         C  s>   t  d    } | d  } | j d  } |  j | |  d S(   sU   Variant of test_issue4156_loop_vars_leak.

        Adding deeper outer loop.
        c         S  sĄ   t  j d  } x t |   D]} } xt t |   D]f } x] t |   D]O } | | | } | d k rt t  j d  } n  | d k rB | | d 7} qB qB Wq/ Wq W| S(   Ni   i    i   (   R   R   R   R   (   R	   R
   t   zR   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyR   G   s    i   N(   R   R   R   (   R   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt&   test_issue4156_loop_vars_leak_variant2B   s    c         C  s>   t  d    } | d  } | j d  } |  j | |  d S(   s_   Variant of test_issue4156_loop_vars_leak.

        Adding inner loop around allocation
        c         S  s   t  j d  } x t |   D]y } xp t |   D]b } | | } | d k rt x& t |   D] } t  j |  } qX Wn  | d k r/ | | d 7} q/ q/ Wq W| S(   Ni   i    (   R   R   R   R   (   R	   R
   R   R   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyR   _   s    
i   N(   R   R   R   (   R   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt&   test_issue4156_loop_vars_leak_variant3Z   s    c         C  s>   t  d    } | d  } | j d  } |  j | |  d S(   s]   Variant of test_issue4156_loop_vars_leak.

        Interleaves loops and allocations
        c         S  sl   d } x_ t  |   D]Q } t j d  } x# t  |   D] } t j d  } q5 W| | d | d 7} q W| S(   Ni    i   (   R   R   R   (   R	   R
   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyR   w   s    i   N(   R   R   R   (   R   R   R   R   (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt&   test_issue4156_loop_vars_leak_variant4r   s    (   t   __name__t
   __module__R   R   R   R   R   (    (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyR      s
   				(   t   __doc__t
   __future__R    t   numpyR   t   numbaR   t   supportR   R   R   (    (    (    sI   lib/python2.7/site-packages/numba/tests/test_practical_lowering_issues.pyt   <module>   s
   