ó
<Zc           @   s   d  d  d „ Z  d „  Z d S(   t   printc            s‹   ˆ s d „  ‰ n' ˆ d k r9 d g ‰ ‡ f d †  ‰ n  ˆ sK d „  ‰ n' ˆ d k rr d g ‰ ‡ f d †  ‰ n  ‡  ‡ ‡ f d †  } | S(   sz  
    Returns a wrapped copy of *f* that monitors evaluation by calling
    *input* with every input (*args*, *kwargs*) passed to *f* and
    *output* with every value returned from *f*. The default action
    (specify using the special string value ``'print'``) is to print
    inputs and outputs to stdout, along with the total evaluation
    count::

        >>> from mpmath import *
        >>> mp.dps = 5; mp.pretty = False
        >>> diff(monitor(exp), 1)   # diff will eval f(x-h) and f(x+h)
        in  0 (mpf('0.99999999906867742538452148'),) {}
        out 0 mpf('2.7182818259274480055282064')
        in  1 (mpf('1.0000000009313225746154785'),) {}
        out 1 mpf('2.7182818309906424675501024')
        mpf('2.7182808')

    To disable either the input or the output handler, you may
    pass *None* as argument.

    Custom input and output handlers may be used e.g. to store
    results for later analysis::

        >>> mp.dps = 15
        >>> input = []
        >>> output = []
        >>> findroot(monitor(sin, input.append, output.append), 3.0)
        mpf('3.1415926535897932')
        >>> len(input)  # Count number of evaluations
        9
        >>> print(input[3]); print(output[3])
        ((mpf('3.1415076583334066'),), {})
        8.49952562843408e-5
        >>> print(input[4]); print(output[4])
        ((mpf('3.1415928201669122'),), {})
        -1.66577118985331e-7

    c         S   s   d  S(   N(   t   None(   t   v(    (    s/   lib/python2.7/site-packages/mpmath/usertools.pyt   <lambda>*   s    R    i    c            s6   |  \ } } d ˆ  d | | f GHˆ  d c d 7<d  S(   Ns   in  %s %r %ri    i   (    (   t   valuet   argst   kwargs(   t   incount(    s/   lib/python2.7/site-packages/mpmath/usertools.pyt   input-   s    c         S   s   d  S(   N(   R   (   R   (    (    s/   lib/python2.7/site-packages/mpmath/usertools.pyR   2   s    c            s'   d ˆ  d |  f GHˆ  d c d 7<d  S(   Ns	   out %s %ri    i   (    (   R   (   t   outcount(    s/   lib/python2.7/site-packages/mpmath/usertools.pyt   output5   s    c             s-   ˆ |  | f ƒ ˆ  |  | Ž  } ˆ | ƒ | S(   N(    (   R   R   R   (   t   fR   R
   (    s/   lib/python2.7/site-packages/mpmath/usertools.pyt   f_monitored8   s    
(    (   R   R   R
   R   (    (   R   R   R   R	   R
   s/   lib/python2.7/site-packages/mpmath/usertools.pyt   monitor   s    '		c            s\  ˆ j  d ƒ } d ˆ k r% ˆ d =n  ˆ s1 ˆ r t ˆ ƒ d k ri ˆ ri ˆ d ‰  ‡  ‡ f d †  } q‡ ‡ ‡ ‡ f d †  } n ˆ } d d l m } | ƒ  } | ƒ  } | ƒ  } | | }	 |	 d k sÎ | rÒ |	 Sxƒ t d	 ƒ D]u }
 | ƒ  } | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  | ƒ  } t |	 | | d
 ƒ }	 qß W|	 S(   sò   
    Returns time elapsed for evaluating ``f()``. Optionally arguments
    may be passed to time the execution of ``f(*args, **kwargs)``.

    If the first call is very quick, ``f`` is called
    repeatedly and the best time is returned.
    t   oncei   i    c              s
   ˆ ˆ  ƒ S(   N(    (    (   t   argR   (    s/   lib/python2.7/site-packages/mpmath/usertools.pyR   M   s    c              s   ˆ ˆ  ˆ Ž  S(   N(    (    (   R   R   R   (    s/   lib/python2.7/site-packages/mpmath/usertools.pyR   O   s    iÿÿÿÿ(   t   default_timergš™™™™™©?i   i
   (   t   gett   lent   timeitR   t   ranget   min(   R   R   R   R   t   gt   clockt   t1R   t   t2t   tt   i(    (   R   R   R   R   s/   lib/python2.7/site-packages/mpmath/usertools.pyt   timing?   s>    

	 	 	 
	         	N(   R   R   (    (    (    s/   lib/python2.7/site-packages/mpmath/usertools.pyt   <module>   s   =