ó
Ê½÷Xc           @` 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 m	 Z	 m
 Z
 d  d l m Z d  d l m Z y d  d l Z Wn e k
 r™ n Xd 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 „  Z d „  Z d „  Z d „  Z y. d  d l Z d  d l Z d e e ƒ k Z  Wn e k
 r…e! Z  n Xd e" f d „  ƒ  YZ# d e j$ e% d „ Z& d „  Z' d „  Z( d  d d „ Z) d S(   i    (   t   divisiont   print_functiont   absolute_importN(   t   dect   assert_(   t   reraise(   t   assert_func_equalt   Argc           B` s3   e  Z d  Z e j e j e e d „ Z d „  Z RS(   s†   
    Generate a set of numbers on the real axis, concentrating on
    'interesting' regions and covering all orders of magnitude.
    c         C` s†   | |  _  | |  _ | |  _ | |  _ |  j  t j k rT t j t ƒ j d |  _  n  |  j t j k r‚ t j t ƒ j d |  _ n  d  S(   Ni   (	   t   at   bt   inclusive_at   inclusive_bt   npt   inft   finfot   floatt   max(   t   selfR   R	   R
   R   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   __init__   s    				c   
      C` s1  t  d t d | ƒ ƒ } t  d t d | ƒ ƒ } t  d | | | ƒ } t j d d | ƒ } t j t j d d t  d	 | d
 ƒ ƒ d d d d f } |  j d	 k r!|  j d	 k r!t j t j d d d | d
 ƒ t j d t j |  j ƒ d | d
 ƒ f } t j d d d | d ƒ } nƒ|  j d	 k  o>|  j k  n rt j t j d d d | d ƒ t j d t j |  j ƒ d | d ƒ t j d d d | d ƒ t j d t j |  j ƒ d | d ƒ f } t j t j d d d | d
 ƒ t j d d d | d
 ƒ f } nŒ |  j d	 k  r˜t j t j d d d | d
 ƒ t j d t j |  j ƒ d | d
 ƒ f } t j d d d | d ƒ } n g  } g  } t j | | | | d	 f }	 |  j	 rß|	 |	 |  j k }	 n |	 |	 |  j k }	 |  j
 r|	 |	 |  j k }	 n |	 |	 |  j k  }	 t j |	 ƒ S(   s7   Return an array containing approximatively `n` numbers.i   g333333Ó?gš™™™™™É?i   iÿÿÿÿi   iöÿÿÿi
   i    i   i÷ÿÿÿg      Àg      @i	   iâÿÿÿi   (   R   t   intR   t   linspacet   r_R   R	   t   logspacet   log10R
   R   t   unique(
   R   t   nt   n1t   n2t   n3t   v1t   v2t   v3t   v4t   v(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   values&   sF    %- "&/%/!		(   t   __name__t
   __module__t   __doc__R   R   t   TrueR   R"   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR      s   
t   FixedArgc           B` s   e  Z d  „  Z d „  Z RS(   c         C` s   t  j | ƒ |  _ d  S(   N(   R   t   asarrayt   _values(   R   R"   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR   V   s    c         C` s   |  j  S(   N(   R)   (   R   R   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR"   Y   s    (   R#   R$   R   R"   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR'   U   s   	t
   ComplexArgc           B` s@   e  Z e e j e j ƒ e e j e j ƒ d  „ Z d „  Z RS(   c         C` s4   t  | j | j ƒ |  _ t  | j | j ƒ |  _ d  S(   N(   R   t   realt   imag(   R   R   R	   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR   ^   s    c         C` st   t  d t t j | ƒ ƒ ƒ } |  j j | ƒ } |  j j | ƒ } | d  d  … d  f d | d  d  d  … f j ƒ  S(   Ni   y              ð?(	   R   R   R   t   sqrtR+   R"   R,   t   Nonet   ravel(   R   R   t   mt   xt   y(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR"   b   s    (   R#   R$   t   complexR   R   R   R"   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR*   ]   s   /t   IntArgc           B` s    e  Z d  d d „ Z d „  Z RS(   iüÿÿiè  c         C` s   | |  _  | |  _ d  S(   N(   R   R	   (   R   R   R	   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR   j   s    	c         C` sŽ   t  |  j |  j ƒ j t d | d | d ƒ ƒ j t ƒ } t j d d ƒ } t j	 t j
 | | f ƒ } | | |  j k | |  j k  @} | S(   Ni   i   i   iûÿÿÿ(   R   R   R	   R"   R   t   astypeR   R   t   arangeR   R   (   R   R   R   R   R!   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR"   n   s
    < (   R#   R$   R   R"   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR4   i   s   c         C` sõ   t  |  t j ƒ r! |  j ƒ  } nÐ t |  ƒ } t j g  |  D]! } t  | t ƒ rU d n d ^ q: ƒ } | | t | ƒ j t	 ƒ d } g  } x3 t
 |  | ƒ D]" \ } } | j | j | ƒ ƒ q› Wt j t j t j | Œ  Œ  ƒ j | d ƒ j } | S(   Ng      ø?g      ð?i   iÿÿÿÿ(   t
   isinstanceR   t   ndarrayt   copyt   lenR(   R*   t   sumR5   R   t   zipt   appendR"   t   arrayt   broadcast_arrayst   ix_t   reshapet   T(   t   argspecR   t   argst   nargst   spect   msR0   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   get_argsv   s    7!0t
   MpmathDatac           B` sA   e  Z d d d d  d d e e e d d „
 Z d „  Z d „  Z RS(   iˆ  gH¯¼šò×z>gYóøÂn¥c         C` s6  | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _ | |  _	 t
 |  j t j ƒ r t j |  j j t j ƒ |  _ n. t g  |  j D] } t
 | t ƒ ^ q ƒ |  _ |
 |  _ | |  _ | sã | d k rø t | d d  ƒ } n  | s| d k r t | d d  ƒ } n  | |  _ | |  _ d  S(   Ns   <lambda>R#   (   t
   scipy_funct   mpmath_funct   arg_spect   dpst   precR   t   rtolt   atolt   ignore_inf_signt   nan_okR7   R   R8   t
   issubdtypet   dtypet   complexfloatingt
   is_complext   anyR*   t   distinguish_nan_and_inft   getattrR.   t   namet   param_filter(   R   RJ   RK   RL   RZ   RM   RN   R   RO   RP   RQ   RX   RR   R[   t   arg(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR   ‡   s*    										!.			c         ` s°  t  j j d ƒ t ˆ j ˆ j ƒ } t j j t j j	 } } zQˆ j d  k	 r_ ˆ j g } n	 d g } ˆ j	 d  k	 r‰ ˆ j	 t j _	 n  t  j | j t  j ƒ r³ t ‰ d „  ‰  n d „  ‰  d „  ‰ xÆ t | ƒ D]¸ \ } } | t j _ yc t ˆ j ‡  ‡ ‡ f d †  | d t d ˆ j d	 ˆ j d
 ˆ j d ˆ j d ˆ j d ˆ j ƒPWqÒ t k
 r‰| t | ƒ d k rŠt t j ƒ  Œ  qŠqÒ XqÒ WWd  | | t j _ t j _	 Xd  S(   NiÒ  i   c         S` s   t  j t |  ƒ ƒ S(   N(   t   mpmatht   mpcR3   (   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   mptype¸   s    c         S` s   t  j t |  ƒ ƒ S(   N(   R]   t   mpfR   (   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR_   »   s    c         S` s>   t  |  j ƒ d d t  |  j ƒ k r- t j St |  j ƒ Sd  S(   Ng¼‰Ø—²Òœ<i   (   t   absR,   R+   R   t   nant	   mpf2float(   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   pytype¾   s    &c          ` s   ˆ ˆ j  t ˆ  |  ƒ Œ  ƒ S(   N(   RK   t   map(   R   (   R_   Rd   R   (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   <lambda>Ê   s    t
   vectorizedRO   RP   RQ   RX   RR   R[   i   (   R   t   randomt   seedRH   RL   R   R]   t   mpRM   RN   R.   RS   RT   RU   t   mpc2complext	   enumerateR   RJ   t   FalseRO   RP   RQ   RX   RR   R[   t   AssertionErrorR:   R   t   syst   exc_info(   R   t   argarrt   old_dpst   old_prect   dps_listt   jRM   (    (   R_   Rd   R   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   check¢   s>    							
c         C` s)   |  j  r d |  j f Sd |  j f Sd  S(   Ns   <MpmathData: %s (complex)>s   <MpmathData: %s>(   RV   RZ   (   R   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   __repr__Ù   s    	N(   R#   R$   R.   Rm   R&   R   Rv   Rw   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyRI   †   s   	7c          O` s   t  |  | Ž  } | j ƒ  d  S(   N(   RI   Rv   (   R   t   kwt   d(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   assert_mpmath_equalà   s    c         C` s   t  j t d ƒ |  ƒ S(   Ns8       Test not yet functional (too slow), needs more work.(   R   t   skipifR&   (   t   func(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   nonfunctional_tooslowå   s    c         C` s"   t  t j |  d d d d d ƒƒ S(   sá   
    Convert an mpf to the nearest floating point number. Just using
    float directly doesn't work because of results like this:

    with mp.workdps(50):
        float(mpf("0.99999999999999999")) = 0.9999999999999999

    i   t	   min_fixedi    t	   max_fixed(   R   R]   t   nstr(   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyRc   í   s    	c         C` s   t  t |  j ƒ t |  j ƒ ƒ S(   N(   R3   Rc   R+   R,   (   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyRk   ù   s    c         ` s   d „  ‰ ‡  ‡ f d †  } | S(   Nc         S` s*   t  |  t j ƒ r t |  ƒ St |  ƒ Sd  S(   N(   R7   R]   R^   R3   R   (   R1   (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   tofloatþ   s    
c          ` s   t  j j d t t ˆ |  ƒ ƒ f ƒ t  j j ƒ  z' ˆ  |  | Ž  } t  j j d | ƒ Wd  t  j j d ƒ t  j j ƒ  X| S(   Ns   %r: s   -> %rs   
(   Ro   t   stderrt   writet   tupleRe   t   flush(   R   Rx   t   r(   R|   R   (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   wrap  s    &(    (   R|   R‡   (    (   R|   R   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt
   trace_argsý   s    	
t	   setitimert   TimeoutErrorc           B` s   e  Z RS(    (   R#   R$   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyRŠ     s   g      à?c         ` sC   t  r- | r- d „  ‰ ‡  ‡ ‡ f d †  } n ‡  ‡ f d †  } | S(   s  
    Decorator for setting a timeout for pure-Python functions.

    If the function does not return within `timeout` seconds, the
    value `return_val` is returned instead.

    On POSIX this uses SIGALRM by default. On non-POSIX, settrace is
    used. Do not use this with threads: the SIGALRM implementation
    does probably not work well. The settrace implementation only
    traces the current thread.

    The settrace implementation slows down execution speed. Slowdown
    by a factor around 10 is probably typical.
    c         S` s   t  ƒ  ‚ d  S(   N(   RŠ   (   t   signumt   frame(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   sigalrm_handler,  s    c         ` s   ‡  ‡ ‡ ‡ f d †  } | S(   Nc          ` s€   t  j  t  j ˆ ƒ } t  j t  j ˆ ƒ z* y ˆ  |  | Ž  SWn t k
 rP ˆ SXWd  t  j t  j d ƒ t  j  t  j | ƒ Xd  S(   Ni    (   t   signalt   SIGALRMR‰   t   ITIMER_REALRŠ   (   R   Rx   t   old_handler(   R|   t
   return_valR   t   timeout(    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR‡   0  s     	(    (   R|   R‡   (   R’   R   R“   (   R|   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   deco/  s    
c         ` s   ‡  ‡ ‡ f d †  } | S(   Nc          ` sw   t  j  ƒ  ‰  ‡  ‡ f d †  } t j | ƒ z7 y ˆ |  | Ž  SWn t k
 r` t j d  ƒ ˆ SXWd  t j d  ƒ Xd  S(   Nc         ` s&   t  j  ƒ  ˆ  ˆ k r" t ƒ  ‚ n  d  S(   N(   t   timeRŠ   R.   (   RŒ   t   eventR\   (   t
   start_timeR“   (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   trace@  s    (   R•   Ro   t   settraceRŠ   R.   (   R   Rx   R˜   (   R|   R’   R“   (   R—   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR‡   =  s     	(    (   R|   R‡   (   R’   R“   (   R|   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR”   <  s    (   t   POSIX(   R“   R’   t   use_sigalrmR”   (    (   R’   R   R“   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   time_limited  s
    	c         ` s   ‡  f d †  } | S(   s9   Decorate function to return nan if it raises an exceptionc          ` s-   y ˆ  |  | Ž  SWn t  k
 r( t j SXd  S(   N(   t	   ExceptionR   Rb   (   R   Rx   (   R|   (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR‡   R  s    (    (   R|   R‡   (    (   R|   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   exception_to_nanP  s    c         ` s   ‡  f d †  } | S(   s1   Decorate function to return nan if it returns infc          ` s)   ˆ  |  | Ž  } t  j | ƒ s% t  j S| S(   N(   R   t   isfiniteRb   (   R   Rx   R!   (   R|   (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyR‡   \  s    (    (   R|   R‡   (    (   R|   s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt
   inf_to_nanZ  s    g—ÔFFõg<c         C` sÿ  y t  |  ƒ Wn t k
 r- t |  ƒ }  n Xt  | ƒ } t  |  ƒ | k r[ t d ƒ ‚ n  g  } xs t | ƒ D]e } y> t t j |  | | | ƒ | | t j | | ƒ k ƒ Wqn t k
 rÒ | j | ƒ qn Xqn Wt	 t
 t j | ƒ ƒ ƒ } d g } | j d j t  | ƒ | ƒ ƒ x¿ | D]· } t j |  | | d d d d ƒ}	 t j | | | d d d d ƒ}
 | | d k r„d } n5 t j |  | | | | | ƒ } t j | d ƒ } | j d	 j | |	 |
 | ƒ ƒ q!W| rût t d
 j | ƒ ƒ n  d S(   s}   
    Compare lists of mpmath.mpf's or mpmath.mpc's directly so that it
    can be done to higher precision than double.

    s   Lengths of inputs not equal.t    s4   Bad results ({} out of {}) for the following points:R~   i    R   R   i   s   {}: {} != {} (rdiff {})s   
N(   R:   t	   TypeErrort   listRn   t   rangeR   R]   t   fabsR=   R   Ra   R   R   t   formatR€   Rm   t   join(   t   rest   stdRP   RO   R   t   failurest   kt   ndigitst   msgt   resrept   stdrept   rdiff(    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   mp_assert_allclosed  s6    >	""	##(*   t
   __future__R    R   R   Ro   R•   t   numpyR   t   numpy.testingR   R   t   scipy._lib.sixR   t   scipy.special._testutilsR   R]   t   ImportErrort   objectR   R'   R*   R4   RH   RI   Rz   R}   Rc   Rk   Rˆ   t   posixRŽ   t   dirRš   Rm   R   RŠ   Rb   R&   Rœ   Rž   R    R±   (    (    (    s9   /tmp/pip-build-7oUkmx/scipy/scipy/special/_mptestutils.pyt   <module>   s@   ?	Z					
4	
	
