ó
\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 Z d d l Z	 d d l
 j j Z d d l
 m Z d d l m Z m Z d d l m Z m Z m Z m Z d d l m Z e ƒ  Z e j Z e	 j e	 j d ƒ ƒ Z e j Z e j  Z! e	 j e	 j d	 ƒ ƒ Z" e" j Z# e" j  Z$ d
 Z% d Z& d Z' d Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 e5 d „ Z6 e4 e j7 e j8 ƒ e4 e j9 e j: ƒ Z; e4 e j< e j= ƒ Z> e4 e j? e j@ ƒ ZA e4 e jB e jC ƒ ZD e4 e jE e jF ƒ ZG e6 e jH d d ƒ ZI e6 e jJ d d ƒ ZK e6 e jL d d  ƒ ZM e6 e jN d! d" ƒ ZO e6 e jP d# d$ ƒ ZQ e6 e jR d% d& ƒ ZS e6 e jT d' d( ƒ ZU e6 e jV d) d* ƒ ZW e6 e jX d+ d, ƒ ZY e6 e jZ d- d. ƒ Z[ e6 e j\ d/ d0 ƒ Z] e6 e j^ d1 d2 ƒ Z_ e6 e j` d3 d4 ƒ Za e6 e jb d5 d6 ƒ Zc e jd dY k r«e6 e je d8 d9 ƒ Zf e6 e jg d: d; eh ƒ Zi e6 e jj d< d= eh ƒ Zk n* e6 e jg d: d; ƒ Zi e6 e jj d< d= ƒ Zk e6 e jl d> d? ƒ Zm e6 e jn d@ dA ƒ Zo e6 e jp dB dC eh ƒ Zq e6 e jr dD dE ƒ Zs e e jt e ju ƒ dF „  ƒ Zv e e jt e jw ƒ dG „  ƒ Zx e e jy e ju ƒ dH „  ƒ Zz e e jy e jw ƒ dI „  ƒ Z{ e jd dZ k ròe e j| e ju ƒ dK „  ƒ Z} e e j| e jw ƒ dL „  ƒ Z~ n  e e j e ju e ju ƒ dM „  ƒ Z€ e e j e ju ƒ dN „  ƒ Z‚ e e jƒ e ju e j„ ƒ dO „  ƒ Z… e e j† e j‡ e j‡ ƒ dP „  ƒ Zˆ e e j† e j‰ e j‰ ƒ dQ „  ƒ ZŠ e e j† e ju e ju ƒ dR „  ƒ Z‹ e e jŒ e j‡ e j‡ ƒ dS „  ƒ Z e e jŒ e j‰ e j‰ ƒ dT „  ƒ ZŽ e e jŒ e ju e ju ƒ dU „  ƒ Z e e j e ju ƒ dV „  ƒ Z‘ e3 e j e‘ ƒ e e j’ e ju ƒ dW „  ƒ Z“ e3 e j’ e“ ƒ e e j” e ju e ju ƒ e e j” e ju e jw ƒ dX „  ƒ ƒ Z• d S([   sA   
Provide math calls that uses intrinsics or libc math functions.
i    (   t   print_functiont   absolute_importt   divisionN(   t   Type(   t   Registryt   impl_ret_untracked(   t   typest   cgutilst   utilst   config(   t	   signaturet   float32t   float64iÿÿÿI   €    Iÿÿÿÿÿÿÿl            c         C` s   |  j  d | | ƒ S(   s<   
    Return a condition testing whether *val* is a NaN.
    t   uno(   t   fcmp_unordered(   t   buildert   val(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   is_nan&   s    c         C` s|   t  j j | j t d ƒ ƒ } t  j j | j t d ƒ ƒ } |  j t  j | | ƒ } |  j t  j | | ƒ } |  j | | ƒ S(   sB   
    Return a condition testing whether *val* is an infinite.
    s   +infs   -inf(   t   lct   Constantt   realt   typet   floatt   fcmpt   FCMP_OEQt   or_(   R   R   t   pos_inft   neg_inft   isposinft   isneginf(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   is_inf,   s
    c         C` s%   |  j  | | ƒ } |  j d | | ƒ S(   s?   
    Return a condition testing whether *val* is a finite.
    t   ord(   t   fsubt   fcmp_ordered(   R   R   t   val_minus_val(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt	   is_finite6   s    c         C` s4   | j  t j ƒ  k s t ‚ |  j | t j d ƒ ƒ S(   s1   
    Bitcast a double into a 64-bit integer.
    i@   (   R   R   t   doublet   AssertionErrort   bitcastt   int(   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   f64_as_int64>   s    c         C` s4   | j  t j d ƒ k s t ‚ |  j | t j ƒ  ƒ S(   s1   
    Bitcast a 64-bit integer into a double.
    i@   (   R   R   R'   R%   R&   R$   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   int64_as_f64E   s    c         C` s4   | j  t j ƒ  k s t ‚ |  j | t j d ƒ ƒ S(   s0   
    Bitcast a float into a 32-bit integer.
    i    (   R   R   R   R%   R&   R'   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   f32_as_int32L   s    c         C` s4   | j  t j d ƒ k s t ‚ |  j | t j ƒ  ƒ S(   s0   
    Bitcast a 32-bit integer into a float.
    i    (   R   R   R'   R%   R&   R   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   int32_as_f32S   s    c         C` s"   |  j  t j j | j d ƒ | ƒ S(   sB   
    Negate real number *val*, with proper handling of zeros.
    g       €(   R    R   R   R   R   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   negate_realZ   s    c         C` sG   |  j  } t j j | | g  | D] } | j ^ q ƒ } |  j | | ƒ S(   s9   
    Call a LLVM intrinsic floating-point operation.
    (   t   moduleR   t   Functiont	   intrinsicR   t   call(   R   t   namet   argst   modt   at   intr(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   call_fp_intrinsica   s    	.c         ` s   ‡  f d †  } | S(   sŒ   
    Return an implementation factory to convert the single integral input
    argument to a float64, then defer to the *wrapped_impl*.
    c   	      ` sz   | \ } | j  d } |  j | | | t j ƒ } t t j t j ƒ } ˆ  |  | | | f ƒ } |  j | | t j | j ƒ S(   Ni    (   R2   t   castR   R   R
   t   return_type(	   t   contextR   t   sigR2   R   t
   input_typet   fpvalt	   inner_sigt   res(   t   wrapped_impl(    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   implementero   s    	(    (   R?   R@   (    (   R?   s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   _unary_int_input_wrapper_implj   s    c         C` s&   t  | ƒ } t |  t j ƒ | ƒ d  S(   N(   RA   t   lowerR   t   Integer(   t   fnt
   float_implt   impl(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   unary_math_int_imply   s    c         ` s2   t  |  t j ƒ ‡  f d †  ƒ } t |  | ƒ | S(   sO   
    Implement the math function *fn* using the LLVM intrinsic *intrcode*.
    c         ` s(   t  | ˆ  | ƒ } t |  | | j | ƒ S(   N(   R6   R   R8   (   R9   R   R:   R2   R>   (   t   intrcode(    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyRE      s    (   RB   R   t   FloatRG   (   RD   RH   RE   (    (   RH   s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   unary_math_intr}   s    !c         ` sN   | r t  j n d } ‡  ‡ f d †  } t |  t  j ƒ | ƒ t |  | ƒ | S(   s!  
    Register implementations of Python function *fn* using the
    external function named *f32extern* and *f64extern* (for float32
    and float64 inputs, respectively).
    If *int_restype* is true, then the function's return value should be
    integral, otherwise floating-point.
    c         ` sÂ   | \ } | j  } | j d } |  j | ƒ } i ˆ  t j 6ˆ t j 6| } t j | | g ƒ }	 t j	 | j  |	 d | ƒ}
 | j
 |
 | f ƒ } |  j | | | | j ƒ } t |  | | j | ƒ S(   s9   
        Implement *fn* for a types.Float input.
        i    R1   (   R-   R2   t   get_value_typeR   R   R   R   t   functionR   t   insert_pure_functionR0   R7   R8   R   (   R9   R   R:   R2   R   R3   R;   t   ltyt	   func_namet   fntyRD   R>   (   t	   f32externt	   f64extern(    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyRE   “   s    		

N(   R   t   int64t   NoneRB   RI   RG   (   RD   RQ   RR   t   int_restypet	   f_restypeRE   (    (   RQ   RR   s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   unary_math_extern‰   s
    t   log1pft   log1pt   expm1ft   expm1t   erfft   erft   erfcft   erfct   tanft   tant   asinft   asint   acosft   acost   atanft   atant   asinhft   asinht   acoshft   acosht   atanhft   atanht   sinhft   sinht   coshft   cosht   tanhft   tanhi   t   log2ft   log2t   ceilft   ceilt   floorft   floort   numba_gammaft   numba_gammat   sqrtft   sqrtt   truncft   trunct   lgammaft   lgammac         C` s.   | \ } t  | | ƒ } t |  | | j | ƒ S(   N(   R   R   R8   (   R9   R   R:   R2   R   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isnan_float_impl×   s    	c         C` s   t  j } t |  | | j | ƒ S(   N(   R   t	   false_bitR   R8   (   R9   R   R:   R2   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isnan_int_implÝ   s    	c         C` s.   | \ } t  | | ƒ } t |  | | j | ƒ S(   N(   R   R   R8   (   R9   R   R:   R2   R   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isinf_float_implã   s    	c         C` s   t  j } t |  | | j | ƒ S(   N(   R   Rƒ   R   R8   (   R9   R   R:   R2   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isinf_int_implé   s    	i   c         C` s.   | \ } t  | | ƒ } t |  | | j | ƒ S(   N(   R#   R   R8   (   R9   R   R:   R2   R   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isfinite_float_implð   s    	c         C` s   t  j } t |  | | j | ƒ S(   N(   R   t   true_bitR   R8   (   R9   R   R:   R2   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   isfinite_int_implö   s    	c         C` sl   | d j  } | j } | j t j j | | | f ƒ d | j ƒ } | j | | ƒ } t |  | | j	 | ƒ S(   Ni    s   llvm.copysign.%s(
   R   R-   t   get_or_insert_functionR   R   RL   t   intrinsic_nameR0   R   R8   (   R9   R   R:   R2   RN   R3   RD   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   copysign_float_implü   s    	c         C` só   | \ } |  j  | j d ƒ } |  j  | j d ƒ } t j | | d d ƒ} t j | | t j | ƒ f ƒ } i d d 6d d 6t | ƒ }	 | j	 j
 | d |	 ƒ}
 | j |
 | | f ƒ } t j | | | j | ƒ f ƒ } t |  | | j | ƒ S(	   Ni    i   R1   t   expt   numba_frexpfR   t   numba_frexpR$   (   t   get_data_typeR2   R8   R   t   alloca_onceR   RL   t   pointert   strR-   RŠ   R0   t   make_anonymous_structt   loadR   (   R9   R   R:   R2   R   t   flttyt   inttyt   expptrRP   t   fnameRD   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt
   frexp_impl	  s    	!!c         C` s¦   | \ } } t  |  j | j ƒ \ } } t j | | | f ƒ } i d d 6d d 6t | ƒ }	 t j | j | d |	 ƒ}
 | j	 |
 | | f ƒ } t
 |  | | j | ƒ S(   Nt   numba_ldexpfR   t   numba_ldexpR$   R1   (   t   mapR   R2   R   RL   R“   R   RM   R-   R0   R   R8   (   R9   R   R:   R2   R   R   R–   R—   RP   R™   RD   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt
   ldexp_impl  s    c         C` sp   | \ } } | j  | t j ƒ  ƒ } | j  | t j ƒ  ƒ } t t j t j t j ƒ } t |  | | | | f ƒ S(   N(   t   sitofpR   R$   R
   R   R   t   atan2_float_impl(   R9   R   R:   R2   t   yt   xt   fsig(    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   atan2_s64_impl+  s
    c         C` sp   | \ } } | j  | t j ƒ  ƒ } | j  | t j ƒ  ƒ } t t j t j t j ƒ } t |  | | | | f ƒ S(   N(   t   uitofpR   R$   R
   R   R   R    (   R9   R   R:   R2   R¡   R¢   R£   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   atan2_u64_impl3  s
    c         C` sË   t  | ƒ d k s t ‚ | j } | j d } |  j | ƒ } i d t j 6t j d k r_ d n d t j	 6| } t
 j | | | f ƒ } t j | j | d | ƒ}	 | j |	 | ƒ }
 t |  | | j |
 ƒ S(   Ni   i    t   atan2ft   win32t   atan2_fixedt   atan2R1   (   t   lenR%   R-   R2   RK   R   R   t   syst   platformR   R   RL   R   RM   R0   R   R8   (   R9   R   R:   R2   R3   t   tyRN   RO   RP   RD   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyR    ;  s    	
c         C` sˆ   | \ } } | j  | t j ƒ  ƒ } | j  | t j ƒ  ƒ } t t j t j t j ƒ } t |  | | | | f ƒ } t |  | | j | ƒ S(   N(	   RŸ   R   R$   R
   R   R   t   hypot_float_implR   R8   (   R9   R   R:   R2   R¢   R¡   R£   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   hypot_s64_implO  s    c         C` sˆ   | \ } } | j  | t j ƒ  ƒ } | j  | t j ƒ  ƒ } t t j t j t j ƒ } t |  | | | | f ƒ } t |  | | j | ƒ S(   N(	   RŸ   R   R$   R
   R   R   R¯   R   R8   (   R9   R   R:   R2   R¢   R¡   R£   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   hypot_u64_implY  s    c         ` s  | j  \ } } | | k o) | j k n s4 t ‚ | \ } } i t j d k rX d n d t j 6t j d k rw d n d t j 6| } t j | | ƒ ‰ t j d k rß t	 j
 d k rß | t d ƒ ƒ ‰  ‡  ‡ f d †  }	 n ‡ f d	 †  }	 |  j | |	 | | ƒ }
 t |  | | j |
 ƒ S(
   NR¨   t   _hypotft   hypotft   _hypott   hypoti    t   infc         ` s/   t  j |  ƒ s t  j | ƒ r" ˆ  Sˆ |  | ƒ S(   N(   t   matht   isinf(   R¢   R¡   (   R¶   t
   plat_hypot(    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt
   hypot_implt  s    c         ` s   ˆ  |  | ƒ S(   N(    (   R¢   R¡   (   R¹   (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyRº   y  s    (   R2   R8   R%   R¬   R­   R   R   R   t   ExternalFunctionR	   t   MACHINE_BITSR   t   compile_internalR   (   R9   R   R:   R2   t   xtyt   ytyR¢   R¡   R™   Rº   R>   (    (   R¶   R¹   s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyR¯   c  s    %c         C` sM   | \ } |  j  | j t j d ƒ } | j | | ƒ } t |  | | j | ƒ S(   Ni´   (   t   get_constantR8   R·   t   pit   fmulR   (   R9   R   R:   R2   R¢   t   coefR>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   radians_float_impl‚  s    	c         C` sM   | \ } |  j  | j d t j ƒ } | j | | ƒ } t |  | | j | ƒ S(   Ni´   (   RÀ   R8   R·   RÁ   RÂ   R   (   R9   R   R:   R2   R¢   RÃ   R>   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   degrees_float_impl  s    	c         C` s"   |  j  t j | ƒ } | | | ƒ S(   N(   t   get_functiont   operatort   pow(   R9   R   R:   R2   RF   (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   pow_impl˜  s    (   i   i    (   i   i   (–   t   __doc__t
   __future__R    R   R   R·   RÇ   R¬   t   numpyt   npt   llvmlite.llvmpy.coret   llvmpyt   coreR   R   t   numba.targets.imputilsR   R   t   numbaR   R   R   R	   t   numba.typingR
   t   registryRB   t   finfot   dtypet   _NP_FLT_FINFOt   maxt   FLT_MAXt   tinyt   FLT_MINt   _NP_DBL_FINFOt   DBL_MAXt   DBL_MINt   FLOAT_ABS_MASKt   FLOAT_SIGN_MASKt   DOUBLE_ABS_MASKt   DOUBLE_SIGN_MASKR   R   R#   R(   R)   R*   R+   R,   R6   RA   RG   RJ   t   FalseRW   t   fabst	   INTR_FABSR   t   INTR_EXPt   exp_implt   logt   INTR_LOGt   log_implt   log10t
   INTR_LOG10t
   log10_implt   sint   INTR_SINt   sin_implt   cost   INTR_COSt   cos_implRY   t
   log1p_implR[   t
   expm1_implR]   t   erf_implR_   t	   erfc_implRa   t   tan_implRc   t	   asin_implRe   t	   acos_implRg   t	   atan_implRi   t
   asinh_implRk   t
   acosh_implRm   t
   atanh_implRo   t	   sinh_implRq   t	   cosh_implRs   t	   tanh_implt	   PYVERSIONRu   t	   log2_implRw   t   Truet	   ceil_implRy   t
   floor_implt   gammat
   gamma_implR}   t	   sqrt_implR   t
   trunc_implR   t   lgamma_implt   isnanRI   R‚   RC   R„   R¸   R…   R†   t   isfiniteR‡   R‰   t   copysignRŒ   t   frexpRš   t   ldexpt   intcRž   Rª   RS   R¤   t   uint64R¦   R    Rµ   R°   R±   R¯   t   radiansRÄ   t   degreesRÅ   RÈ   RÉ   (    (    (    s5   lib/python2.7/site-packages/numba/targets/mathimpl.pyt   <module>   s®   "								
											$!$$$$$$
$
$