
\K]c           @` s>  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z m	 Z	 d d l
 m Z m Z d d l m Z m Z e j d. k Z d	 e f d
     YZ d   Z d d  Z d   Z d   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d e f d     YZ d   Z d e f d     YZ  d e  f d      YZ! d! e! f d"     YZ" e! d#  Z# d$   Z$ d%   Z% d& e f d'     YZ& d( e f d)     YZ' d* e f d+     YZ( d, e( f d-     YZ) e'   Z* e* j+ Z, e* j- Z. e* j/ Z0 d S(/   s   
Define typing templates
i    (   t   print_functiont   divisiont   absolute_importN(   t
   MethodTypet   FunctionTypei   (   t   typest   utils(   t   TypingErrort   InternalErrori   t	   Signaturec           B` s   e  Z d  Z d Z d d  Z d   Z d   Z d   Z d	   Z	 d
   Z
 d   Z d   Z e d    Z d   Z d   Z RS(   se   
    The signature of a function call or operation, i.e. its argument types
    and return type.
    t   return_typet   argst   recvrt   pysigc         C` sF   t  | t  r t |  } n  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t
   isinstancet   listt   tupleR
   R   R   R   (   t   selfR
   R   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __init__   s    			c      	   K` sD   t  d |  j d |  j d |  j d |  j  } | j |  t |   S(   sn   Copy and replace the given attributes provided as keyword arguments.
        Returns an updated copy.
        R
   R   R   R   (   t   dictR
   R   R   R   t   updateR	   (   R   t   kwargst   curstate(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   replace"   s    		c         C` s   |  j  |  j |  j |  j f S(   s.   
        Needed because of __slots__.
        (   R
   R   R   R   (   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __getstate__-   s    c         C` s"   | \ |  _  |  _ |  _ |  _ d S(   s.   
        Needed because of __slots__.
        N(   R
   R   R   R   (   R   t   state(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __setstate__3   s    c         C` s   t  |  j |  j f  S(   N(   t   hashR   R
   (   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __hash__9   s    c         C` sY   t  | t  rU |  j | j k oT |  j | j k oT |  j | j k oT |  j | j k Sd  S(   N(   R   R	   R   R
   R   R   (   R   t   other(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __eq__<   s
    c         C` s   |  | k S(   N(    (   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __ne__C   s    c         C` s   d |  j  |  j f S(   Ns   %s -> %s(   R   R
   (   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   __repr__F   s    c         C` s   |  j  d k	 S(   sa   
        Whether this signature represents a bound method or a regular
        function.
        N(   R   t   None(   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt	   is_methodI   s    c         C` sz   |  j  d k	 r |  St |  j d |  j d |  j d } t |  j j j    d } t	 j
 d | d |  j j  | _ | S(   sE   
        Convert this signature to a bound method signature.
        R   i    i   t
   parameterst   return_annotationN(   R   R!   t	   signatureR
   R   R   R   R#   t   valuesR   t   pySignatureR$   (   R   t   sigt   params(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt	   as_methodQ   s    	c         C` s6   |  j  d k r |  St |  j |  j  f |  j  } | S(   sI   
        Convert this signature to a regular function signature.
        N(   R   R!   R%   R
   R   (   R   R(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   as_functionb   s    (   R
   R   R   R   N(   t   __name__t
   __module__t   __doc__t	   __slots__R!   R   R   R   R   R   R   R   R    t   propertyR"   R*   R+   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR	      s   								c         C` s4   t  f } t d | d t |   } t |  | |  S(   Nt   keyt   cases(   t   ConcreteTemplateR   R   t   type(   t   nameR1   t
   signaturest   baseclassest   gvars(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   make_concrete_templatel   s    	c         ` sP     f d   } d |  f } t  f } t d |  d | d |  } t | | |  S(   sK   
    Create a callable template with the given key and typer function.
    c         ` s     S(   N(    (   R   (   t   typer(    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   genericv   s    s   %s_CallableTemplateR1   R;   R   (   t   CallableTemplateR   R4   (   R1   R:   R   R;   R5   t   basest
   class_dict(    (   R:   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   make_callable_templater   s
    	c         O` s2   | j  d d   } | s t  t |  | d | S(   NR   (   t   popR!   t   AssertionErrorR	   (   R
   R   t   kwsR   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR%      s    c         ` s  |  j  } g  } x< | j   D]. \ } }	 |	 j |	 j k r | j |  q q W| rh | t |   }
 n | }
 | j   } | r x5 t |  D]$ \ } } | t |  | | | <q Wn  |  j |
 |     x t |  j  j	    D] \ } } | j
 } | j } | j | j k r;| | |   j j | d     j | <q |   j k rm| | |   j |    j | <q | | j k	 st  | | | |    j | <q Wt   f d   |  j  j	   D  } | S(   s  
    Given the signature *pysig*, explicit *args* and *kws*, resolve
    omitted arguments and keyword arguments. A tuple of positional
    arguments is returned.
    Various handlers allow to process arguments:
    - normal_handler(index, param, value) is called for normal arguments
    - default_handler(index, param, default) is called for omitted arguments
    - stararg_handler(index, param, values) is called for a "*args" argument
    c         3` s   |  ] }   j  | j Vq d  S(   N(   t	   argumentsR5   (   t   .0t   param(   t   ba(    s5   lib/python2.7/site-packages/numba/typing/templates.pys	   <genexpr>   s   (    (   R#   t   itemst   kindt   KEYWORD_ONLYt   appendt   lent   copyt	   enumeratet   bindR&   R5   t   defaultt   VAR_POSITIONALRC   t   gett   emptyRA   R   (   R   R   RB   t   normal_handlert   default_handlert   stararg_handlerR)   t   kwonlyR5   t   pt	   bind_argst   bind_kwst   idxt   nt   iRE   RO   (    (   RF   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   fold_arguments   s4    	"			"#t   FunctionTemplatec           B` s/   e  Z e Z e Z d    Z d   Z d   Z RS(   c         C` s   | |  _  d  S(   N(   t   context(   R   R_   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR      s    c         C` s?   i |  j  d 6|  j d 6} |  j j |  j | | | |  } | S(   Nt   unsafe_castingt   exact_match_required(   R`   Ra   R_   t   resolve_overloadR1   (   R   R2   R   RB   t   optionst   selected(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   _select   s    
	c         C` sC   t  |   j } t | t  r? | j d k s3 t  | j } n  | S(   sy   
        Return the key for looking up the implementation for the given
        signature on the target context.
        N(   R4   R1   R   R   t   im_selfR!   RA   t   im_func(   R   R(   R1   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   get_impl_key   s
    (	   R,   R-   t   TrueR`   t   FalseRa   R   Re   Rh   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR^      s
   			t   AbstractTemplatec           B` s   e  Z d  Z d   Z RS(   s   
    Defines method ``generic(self, args, kws)`` which compute a possible
    signature base on input types.  The signature does not have to match the
    input types. It is compared against the input types afterwards.
    c         C` s   t  |  d  } | | |  } | d  k	 r] t | t  s] t d j | t |     q] n  | r t d   | D  r d   } t t	 | |   } | s t  | | |  } n  | S(   NR;   s9   generic() must return a Signature or None. {} returned {}c         s` s!   |  ] } t  | t j  Vq d  S(   N(   R   R   t   Optional(   RD   t   x(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pys	   <genexpr>   s    c         S` s!   t  |  t j  r |  j S|  Sd  S(   N(   R   R   Rl   R4   (   Rm   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt
   unpack_opt   s    (
   t   getattrR!   R   R	   RA   t   formatR4   t   anyR   t   map(   R   R   RB   R;   R(   Rn   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   apply   s    	(   R,   R-   R.   Rs   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRk      s   R<   c           B` s   e  Z d  Z d Z d   Z RS(   sy  
    Base class for a template defining a ``generic(self)`` method
    returning a callable to be called with the actual ``*args`` and
    ``**kwargs`` representing the call signature.  The callable has
    to return a return type, a full signature, or None.  The signature
    does not have to match the input types. It is compared against the
    input types afterwards.
    c         C` s  t  |  d  } |   } | | |   } | d  k r t d   | D  ry d   } t t | |   } | | |   } n  | d  k r d  Sn  y | j } Wn  t k
 r t j |  } n X| j	 | |   } | j
 r t d   n  t | t  s2t | t j  st d | f   n  t | | j  } n  |  j d  k	 rP|  j | _ n  t | j  t | j  k  rt | j j    t | j   }	 | j d |	  } n  | | _ | g }
 |  j |
 | j | j
  S(   NR;   c         s` s!   |  ] } t  | t j  Vq d  S(   N(   R   R   Rl   (   RD   Rm   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pys	   <genexpr>  s    c         S` s!   t  |  t j  r |  j S|  Sd  S(   N(   R   R   Rl   R4   (   Rm   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRn     s    s   unsupported call signatures1   invalid return type for callable template: got %rR#   (   Ro   R!   Rq   R   Rr   R   t   AttributeErrorR   t   pysignatureRN   R   R   R   R	   R   t   Typet	   TypeErrorR%   R   R   RK   R#   R&   R   Re   (   R   R   RB   R;   R:   R(   Rn   R   t   boundR#   R2   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRs     s<    			"		N(   R,   R-   R.   R!   R   Rs   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR<      s   R3   c           B` s   e  Z d  Z d   Z RS(   sg   
    Defines attributes "cases" as a list of signature to match against the
    given input types.
    c         C` s"   t  |  d  } |  j | | |  S(   NR2   (   Ro   Re   (   R   R   RB   R2   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRs   :  s    (   R,   R-   R.   Rs   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR3   4  s   t   _OverloadFunctionTemplatec           B` s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s;   
    A base class of templates for overload functions.
    c         C` s]  t  j |  } t  j |  } d   } | |  \ } } } | |  \ }	 }
 } d } | | | f } d } | } |	 } | r | s d | | f } t |   q ny | r |	 |	 j |   } y | | j | d  d  } Wq t k
 rd } | | | | d f } t |   q Xn  t r2d   } n	 d	   } | | k rsd
 | | | |  f } t | |   n  g  | D] } | j ^ qz} g  |
 D] } | j ^ q} | | k rd } | | | | | |
  f } t |   n  g  | D] } | j ^ qg  |
 D] } | j ^ q	k } | sYd } | | | | | |
  f } t |   n  d  S(   Nc         S` s   g  } g  } d  } x |  j j   D] } | j t j j k r | j |  | j t j j	 k rh | } q | j t j j
 k r d } t | |   q q" | j |  q" W| | | f S(   NsX   The use of VAR_KEYWORD (e.g. **kwargs) is unsupported. (offending argument name is '%s')(   R!   R#   R&   RO   R   t   pyParameterRR   RJ   RH   RP   t   VAR_KEYWORDR   (   R(   RB   R   t   pos_argRm   t   msg(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   get_args_kwargsV  s    	s9   Typing signature:         %s
Implementation signature: %ss.   Typing and implementation arguments differ in s   VAR_POSITIONAL (e.g. *args) argument kind (offending argument name is '%s') found in the typing function signature, but is not in the implementing function signature.
%sii   s)   argument names.
%s
First difference: '%s'c         S` s   t  |   t  |  A} d | S(   Ns   Difference: %s(   t   set(   t   typingt   implementingt   diff(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   gen_diff  s    c         S` s   d  S(   N(    (   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s    s   argument names.
%s
%ss   keyword argument names.
%s
%ss&   keyword argument default values.
%s
%s(   R   Ru   R   t   indext
   ValueErrort   _IS_PY3R5   RO   (   R   t   typing_funct	   impl_funct
   typing_sigt   impl_sigR~   t   ty_argst   ty_kwst   ty_post   im_argst   im_kwst   im_post   sig_fmtt   sig_strt
   err_prefixt   at   bR}   t   specializedR   Rm   t   tyt   imt   same(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   _validate_sigsD  sP    		8c         C` sl   |  j  | |  \ } } | d k r( d St j |  } | j |  j | |  } | j |  |  j | j <| S(   sv   
        Type the overloaded function by compiling the appropriate
        implementation for the given args.
        N(	   t	   _get_implR!   R   t
   Dispatchert   get_call_typeR_   t   get_overloadt   _compiled_overloadsR   (   R   R   RB   t   dispt	   disp_typeR(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR;     s    c         C` st   |  j  t |  t | j    f } y |  j | \ } } Wn, t k
 ri |  j | | |  \ } } n X| | f S(   s   Get implementation given the argument types.

        Returning a Dispatcher object.  The Dispatcher object is cached
        internally in `self._impl_cache`.
        (   R_   R   RG   t   _impl_cachet   KeyErrort   _build_impl(   R   R   RB   t	   cache_keyt   impl(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s    $c         C` s  d d l  m } |  j | |   } | d k r? d |  j | <d St | t  rl | \ } } | j } d } n | } t | t  s d } t	 | j
 |    n  |  j r |  j |  j |  n  | d t |  j  }	 |	 |  }
 | d k	 r|
 | f |  j | <n  |
 | f S(   sN  Build and cache the implementation.

        Given the positional (`args`) and keyword arguments (`kws`), obtains
        the `overload` implementation and wrap it in a Dispatcher object.
        The expected argument types are returned for use by type-inference.
        The expected argument types are only different from the given argument
        types if there is an imprecise type in the given argument types.

        Parameters
        ----------
        cache_key : hashable
            The key used for caching the implementation.
        args : Tuple[Type]
            Types of positional argument.
        kws : Dict[Type]
            Types of keyword argument.

        Returns
        -------
        disp, args :
            On success, returns `(Dispatcher, Tuple[Type])`.
            On failure, returns `(None, None)`.

        i    (   t   jitsN   Implementator function returned by `@overload` has an unexpected type.  Got {}t   nopythonN(   NN(   NN(   t   numbaR   t   _overload_funcR!   R   R   R   R   R   RA   Rp   t   _strictR   Ri   t   _jit_options(   R   R   R   RB   R   t
   ovf_resultR(   t   pyfuncR}   t   jitdecorR   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s(    			c         C` s   |  j  | j S(   sy   
        Return the key for looking up the implementation for the given
        signature on the target context.
        (   R   R   (   R   R(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRh     s    (   R,   R-   R.   R   R;   R   R   Rh   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRy   ?  s   	_			;c         C` sw   t  |  d t |    } d | f } t } t d |  d t |  d i  d i  d | d |  } t |  | | f |  S(	   s   
    Make a template class for function *func* overloaded by *overload_func*.
    Compiler options are passed as a dictionary to *jit_options*.
    R,   s   OverloadTemplate_%sR1   R   R   R   R   R   (   Ro   t   strRy   R   t   staticmethodR4   (   t   funct   overload_funct   jit_optionst   strictt	   func_nameR5   t   baset   dct(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   make_overload_template  s    	t   _IntrinsicTemplatec           B` s    e  Z d  Z d   Z d   Z RS(   s<   
    A base class of templates for intrinsic definition
    c   
      C` s   d d l  m } |  j | t | j    f } y |  j | SWn t k
 r |  j |  j | |  } | d k ru d S| \ } } t	 j
 |  j  } t | j j    d }	 | j d |	  | _ | |  j | <| |  j | j <| | | j  |  | SXd S(   s6   
        Type the intrinsic by the arguments.
        i    (   t   lower_builtinNi   R#   (   t   numba.targets.imputilsR   R_   R   RG   R   R   t   _definition_funcR!   R   Ru   R   R#   R&   R   R   t   _overload_cacheR   (
   R   R   RB   R   R   t   resultR(   t   impR   R#   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR;     s     c         C` s   |  j  | j S(   sy   
        Return the key for looking up the implementation for the given
        signature on the target context.
        (   R   R   (   R   R(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyRh   -  s    (   R,   R-   R.   R;   Rh   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s   	c      	   C` sP   t  } d | } t d |  d t |  d i  d i   } t |  | | f |  S(   s   
    Make a template class for a intrinsic handle *handle* defined by the
    function *defn*.  The *name* is used for naming the new template class.
    s   _IntrinsicTemplate_%sR1   R   R   R   (   R   R   R   R4   (   t   handlet   defnR5   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   make_intrinsic_template5  s
    
t   AttributeTemplatec           B` sM   e  Z e Z d    Z d   Z e d    Z e d    Z d   Z	 e
 Z RS(   c         C` s   |  j    | |  _ d  S(   N(   t   _lazy_class_initR_   (   R   R_   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   D  s    
c         C` s   |  j  | |  S(   N(   t   _resolve(   R   t   valuet   attr(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   resolveH  s    c         C` s#   |  j  s |  j   t |  _  n  d  S(   N(   t   _initializedt   do_class_initRi   (   t   cls(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   K  s    	
c         C` s   d S(   s   
        Class-wide initialization.  Can be overriden by subclasses to
        register permanent typing or target hooks.
        N(    (   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   Q  t    c         C` s   t  |  d | d   } | d  k rs |  j } | t k rc t | t j  r\ |  j j | |  Sd  Sq} | | |  Sn
 | |  Sd  S(   Ns
   resolve_%s(	   Ro   R!   t   generic_resolvet   NotImplementedR   R   t   ModuleR_   t   resolve_module_constants(   R   R   R   t   fn(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   X  s    	(   R,   R-   Rj   R   R   R   t   classmethodR   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   A  s   			t   _OverloadAttributeTemplatec           B` sG   e  Z d  Z d   Z e d    Z e d    Z d   Z d   Z RS(   sF   
    A base class of templates for @overload_attribute functions.
    c         C` s#   t  t |   j |  | |  _ d  S(   N(   t   superR   R   R_   (   R   R_   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   n  s    c         ` sA   d d l  m }  j   |  j       f d    } d S(   s4   
        Register attribute implementation.
        i    (   t   lower_getattrc         ` s   | f } i  } |  j  }  j | |   | |  \ } } t j |  } | j | | |  }	 |  j | |	  }
 |
 | | f  S(   N(   t   typing_contextt   _get_dispatcherR   R   R   t   get_function(   R_   t   buildert   typR   t   sig_argst   sig_kwsR   R   R   R(   t   call(   R   R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   getattr_implz  s    		!N(   R   R   t   _attrR1   (   R   R   R   (    (   R   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyR   r  s    	c         C` s   | | | t  |  t  | j    f } y |  j | } Wn t k
 r |  j | |   } | d k rw d |  j | <d St | t   r | \ }	 } |	 j } d } n  d d l m	 }
 |
 d t
  |  } |  j | <n X| | f S(   sp   
        Get the compiled dispatcher implementing the attribute for
        the given formal signature.
        i    (   R   R   N(   NN(   R   RG   R   R   R   R!   R   R   R   R   Ri   (   R   R_   R   R   R   R   R   R   R   R(   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s    '		$c         C` s_   |  j  |  j | | | |  \ } } | d k r4 d St j |  } | j |  j | |  } | S(   s\   
        Compute the actual implementation sig for the given formal argument types.
        N(   R   R_   R!   R   R   R   (   R   R   R   R   R   R   R   R(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   _resolve_impl_sig  s    $c         C` s5   |  j  | k r d  S|  j | | | f i   } | j S(   N(   R   R!   R   R
   (   R   R   R   R(   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s    (	   R,   R-   R.   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   i  s   		t   _OverloadMethodTemplatec           B` s&   e  Z d  Z e d    Z d   Z RS(   sC   
    A base class of templates for @overload_method functions.
    c         ` sY   d d l  m }  j   |  j   f  j t j t j      f d    } d S(   s9   
        Register generic method implementation.
        i    (   R   c   
      ` s   | j  d } |  j }  j | |   | j  i   \ } } t j |  } | j | | j  i   } |  j | |  }	 |  j t |	 d d   |	 | |  S(   Ni    t   libs(    (	   R   R   R   R   R   R   R   t   add_linking_libsRo   (
   R_   R   R(   R   R   R   R   R   R   R   (   R   R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   method_impl  s    	$N(   R   R   R   R1   R   t   VarArgt   Any(   R   R   R   (    (   R   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s    	c         ` s]    j    k r d  St   j  s+ t  d t f     f d     Y} t j |   S(   Nt   MethodTemplatec           ` s,   e  Z  j   f Z     f d    Z RS(   c         ` sE    f t  |  }  j    | |  } | d  k	 rA | j   Sd  S(   N(   R   R   R!   R*   (   t   _R   RB   R(   (   R   R   R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR;     s    (   R,   R-   R1   R;   (    (   R   R   R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s   (   R   R!   R   R1   RA   Rk   R   t   BoundFunction(   R   R   R   R   (    (   R   R   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s
    "	(   R,   R-   R.   R   R   R   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s   c      
   C` sz   t  |  t j  s* t |  t j  s* t  d |  | f } t d |  d | d i  d t |   } t |  | | f |  S(   s`   
    Make a template class for attribute *attr* of *typ* overloaded by
    *overload_func*.
    s   OverloadTemplate_%s_%sR1   R   R   R   (   R   R   Rv   t
   issubclassRA   R   R   R4   (   R   R   R   R   R5   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt    make_overload_attribute_template  s
    *c         C` s   t  |  | | d t S(   s]   
    Make a template class for method *attr* of *typ* overloaded by
    *overload_func*.
    R   (   R   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   make_overload_method_template  s    c         ` s     f d   } | S(   sq  
    Wrap an AttributeTemplate resolve_* method to allow it to
    resolve an instance method's signature rather than a instance attribute.
    The wrapped method must return the resolved method's signature
    according to the given self type, args, and keywords.

    It is used thusly:

        class ComplexAttributes(AttributeTemplate):
            @bound_function("complex.conjugate")
            def resolve_conjugate(self, ty, args, kwds):
                return ty

    *template_key* (e.g. "complex.conjugate" above) will be used by the
    target to look up the method's implementation, as a regular function.
    c         ` s%   t  j       f d    } | S(   Nc         ` s5   d t  f      f d     Y} t j |   S(   NR   c           ` s#   e  Z  Z     f d    Z RS(   c         ` s@       | |  } | d  k	 r< | j d  k r<  | _ n  | S(   N(   R!   R   (   R   R   RB   R(   (   t   method_resolverR   R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR;     s    (   R,   R-   R1   R;   (    (   R   R   t   template_keyR   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s   (   Rk   R   R   (   R   R   R   (   R   R   (   R   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   attribute_resolver
  s    %	(   t	   functoolst   wraps(   R   R   (   R   (   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   wrapper	  s    !(    (   R   R   (    (   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   bound_function  s    t   MacroTemplatec           B` s   e  Z RS(    (   R,   R-   (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR     s   t   Registryc           B` s8   e  Z d  Z d   Z d   Z d   Z d d d  Z RS(   s~   
    A registry of typing declarations.  The registry stores such declarations
    for functions, attributes and globals.
    c         C` s   g  |  _  g  |  _ g  |  _ d  S(   N(   t	   functionst
   attributest   globals(   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   &  s    		c         C` s)   t  | t  s t  |  j j |  | S(   N(   R   R^   RA   R   RJ   (   R   t   item(    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   register+  s    c         C` s)   t  | t  s t  |  j j |  | S(   N(   R   R   RA   R   RJ   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   register_attr0  s    c         ` s   | d k	 rD  d k	 s t  | s+ t   j j  | f  n   f d      d k	 sh t  | j d    | s t    k r t j  j } t |  j	   k	 r t
 d |  j  j	 f   q n     f d   } | Sd S(   s#  
        Register the typing of a global value.
        Functional usage with a Numba type::
            register_global(value, typ)

        Decorator usage with a template class::
            @register_global(value, typing_key=None)
            class Template:
                ...
        c         ` s`   d |  f   f d     Y} t    r: t j |  } n t d    j j  | f  |  S(   Nt   Templatec           ` s   e  Z   Z RS(    (   R,   R-   R1   (    (   t
   typing_key(    s5   lib/python2.7/site-packages/numba/typing/templates.pyR   G  s   s%   cannot infer type for global value %r(   t   callableR   t   FunctionRw   R   RJ   (   R   R   R   R   (   R   t   val(   R   s5   lib/python2.7/site-packages/numba/typing/templates.pyt   decorateF  s    R   s'   %r is not globally reachable as '%s.%s'c         ` s     |    S(   N(    (   R   (   R  R   (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt	   decorator\  s    N(   R!   RA   R   RJ   R@   t   syst   modulesR-   Ro   R,   R   (   R   R  R   R   t   modR  (    (   R  R   R   R  s5   lib/python2.7/site-packages/numba/typing/templates.pyt   register_global5  s    N(   R,   R-   R.   R   R   R   R!   R  (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR      s
   			t   BaseRegistryLoaderc           B` s    e  Z d  Z d   Z d   Z RS(   s  
    An incremental loader for a registry.  Each new call to
    new_registrations() will iterate over the not yet seen registrations.

    The reason for this object is multiple:
    - there can be several contexts
    - each context wants to install all registrations
    - registrations can be added after the first installation, so contexts
      must be able to get the "new" installations

    Therefore each context maintains its own loaders for each existing
    registry, without duplicating the registries themselves.
    c         ` s&   t    f d   |  j D  |  _ d  S(   Nc         3` s-   |  ]# } | t  j t   |   f Vq d  S(   N(   R   t   stream_listRo   (   RD   R5   (   t   registry(    s5   lib/python2.7/site-packages/numba/typing/templates.pys	   <genexpr>r  s   (   R   t   registry_itemst   _registrations(   R   R
  (    (   R
  s5   lib/python2.7/site-packages/numba/typing/templates.pyR   p  s    c         c` s'   x  t  |  j |  D] } | Vq Wd  S(   N(   t   nextR  (   R   R5   R   (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   new_registrationsu  s    (   R,   R-   R.   R   R  (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR  a  s   	t   RegistryLoaderc           B` s   e  Z d  Z d Z RS(   s6   
    An incremental loader for a typing registry.
    R   R   R   (   R   R   R   (   R,   R-   R.   R  (    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyR  z  s   (   i   (1   R.   t
   __future__R    R   R   R   R  R   R   R   R   R   t   errorsR   R   t   version_infoR   t   objectR	   R9   R!   R?   R%   R]   R^   Rk   R<   R3   Ry   R   R   R   R   R   R   R   R   R   R   R   R  R  t   builtin_registryR   t   inferR   t   infer_getattrR  t   infer_global(    (    (    s5   lib/python2.7/site-packages/numba/typing/templates.pyt   <module>   sD   \			3 !;	%	(L,			"A			