
\K]c           @` 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	 m
 Z
 m Z m Z m Z e e e e j j d  d    Z e j d< k Z e d= k Z i e j e j d	  6e j e j d
  6e j e j d  6e j e j d  6e j e j d  6e j e j d  6e j e j d  6e j e j d  6e j  e j d  6e j! e j d  6e j" e j d  6e j# e j d  6e j$ e j d  6Z% e j& d e j'  Z( e j& d e j'  Z) e j d  j* Z+ d   Z, d   Z- d   Z. i d e j/ 6d e j0 6d e j1 6d e j2 6Z3 d    Z4 d!   Z5 d"   Z6 d#   Z7 d$   Z8 d%   Z9 d&   Z: d'   Z; d(   Z< d)   Z= d* e j> d+ d>  f d/     YZ? d0 d1  Z@ d2   ZA d3   ZB d4   ZC d5   ZD d6   ZE d d7  ZG d d8  ZH d9   ZI d:   ZJ d;   ZK d S(?   i    (   t   print_functiont   divisiont   absolute_importNi   (   t   errorst   typest   configt   utilst   .i   i   i
   t   boolt   int8t   int16t   int32t   int64t   uint8t   uint16t   uint32t   uint64t   float32t   float64t	   complex64t
   complex128s   [<>=\|]([a-z])(\d+)?$s   [<>=\|]([mM])8?(\[([a-z]+)\])?$t   U1c         C` s   t  j |  j  } | s' t |    n  | j   } | d } | d k r |  j d k rg t d   n  |  j t } | t | d  k s t	 d   t
 j |  S| d k r |  j } | t | d  k s t	 d   t
 j |  St |    d  S(	   Ni    t   Us   =|s%   Does not support non-native byteorderi   s   Unicode char size mismatcht   Ss   Char size mismatch(   t
   re_typestrt   matcht   strt   NotImplementedErrort   groupst	   byteordert   itemsizet   sizeof_unicode_chart   intt   AssertionErrorR   t   UnicodeCharSeqt   CharSeq(   t   dtypet   mR   t   typecodet   count(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   _from_str_dtype-   s     
"	"c         C` s   t  j |  j  } | s' t |    n  | j   } | d } | d pJ d } | d k rf t j |  S| d k r t j |  St |    d  S(   Ni    i   t    R%   t   M(   t   re_datetimestrR   R   R   R   R   t   NPTimedeltat
   NPDatetime(   R$   R%   R   R&   t   unit(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   _from_datetime_dtypeF   s    
c         C` s   t  |   t  k r6 t |  t j  r6 t j |   }  n" t |  d d  d k	 rX t |   Sy t |  SWnx t	 k
 r |  j
 } | d k r t |   S| d k r t |   S| d k r t |  j d  } t j | |  j  Sn Xt |    d S(   s   
    Return a Numba Type instance corresponding to the given Numpy *dtype*.
    NotImplementedError is raised on unsupported Numpy dtypes.
    t   fieldst   SUt   mMt   Vi    N(   t   typet
   issubclasst   npt   genericR$   t   getattrt   Nonet   from_struct_dtypet
   FROM_DTYPEt   KeyErrort   charR(   R/   t
   from_dtypet   subdtypeR   t   NestedArrayt   shapeR   (   R$   R=   t   subtype(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyR>   U   s     $
	

t   M8t   m8R   R   c         C` s  t  j |   }  t |  t  j t  j t  j f  rC t j t |    S|  t  j	 k r_ t j d  St |  t  j
 t  j f  r t t |   } |  j r t j d | |  j f  St j |  Sn  t |  t  j t  j f  rt t |   } t j d | |  j f  St |  t  j  rt |   St |  t  j  r=t |  j  St |  t  j j  r_t |  j  St |  t  j  r~t |  j  St |  t  j  rt |  j  t |  j  f } t j |  St d |  f   d S(   s   
    Return a numpy dtype instance corresponding to the given Numba type.
    NotImplementedError is if no correspondence is known.
    t   ?s   %s[%s]s   %s%ds)   %r cannot be represented as a Numpy dtypeN(   R   t	   unliteralt
   isinstancet   Complext   Integert   FloatR6   R$   R   t   bool_R-   R,   t   _as_dtype_lettersR4   R.   R#   R"   R'   t   Recordt   as_struct_dtypet
   EnumMembert   as_dtypet   npytypest   DTypet   NumberClassR@   t   tupleRA   R   (   t   nbtypet   lettert   spec(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyRP   w   s4    !	
c         C` s   t  |  t j  s t  g  } g  } g  } g  } xv |  j D]k \ } } |  j |  s: | j |  | j t |   | j |  j |   | j |  j	 | j
  q: q: Wi | d 6| d 6| d 6|  j d 6| d 6} t |  |  t j | d |  j S(   s8   Convert Numba Record type to NumPy structured dtype
    t   namest   formatst   offsetsR   t   titlest   align(   RG   R   RM   R!   t   memberst   is_titlet   appendRP   t   offsetR0   t   titlet   sizet   _check_struct_alignmentR6   R$   t   aligned(   t   recRX   RY   RZ   R[   t   kt   tR0   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyRN      s&    

c         C` s   |  j  r x| t | d | d  D]` \ } } |  j |  } | j } | d k	 r! | | k r! d } t | j | | |    q! q! Wn  d S(   s(   Check alignment compatibility with NumpyRX   RY   sb   NumPy is using a different alignment ({}) than Numba/LLVM ({}) for {}. This is likely a NumPy bug.N(   Rd   t   zipt   alignoft	   alignmentR9   t
   ValueErrort   format(   Re   R0   Rf   t   dtt
   llvm_alignt	   npy_alignt   msg(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyRc      s    	$	c         C` s   t  j t |    t k S(   N(   R6   R$   R4   R;   (   t   val(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   is_arrayscalar   s    c         C` sk   t  |  t j  r |  j } nC y t j t |    } Wn' t k
 r` t d t |     n Xt |  S(   Ns#   no corresponding numpy dtype for %r(   RG   R6   R7   R$   R4   t	   TypeErrorR   R>   (   Rq   R$   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   map_arrayscalar_type   s    c         C` s   t  |  t j  S(   N(   RG   R6   t   ndarray(   Rq   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   is_array   s    c         C` s6   |  j  d r d } n |  j  d r, d } n d } | S(   Nt   C_CONTIGUOUSt   Ct   F_CONTIGUOUSt   Ft   A(   t   flags(   Rq   t   layout(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt
   map_layout   s    		c         C` sx   t  d  } d } xM t |   D]? \ } } t | t j  r | j | k r | } | j } q q W| d k	 st t  | S(   s   
    Given the array-compatible input types to an operation (e.g. ufunc),
    select the appropriate input for wrapping the operation output,
    according to each input's __array_priority__.

    An index into *inputs* is returned.
    s   -infN(   t   floatR9   t	   enumerateRG   R   t   ArrayCompatiblet   array_priorityR!   (   t   inputst   max_priot   selected_indext   indext   ty(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   select_array_wrapper   s    !c         C` sv   | t  |  } | | f } |  j d | i   } | d k ro | j t j j k rV | St j d | f   n  | j S(   s.  
    Given the array-compatible input types to an operation (e.g. ufunc),
    and the operation's formal output type (a types.Array instance),
    resolve the actual output type using the typing *context*.

    This uses a mechanism compatible with Numpy's __array_priority__ /
    __array_wrap__.
    t   __array_wrap__s   __array_wrap__ failed for %sN(	   R   t   resolve_function_typeR9   R   R   t   ArrayR   t   TypingErrort   return_type(   t   contextR   t   formal_outputt   selected_inputt   argst   sig(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   resolve_output_type   s    	c         ` s   d d l  m } | j } y | | j |   k } WnY t k
 r g  | j | j D] } | j ^ qS } d   t   f d   | D  } n X| S(   sR  Return whether the *loop* for the *ufunc* is supported -in nopython-.

    *loop* should be a UFuncLoopSpec instance, and *ufunc* a numpy ufunc.

    For ufuncs implemented using the ufunc_db, it is supported if the ufunc_db
    contains a lowering definition for 'loop' in the 'ufunc' entry.

    For other ufuncs, it is type based. The loop will be considered valid if it
    only contains the following letter types: '?bBhHiIlLqQfd'. Note this is
    legacy and when implementing new ufuncs the ufunc_db should be preferred,
    as it allows for a more fine-grained incremental support.
    i   (   t   ufunc_dbs   ?bBhHiIlLqQfdc         3` s   |  ] } |   k Vq d  S(   N(    (   t   .0Rg   (   t   supported_types(    s2   lib/python2.7/site-packages/numba/numpy_support.pys	   <genexpr>*  s    (	   t   targetsR   t	   ufunc_sigt   get_ufunc_infoR<   t   numpy_inputst   numpy_outputsR=   t   all(   t   ufunct   loopR   t   loop_sigt   supported_loopt   xt
   loop_types(    (   R   s2   lib/python2.7/site-packages/numba/numpy_support.pyt   supported_ufunc_loop  s    	& t   UFuncLoopSpect   _UFuncLoopSpecR   t   outputsR   c           B` s2   e  Z d  Z d Z e d    Z e d    Z RS(   s   
    An object describing a ufunc loop's inner types.  Properties:
    - inputs: the inputs' Numba types
    - outputs: the outputs' Numba types
    - ufunc_sig: the string representing the ufunc's type signature, in
      Numpy format (e.g. "ii->i")
    c         C` s    g  |  j  D] } t |  ^ q
 S(   N(   R   RP   (   t   selfR   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyR   ;  s    c         C` s    g  |  j  D] } t |  ^ q
 S(   N(   R   RP   (   R   R   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyR   ?  s    (    (   t   __name__t
   __module__t   __doc__t	   __slots__t   propertyR   R   (    (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyR   /  s   t   safec         C` sY   t  j |   }  t  j |  } | rF |  j d k rF | j d k rF t St  j |  | |  S(   sW  
    A variant of np.can_cast() that can allow casting any integer to
    any real or complex type, in case the operation has mixed-kind
    inputs.

    For example we want `np.power(float32, int32)` to be computed using
    SP arithmetic and return `float32`.
    However, `np.sqrt(int32)` should use DP arithmetic and return `float64`.
    t   iut   cf(   R6   R$   t   kindt   Truet   can_cast(   t   from_t   tot   has_mixed_inputst   casting(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   ufunc_can_castD  s
    
$c         C` sQ  | |  j   } | |  j  } t |  |  j  k s5 t  y# g  | D] } t |  ^ q? } Wn t k
 rl d SXy# g  | D] } t |  ^ qw } Wn t k
 r d SXt d   | D  o t d   | D  } d   } xp|  j D]e}	 |	 |  j   }
 |	 |  j } d |
 k rq n  t	 } xv t
 | |
  D]e \ } } | j d k sT| d k rp| j | k rt } Pqq-t | j | | d  s-t } Pq-q-W| rt rxR t
 | |  D]> \ } } | j d k rt | | j | d  rt } PqqWn  | r y" | | |
  } | | |  } Wn t k
 r5q qIXt | | |	  Sq q Wd S(	   sj  Find the appropriate loop to be used for a ufunc based on the types
    of the operands

    ufunc        - The ufunc we want to check
    arg_types    - The tuple of arguments to the ufunc, including any
                   explicit output(s).
    return value - A UFuncLoopSpec identifying the loop, or None
                   if no matching loop is found.
    c         s` s   |  ] } | j  d  k Vq d S(   R   N(   R   (   R   Rm   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pys	   <genexpr>q  s    c         s` s   |  ] } | j  d  k Vq d S(   R   N(   R   (   R   Rm   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pys	   <genexpr>r  s    c         S` s   t  |  t  |   k s t  g  t |  |  D]3 \ } } | d k rL | n t t j |   ^ q. } | g  | t  |   D] } t t j |   ^ q{ 7} | S(   s   
        Return a list of Numba types representing *ufunc_letters*,
        except when the letter designates a datetime64 or timedelta64,
        in which case the type is taken from *numba_types*.
        R2   (   t   lenR!   Rh   R>   R6   R$   (   t   numba_typest   ufunc_letterst   tpRV   R   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   choose_typest  s    F0t   OR2   R   t	   same_kindN(   t   ninR   R!   RP   R   R9   t   anyR   t   noutR   Rh   R=   t   FalseR   t   strict_ufunc_typingR   (   R   t	   arg_typest   input_typest   output_typesR   t   np_input_typest   np_output_typesR   R   t	   candidatet   ufunc_inputst   ufunc_outputst   foundt   outert   innerR   R   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   ufunc_find_matching_loopV  sX    ##	c         C` s   |  j  S(   N(   t   isalignedstruct(   t   struct(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   _is_aligned_struct  s    c         C` s   |  j  r t d   n  g  } x |  j j   D]x \ } } | d  \ } } t |  d k rf | d n d } t |  } i | d 6| d 6| d 6} | j | | f  q. W|  j }	 t	 |   }
 t
 j | |	 |
  S(   s:   Convert a NumPy structured dtype to Numba Record type
    s&   Do not support dtype containing objecti   i   R4   R`   Ra   N(   t	   hasobjectRs   R0   t   itemsR   R9   R>   R_   R   R   R   RM   (   R$   R0   t   namet   infot	   elemdtypeR`   Ra   R   t   infosRb   Rd   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyR:     s    	"
	c         C` s8   t  |  t j  r |  j }  n  t j | } | j |   S(   s;   
    Get a ctypes array of *nbytes* starting at *ptr*.
    (   RG   t   ctypest   c_void_pt   valuet   c_bytet   from_address(   t   ptrt   nbytest   arrty(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   _get_bytes_buffer  s    c         C` s   t  j t |  |  |  S(   N(   R6   t
   frombufferR   (   R   R   R$   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   _get_array_from_ptr  s    c         C` sg  d d l  m } y |  j }  Wn t k
 r0 n X| d k	 rO t j |  } n  t |  t j	  r | d k r| t
 d   n  |  } n t |  t j  r| |  j  } t | t j  s t  t | j  } | d k	 r | | k r t
 d | |  f   n  | } t j |  t j	  } n t
 d |  f   | j t j | d t j } t | | |  j |  S(   s   
    Return a Numpy array view over the data pointed to by *ptr* with the
    given *shape*, in C order.  If *dtype* is given, it is used as the
    array's dtype, otherwise the array's dtype is inferred from *ptr*'s type.
    i   (   t   from_ctypess*   explicit dtype required for void* arguments%   mismatching dtype '%s' for pointer %ss!   expected a ctypes pointer, got %rR$   N(   t   typing.ctypes_utilsR   t   _as_parameter_t   AttributeErrorR9   R6   R$   RG   R   R   Rs   t   _Pointert	   __class__R   t   CPointerR!   RP   t   castR   t   productt   intpR   t   reshape(   R   RA   R$   R   t   pt   ptrtyt	   ptr_dtypeR   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   carray  s.    	c         C` s;   t  | t j  s( | d d d  } n  t |  | |  j S(   s   
    Return a Numpy array view over the data pointed to by *ptr* with the
    given *shape*, in Fortran order.  If *dtype* is given, it is used as the
    array's dtype, otherwise the array's dtype is inferred from *ptr*'s type.
    Ni(   RG   R   t	   INT_TYPESR   t   T(   R   RA   R$   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   farray
  s    c         C` s   t  |   } | d } x* | d k rB |  | d k rB | d 8} q W| d k  rS t S| | | k rg t Sd } x* | | k  r |  | d k r | d 7} qp W| } x> | | k r | | |  | | | d k r t S| d 8} q Wt S(   sv   Is the given shape, strides, and itemsize of C layout?

    Note: The code is usable as a numba-compiled function
    i   ii    (   R   R   R   (   t   dimst   stridesR   t   ndt   inneraxt   outeraxt   ax(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   is_contiguous  s"    
 c         C` s   t  |   } d } x* | | k  r> |  | d k r> | d 7} q W| | k rO t S| | | k rc t S| d } x* | | k r |  | d k r | d 8} qp W| } x> | | k  r | | |  | | | d k r t S| d 7} q Wt S(   sv   Is the given shape, strides, and itemsize of F layout?

    Note: The code is usable as a numba-compiled function
    i    i   (   R   R   R   (   R   R   R   R   t   firstaxt   lastaxR   (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt
   is_fortran6  s"    
 c         C` s1   t  j t  j t  j t  j t  j f } t |  |  S(   ss    Returns True if the type of 'arr' is supported by the Numba `np.asarray`
    implementation, False otherwise.
    (   R   R   t   Sequencet   Tuplet   Numbert   BooleanRG   (   t   arrt   ok(    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   type_can_asarrayW  s    $(   i   i    (   i   i
   (   R   R   R   (L   t
   __future__R    R   R   t   collectionsR   t   ret   numpyR6   R)   R   R   R   R   RT   t   mapR    t   __version__t   splitt   versiont	   PYVERSIONt   int_divbyzero_returns_zeroR   t   booleanR$   R	   R
   R   R   R   R   R   R   R   R   R   R   R;   t   compilet   IR   R+   R   R   R(   R/   R>   R-   R,   R#   R"   RL   RP   RN   Rc   Rr   Rt   Rv   R~   R   R   R   t
   namedtupleR   R   R   R   R:   R   R   R9   R   R   R   R   R  (    (    (    s2   lib/python2.7/site-packages/numba/numpy_support.pyt   <module>   sp   "%			


	"						
			"	_			
	&	!	!