σ
\K]c           @` sώ   d  d l  m Z m Z m Z d  d l Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z d d l m Z d d l m Z m Z d d l m Z m Z d d	 l m Z d d
 l m Z d   Z d e f d     YZ d e j f d     YZ e j j e  d S(   i    (   t   absolute_importt   print_functiont   divisionNi   (   t   jitt   typeoft   utilst   typest   numpy_supportt   sigutils(   t   npydecl(   t   AbstractTemplatet	   signaturei   (   t	   _internalt   ufuncbuilder(   t
   Dispatcher(   t   array_analysisc         ` sK   d d l  m } d | j f    f d     Y    j  j j 7_   S(   Ni   (   t   npyimplt   DUFuncKernelc           ` s,   e  Z d  Z  Z   f d   Z d   Z RS(   sΙ   
        npyimpl._Kernel subclass responsible for lowering a DUFunc kernel
        (element-wise function) inside a broadcast loop (which is
        generated by npyimpl.numpy_ufunc_kernel()).
        c         ` sA   t    |   j | | |  |  j j | j  \ |  _ |  _ d  S(   N(   t   supert   __init__t   dufunct   find_ewise_functiont   argst	   inner_sigt   cres(   t   selft   contextt   buildert	   outer_sig(   R   (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR      s    	c         W` s9  |  j  } |  j } g  t | | j | j  D]$ \ } } } |  j | | |  ^ q+ } |  j j r |  j j j	 t
 j t
 j g t | j   } n |  j j j	 | j | j  } |  j j j j }	 |	 j | d |  j j j }
 |
 j j d  |  j j j |  j |
 | j | j |  \ } } |  j | | j | j  S(   Nt   namet   alwaysinline(   R   R   t   zipR   t   castR   t
   objectmodeR   t	   call_convt   get_function_typeR   t   pyobjectt   lent   return_typeR   t   blockt   functiont   modulet   get_or_insert_functiont   fndesct   llvm_func_namet
   attributest   addt   call_function(   R   R   t   isigt   osigt   valt   intyt   outtyt	   cast_argst	   func_typeR)   t   entry_pointt   _t   res(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   generate   s"    		@%(   t   __name__t
   __module__t   __doc__R   R   R:   (    (   R   t   _dufunc(    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR      s   (   t   targetsR   t   _KernelR;   t   ufunc(   R>   R   (    (   R   R>   s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   make_dufunc_kernel   s    ""t   DUFuncLowererc           B` s    e  Z d  Z d   Z d   Z RS(   sH   Callable class responsible for lowering calls to a specific DUFunc.
    c         C` s   t  |  |  _ g  |  _ d  S(   N(   RB   t   kernelt   libs(   R   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR   8   s    c         C` sP   d d l  m } t |  |  j j j j k } | j | | | | |  j d | S(   Ni   (   R   t   explicit_output(   R?   R   R%   RD   R   RA   t   nint   numpy_ufunc_kernel(   R   R   R   t   sigR   R   RF   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   __call__<   s
    	(   R;   R<   R=   R   RJ   (    (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRC   5   s   	t   DUFuncc           B` sΰ   e  Z d  Z e d  Z d e i  d  Z d   Z e	 d    Z
 e	 d    Z e	 d	    Z e	 d
    Z e	 d    Z e	 d    Z d   Z d   Z d   Z d d  Z d d  Z d   Z d   Z d d  Z RS(   sΉ   
    Dynamic universal function (DUFunc) intended to act like a normal
    Numpy ufunc, but capable of call-time (just-in-time) compilation
    of fast loops specialized to inputs.
    t   identityt
   _keepaliveRG   t   noutc         C` sΆ   t  | t  r | j } n  | j   |  _ i  } t j |  | d <t d d d |  |  } t t	 |   j
 | |  |  j   t |   |  _ |  j   | j |  _ | j |  _ d  S(   NRL   t   targett   npyufunct   cache(   t
   isinstanceR   t   py_funct   copyt   targetoptionsR   t   parse_identityR   R   RK   R   t   _install_typeRC   t	   _lower_met   _install_cgR;   R=   (   R   RS   RL   RQ   RU   t   kwst
   dispatcher(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR   N   s    

c         C` s   |  S(   sK   
        For compatibility with the various *UFuncBuilder classes.
        (    (   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   build_ufunc_   s    c         C` s
   |  j  j S(   N(   RA   RG   (   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRG   e   s    c         C` s
   |  j  j S(   N(   RA   RN   (   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRN   i   s    c         C` s
   |  j  j S(   N(   RA   t   nargs(   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR]   m   s    c         C` s
   |  j  j S(   N(   RA   t   ntypes(   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR^   q   s    c         C` s
   |  j  j S(   N(   RA   R   (   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR   u   s    c         C` s
   |  j  j S(   N(   RA   RL   (   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRL   y   s    c         C` s+   t  |  j j  d k s t  t |  _ d S(   sI   
        Disable the compilation of new signatures at call time.
        i    N(   R%   t   _dispatchert	   overloadst   AssertionErrort   Truet   _frozen(   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   disable_compile}   s    c         C` s%   t  j |  \ } } |  j | |  S(   s=   
        Compile the DUFunc for the given signature.
        (   R   t   normalize_signaturet   _compile_for_argtys(   R   RI   R   R&   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR.      s    c   	      O` s@  |  j  j } | rr d | k r= | j d  } | | f 7} n  | rr t d d j d   t |  D    qr n  t |  } | | k s¦ | | |  j  j k s¦ t  | s³ t  g  } xq | |  D]e } t	 j
 |  rς | j t	 j |   qΔ t |  } t | t j  r| j } n  | j |  qΔ W|  j t |   S(   Nt   outs)   unexpected keyword arguments to ufunc: %ss   , c         s` s   |  ] } t  |  Vq d  S(   N(   t   repr(   t   .0t   k(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pys	   <genexpr>   s    (   RA   RG   t   popt	   TypeErrort   joint   sortedR%   RN   Ra   R   t   is_arrayscalart   appendt   map_arrayscalar_typeR   RR   R   t   Arrayt   dtypeRf   t   tuple(	   R   R   RZ   RG   Rg   t   args_lent   argtyst   argt   argty(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   _compile_for_args   s(    )(c   	      C` sψ   |  j  r t d |  f   n  t | t  s4 t  | d k rI | } n | |   } t j |  j |  j	 |  \ } } } t j
 | | |  } t j | |  \ } } } |  j t j |  |  |  j j | | j | f  |  j j j | j  | S(   s/  
        Given a tuple of argument types (these should be the array
        dtypes, and not the array types themselves), compile the
        element-wise function for those inputs, generate a UFunc loop
        wrapper, and register the loop with the Numpy ufunc object for
        this DUFunc.
        s   compilation disabled for %sN(   Rc   t   RuntimeErrorRR   Rt   Ra   t   NoneR   t   _compile_element_wise_functionR_   RU   t   _finalize_ufunc_signaturet!   _build_element_wise_ufunc_wrappert	   _add_loopR   t   longintRM   Rp   t   libraryRX   RE   (	   R   Rv   R&   RI   R   t
   actual_sigt	   dtypenumst   ptrt   env(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRf   ¨   s     		c         C` sc   | d k r |  j j j } n  t d |  j j t f t d |  d |  j	   } | j
 |  |  d S(   s*  Constructs and installs a typing class for a DUFunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        t   DUFuncTyping_t   keyt   genericN(   R{   R_   t   targetdescrt   typing_contextt   typeRA   R;   R
   t   dictt   _type_met   insert_user_function(   R   t	   typingctxt   _ty_cls(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRW   Β   s    c         C` s   |  j  rN t j |  |  } | d k r+ d St | j | j  t |   } n  x9 |  j j	 j
   D]% \ } } | j | k ra | | f Sqa Wd S(   s  
        Given a tuple of element-wise argument types, find a matching
        signature in the dispatcher.

        Return a 2-tuple containing the matching signature, and
        compilation result.  Will return two None's if no matching
        signature was found.
        N(   NN(   NN(   Rc   R   t   ufunc_find_matching_loopR{   Rt   t   inputst   outputsR%   R_   R`   t   itemsR   (   R   t   ewise_typest   loopRI   R   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR   Π   s    		#c         C` s~  | s t   |  j } t j j | | |  } | \ } } } } t |  }	 |	 d k rr t | t |    }
 n t |  }
 |  j |
  \ } } | d k rψ |  j	 rΑ t
 d |  | f   n  |  j |
  |  j |
  \ } } | d k	 sψ t   n  |	 d k rt |  } nT | j d k r[| d k rLt j | j | |  g } qg| j g } n t d   | j |  t |   S(   sμ   
        Implement AbstractTemplate.generic() for the typing class
        built by DUFunc._install_type().

        Return the call-site signature after either validating the
        element-wise signature or compiling for it.
        i    s   cannot call %s with types %si   s   typing gufuncs (nout > 1)N(   Ra   RA   R	   t   Numpy_rules_ufunct   _handle_inputsR%   Rt   R   R{   Rc   Rl   Rf   t   listRN   R   Rr   R&   t   NotImplementedErrort   extendR   (   R   Rv   t   kwtysRA   t   _handle_inputs_resultt
   base_typest   explicit_outputst   ndimst   layoutt   explicit_output_countR   RI   R   t   outtys(    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyR   δ   s4    			c         C` s   | d k r |  j j j } n  t j } t j } | f |  j j | f |  j j	 } | f |  j j } | j
 g  | | f D] } |  j |  | f ^ qz  d S(   s-  
        Install an implementation function for a DUFunc object in the
        given target context.  If no target context is given, then
        _install_cg() installs into the target context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        N(   R{   R_   R   t   target_contextR   t   AnyRr   RA   RG   RN   t   insert_func_defnRX   (   R   t	   targetctxt   _anyt   _arrt   sig0t   sig1RI   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRY     s    		$(   RL   RM   RG   RN   N(   R;   R<   R=   t   sett   _DUFunc__base_kwargsR{   t   FalseR   R\   t   propertyRG   RN   R]   R^   R   RL   Rd   R.   Ry   Rf   RW   R   R   RY   (    (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyRK   D   s$   						((   t
   __future__R    R   R   t   numpyt   npt    R   R   R   R   R   R   t   typingR	   t   typing.templatesR
   R   R   R   R[   R   R   RB   t   objectRC   t   _DUFuncRK   t	   MAP_TYPESRp   (    (    (    s4   lib/python2.7/site-packages/numba/npyufunc/dufunc.pyt   <module>   s   .	)Ϊ