
\K]c           @@ sR  d  d l  m Z m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l m Z m Z d  d l m Z m Z d d l m Z d d l m Z m Z d  d	 l m Z d  d
 l m 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 S(   i    (   t   print_functiont   absolute_import(   t   defaultdictN(   t   typest   errors(   t
   Conversiont   rulesi   (   t	   templates(   t   typeoft   Purpose(   t   utils(   t   Sequencet   Ratingc           B@ s)   e  Z d Z d   Z d   Z d   Z RS(   t   promotet   safe_convertt   unsafe_convertc         C@ s   d |  _  d |  _ d |  _ d  S(   Ni    (   R   R   R   (   t   self(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   __init__   s    		c         C@ s   |  j  |  j |  j f S(   s]   Returns a tuple suitable for comparing with the worse situation
        start first.
        (   R   R   R   (   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   astuple   s    c         C@ sb   t  |   t  |  k	 r t St   } |  j | j | _ |  j | j | _ |  j | j | _ | S(   N(   t   typet   NotImplementedR   R   R   R   (   R   t   othert   rsum(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   __add__"   s    	(   R   R   R   (   t   __name__t
   __module__t	   __slots__R   R   R   (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR      s   		t	   CallStackc           B@ sV   e  Z d  Z d   Z d   Z d   Z e j d    Z d   Z	 d   Z
 d   Z RS(   s#   
    A compile-time call stack
    c         C@ s   g  |  _  t j   |  _ d  S(   N(   t   _stackt	   threadingt   RLockt   _lock(   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   1   s    	c         C@ s   |  j  t |   | d S(   sy   
        Returns item in the stack where index=0 is the top and index=1 is
        the second item from the top.
        i   (   R   t   len(   R   t   index(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   __getitem__5   s    c         C@ s   t  |  j  S(   N(   R    R   (   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   __len__<   s    c         c@ s~   |  j  | j |  r* d } t |   n  |  j j   |  j j t | | |   z	 d  VWd  |  j j   |  j j	   Xd  S(   Ns2   compiler re-entrant to the same function signature(
   t   matcht   funct   RuntimeErrorR   t   acquireR   t   appendt	   CallFramet   popt   release(   R   t	   typeinfert   func_idt   argst   msg(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   register?   s    	c         c@ s/   x( |  D]  } | j  j | k r | Vq q Wd S(   sg   
        Yields frame that matches the function object starting from the top
        of stack.
        N(   R-   R%   (   R   t   py_funct   frame(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   finditerM   s    c         C@ s0   y t  |  j |   SWn t k
 r+ d SXd S(   sZ   
        Returns the first result from `.finditer(py_func)`; or None if no match.
        N(   t   nextR3   t   StopIteration(   R   R1   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt	   findfirstV   s    c         C@ s1   x* |  j  |  D] } | j | k r | Sq Wd S(   s   
        Returns first function that matches *py_func* and the arguments types in
        *args*; or, None if no match.
        N(   R3   R.   (   R   R1   R.   R2   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR$   _   s    (   R   R   t   __doc__R   R"   R#   t
   contextlibt   contextmanagerR0   R3   R6   R$   (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   ,   s   							R)   c           B@ s    e  Z d  Z d   Z d   Z RS(   s#   
    A compile-time call frame
    c         C@ s   | |  _  | |  _ | |  _ d  S(   N(   R,   R-   R.   (   R   R,   R-   R.   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   m   s    		c         C@ s   d j  |  j |  j  S(   Ns   CallFrame({}, {})(   t   formatR-   R.   (   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   __repr__r   s    (   R   R   R7   R   R;   (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR)   i   s   	t   BaseContextc           B@ sR  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d# d  Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  e! e" d  Z# d   Z$ e! e! e" d   Z% d!   Z& d"   Z' RS($   sE   A typing context for storing function typing constrain template.
    c         C@ s\   i  |  _  t t  |  _ t t  |  _ t j   |  _ t j	 |  _
 t   |  _ |  j   d  S(   N(   t   _registriesR   t   listt
   _functionst   _attributesR
   t
   UniqueDictt   _globalsR   t   default_type_managert   tmR   t	   callstackt   init(   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   z   s    	c         C@ s   d S(   sQ   
        Initialize the typing context.  Can be overriden by subclasses.
        N(    (   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyRF      t    c         C@ s   |  j    |  j   d S(   sy   
        Refresh context with new declarations from known registries.
        Useful for third-party extensions.
        N(   t   load_additional_registriest   _load_builtins(   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   refresh   s    
c   	      C@ s  g  } g  } t  } t | t j  rF | j   \ } } | j |  nw | |  j k r xe |  j | D]4 } | p{ t | d  } | j t | d g    qc Wn d } | j	 | j
 d |   | r d g } x' | D] } | j	 d j
 |   q Wn  | r| j	 d  n  d j |  S(	   sH   
        Returns a string description of the type of a function
        t   generict   casess2   No type info available for {func!r} as a callable.R%   s   Known signatures:s    * {0}s    * parameterizeds   
(   t   Falset
   isinstanceR   t   Callablet   get_call_signaturest   extendR?   t   hasattrt   getattrR(   R:   t   join(	   R   R%   t   desct   defnst   paramt   sigst   tplR/   t   sig(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   explain_function_type   s&     	c         C@ s   y |  j  | | |  } Wn" t j k
 r= } | } d } n Xd } | d k	 rT | S|  j | | |  } | d k r | d k	 r |  n  | S(   st   
        Resolve function type *func* for argument types *args* and *kws*.
        A signature is returned.
        N(   t   _resolve_user_function_typeR   t   TypingErrort   Nonet   _resolve_builtin_function_type(   R   R%   R.   t   kwst   rest   et   last_exception(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_function_type   s    
	c   
      C@ s   | |  j  k r |  j  | } x | D]| } xs t t g D]e } | rW | j | |  } n4 g  | D] } t j |  ^ q^ }	 | j |	 |  } | d  k	 r6 | Sq6 Wq# Wn  d  S(   N(   R?   t   TrueRM   t   applyR   t	   unliteralR^   (
   R   R%   R.   R`   RV   t   defnt   support_literalsRa   t   at	   fixedargs(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR_      s    "c         C@ s   |  j  |  } | d  k	 r$ | } n  t | t j  rj |  j | d  } | d  k	 rj |  j | | |  Sn  t | t j  r | j |  | |  Sd  S(   Nt   __call__(	   t   _lookup_globalR^   RN   R   t   Typet   resolve_getattrRd   RO   t   get_call_type(   R   R%   R.   R`   t   literalst   functyt	   func_type(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR\      s    	c         c@ s|   | |  j  k r/ xf |  j  | D] } | Vq WnI xF t |  j D]5 } | |  j  k r? x |  j  | D] } | Vqb Wq? q? Wd S(   sE   
        Get matching AttributeTemplates for the Numba type.
        N(   R@   R   t   __mro__(   R   t   typt   attrinfot   cls(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   _get_attribute_templates   s    c         @ s      f d   } | |  } | d k	 r. | S| t j |   } | d k	 rS | St | t j  r  j |    } | d k	 r | Sn  d S(   s   
        Resolve getting the attribute *attr* (a string) on the Numba type.
        The attribute's type is returned, or None if resolution failed.
        c         @ s@   x9  j  |   D]( } | j |     } | d  k	 r | Sq Wd  S(   N(   Rx   t   resolveR^   (   Ru   Rv   t   ret(   t   attrR   (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   core  s    N(   R^   R   Rg   RN   t   Modulet   resolve_module_constants(   R   Ru   R{   R|   t   outt   attrty(    (   R{   R   s3   lib/python2.7/site-packages/numba/typing/context.pyRo      s    c         C@ sR   xK |  j  |  D]: } | j | |  } | d k	 r t j t j | |  Sq Wd S(   s   
        Resolve setting the attribute *attr* (a string) on the *target* type
        to the given *value* type.
        A function signature is returned, or None if resolution failed.
        N(   Rx   Ry   R^   R   t	   signatureR   t   void(   R   t   targetR{   t   valueRv   t
   expectedty(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_setattr  s    c         C@ sD   t  | t j  s t |   | | f } d } |  j d | |  S(   Nt   static_getitem(    (   RN   R   Rn   t   AssertionErrorRd   (   R   R   R!   R.   R`   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_static_getitem#  s    c         C@ sG   t  | t j  s t |   | | | f } i  } |  j d | |  S(   Nt   static_setitem(   RN   R   Rn   R   Rd   (   R   R   R!   R   R.   R`   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_static_setitem)  s    c         C@ sR   t  | t j  s t |   |  j t j  } | j |  | | | f i   } | S(   N(   RN   R   Rn   R   t   resolve_value_typet   operatort   setitemRp   (   R   R   R!   R   t   fntyRZ   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_setitem/  s    c         C@ s=   | | f } i  } |  j  t j  } | j |  | |  } | S(   N(   R   R   t   delitemRp   (   R   R   R!   R.   R`   R   RZ   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_delitem5  s
    c         C@ sS   t  | t j  s t  t | j |  } y |  j |  SWn t k
 rN n Xd S(   sb   
        Resolve module-level global constants.
        Return None or the attribute type
        N(   RN   R   R}   R   RS   t   pymodR   t
   ValueError(   R   Ru   R{   t   attrval(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR~   <  s    c         C@ s]   y t  | t j  SWnB t k
 rX t j j |  rR t  t j j |  t j  S  n Xd S(   s   
        Return the numba type of a Python value that is being used
        as a function argument.  Integer types will all be considered
        int64, regardless of size.

        ValueError is raised for unsupported types.
        N(   R   R	   t   argumentR   t   numbat   cudat   is_cuda_arrayt   as_cuda_array(   R   t   val(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_argument_typeH  s    c         C@ s~   y t  | t j  } Wn" t k
 r: } t j |  } n X| St | t j  rU | S|  j	 |  } | d k	 rt | S|  d S(   s   
        Return the numba type of a Python value that is being used
        as a runtime constant.
        ValueError is raised for unsupported types.
        N(   R   R	   t   constantR   R
   t   erase_tracebackRN   R   t   ExternalFunctiont   _get_global_typeR^   (   R   R   t   tyRb   t
   typeof_exc(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   X  s    c         C@ sB   |  j  |  } | d  k	 r | St | t j  r> t j |  Sd  S(   N(   Rm   R^   RN   t   pytypest
   ModuleTypeR   R}   (   R   t   gvR   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   q  s
    c         C@ sF   d d l  m } m } m } d d l  m } m } |  j t j  d  S(   Ni   (   t   builtinst	   arraydeclt
   npdatetime(   t   ctypes_utilst   bufproto(	   RG   R   R   R   R   R   t   install_registryR   t   builtin_registry(   R   R   R   R   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyRI   x  s    c         C@ s   d S(   sS   
        Load target-specific registries.  Can be overriden by subclasses.
        N(    (   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyRH     RG   c         C@ s>  y |  j  | } Wn- t k
 r@ t j |  } | |  j  | <n Xx* | j d  D] } |  j | |    qQ Wx* | j d  D] } |  j | |    q~ Wx | j d  D] \ } } |  j |  } | d k r |  j	 | |  q | j
 |  } | d k rt d | | f   n  |  j |  |  j | |  q Wd S(   s~   
        Install a *registry* (a templates.Registry instance) of function,
        attribute and global declarations.
        t	   functionst
   attributest   globalss   cannot augment %s with %sN(   R=   t   KeyErrorR   t   RegistryLoadert   new_registrationst   insert_functiont   insert_attributesRm   R^   t   insert_globalt   augmentt	   TypeErrort   _remove_globalt   _insert_global(   R   t   registryt   loadert   ftclsR   t   gtyt   existingt   newty(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s&    c         C@ sW   y t  j |  } Wn t k
 r& n Xy |  j j | d  SWn t k
 rR d SXd S(   sD   
        Look up the registered type for global value *gv*.
        N(   t   weakreft   refR   RB   t   getR^   (   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyRm     s    c         C@ sM   |  j  j d  } y t j | |  } Wn t k
 r; n X| |  j  | <d S(   sr   
        Register type *gty* for value *gv*.  Only a weak reference
        to *gv* is kept, if possible.
        c         S@ s   | |   d  S(   N(    (   t   wrR*   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   on_disposal  s    N(   RB   R*   R   R   R   (   R   R   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s    c         C@ s5   y t  j |  } Wn t k
 r& n X|  j | =d S(   sC   
        Remove the registered type for global value *gv*.
        N(   R   R   R   RB   (   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s
    c         C@ s   |  j  | |  d  S(   N(   R   (   R   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s    c         C@ s!   | j  } |  j | j |  d  S(   N(   t   keyR@   R(   (   R   t   atR   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s    	c         C@ s!   | j  } |  j | j |  d  S(   N(   R   R?   R(   (   R   t   ftR   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR     s    	c         C@ s   |  j  | t j |   d S(   s   Insert a user function.

        Args
        ----
        - fn:
            object used as callee
        - ft:
            function template
        N(   R   R   t   Function(   R   t   fnR   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   insert_user_function  s    
c         C@ s   | | k r t  j S|  j j | |  } | d k	 r8 | S| j |  |  } | j |  |  } | d k rl | S| d k r| | St | |  Sd S(   s   
        Check whether conversion is possible from *fromty* to *toty*.
        If successful, return a numba.typeconv.Conversion instance;
        otherwise None is returned.
        N(   R   t   exactRD   t   check_compatibleR^   t   can_convert_tot   can_convert_fromt   min(   R   t   fromtyt   totyt   convt   forwardt   backward(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   can_convert  s    c   	      C@ s"  t  |  t  |  k r d St   } x t | |  D] \ } } |  j | |  } | d k rc d S| r} | t j k r} d S| r | t j k r d S| t j k r | j d 7_ q5 | t j	 k r | j
 d 7_
 q5 | t j k r | j d 7_ q5 | t j k rq5 t d |   q5 W| S(   s   
        Rate the actual arguments for compatibility against the formal
        arguments.  A Rating instance is returned, or None if incompatible.
        i   t   unreachableN(   R    R^   R   t   zipR   R   t   unsafeR   R   t   safeR   R   t	   Exception(	   R   t
   actualargst
   formalargst   unsafe_castingt   exact_match_requiredt   ratet   actualt   formalR   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   _rate_arguments  s*    	c         C@ s   t  |  t  |  k r t Sx t | |  D]z \ } } |  j j | |  d k	 rY q, n  |  j | |  } | d k r{ t S| t j k	 s t	  |  j j
 | | |  q, Wt S(   s   
        Install possible conversions from the actual argument types to
        the formal argument types in the C++ type manager.
        Return True if all arguments can be converted.
        N(   R    RM   R   RD   R   R^   R   R   R   R   t   set_compatibleRe   (   R   R   R   R   R   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   install_possible_conversions  s    c         C@ s\  | s t  d   i | d 6| d 6} g  }	 xl | D]d }
 t |  t |
 j  k r4 |  j | |
 j |  } | d
 k	 r |	 j | j   |
 f  q q4 q4 W|	 j d d    |	 rX|	 d \ } } | sTg  } x1 |	 D]) \ } }
 | | k r Pn  | j |
  q Wt |  d k rT| | d j t	 t
 |   f } d	 | } t |   qTn  | Sd
 S(   sS  
        Given actual *args* and *kws*, find the best matching
        signature in *cases*, or None if none matches.
        *key* is used for error reporting purposes.
        If *allow_ambiguous* is False, a tie in the best matches
        will raise an error.
        If *unsafe_casting* is False, unsafe casting is forbidden.
        s(   Keyword arguments are not supported, yetR   R   R   c         S@ s   |  d S(   Ni    (    (   t   i(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   <lambda>A  RG   i    i   s   
s#   Ambiguous overloading for %s %s:
%sN(   R   R    R.   R   R^   R(   R   t   sortRT   t   mapt   strR   (   R   R   RL   R.   R`   t   allow_ambiguousR   R   t   optionst
   candidatest   caset   ratingt	   best_ratet   bestt   tiedR   R/   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   resolve_overload(  s0    
#!
c         G@ s`   d   } t  | d | } | d } x4 | d D]( } |  j | |  } | d  k r0 Pq0 q0 W| S(   Nc         S@ s   t  |  d d  S(   sf   Uses bitwidth to order numeric-types.
            Fallback to stable, deterministic sort.
            t   bitwidthi    (   RS   (   t   obj(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   keyfuncZ  s    R   i    i   (   t   sortedt   unify_pairsR^   (   R   t   typelistR   t   unifiedt   tp(    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   unify_typesW  s    	
c         C@ s>  | | k r | S| t  j k r# | S| t  j k r6 | S| j |  |  } | d k	 rX | S| j |  |  } | d k	 rz | S|  j d | d |  } | d k	 r | t j k r | S|  j d | d |  } | d k	 r | t j k r | St | t  j  st | t  j  r:t  j	 |  } t  j	 |  } |  j
 | |  Sd S(   sr   
        Try to unify the two given types.  A third type is returned,
        or None in case of failure.
        R   R   N(   R   t	   undefinedt   unifyR^   R   R   R   RN   t   LiteralRg   R   (   R   t   firstt   secondR   R   (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR   g  s.    $N((   R   R   R7   R   RF   RJ   R[   Rd   R_   R^   R\   Rx   Ro   R   R   R   R   R   R~   R   R   R   RI   RH   R   Rm   R   R   R   R   R   R   R   Re   RM   R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR<   v   sJ   																								
						-	t   Contextc           B@ s   e  Z d    Z RS(   c   
      C@ s   d d l  m } m } m } m } m } m } m } m } m	 }	 |  j
 | j  |  j
 | j  |  j
 | j  |  j
 | j  |  j
 | j  |  j
 | j  |  j
 | j  |  j
 | j  |  j
 |	 j  d  S(   Ni   (	   t
   cffi_utilst	   cmathdeclt   enumdeclt   listdeclt   mathdeclt   npydeclt
   randomdeclt   setdeclt   dictdecl(   RG   R  R  R  R  R  R  R  R	  R
  R   R   (
   R   R  R  R  R  R  R  R  R	  R
  (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyRH     s    @(   R   R   RH   (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyR    s   (   t
   __future__R    R   t   collectionsR   R   R   R   R   R8   R   R   R   t   numba.typeconvR   R   RG   R   R   R	   R
   t	   numba.sixR   t   objectR   R   R)   R<   R  (    (    (    s3   lib/python2.7/site-packages/numba/typing/context.pyt   <module>   s(   =  