a
    ¬<bΥ  γ                   @   s   dddZ dd ZdS )Ϊprintc                    sd   sdd ndkr(dgfdds6dd ndkrPdgfdd	 fd
d}|S )az  
    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© ©Ϊvr   r   ϊ`/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/mpmath/usertools.pyΪ<lambda>*   σ    zmonitor.<locals>.<lambda>r   ι    c                    s2   | \}}t d d ||f   d  d7  < d S )Nzin  %s %r %rr	   ι   ©r   )ΪvalueΪargsΪkwargs)Ϊincountr   r   Ϊinput-   s    zmonitor.<locals>.inputc                 S   s   d S r   r   r   r   r   r   r   2   r   c                    s(   t d d | f   d  d7  < d S )Nz	out %s %rr	   r
   r   )r   )Ϊoutcountr   r   Ϊoutput5   s    zmonitor.<locals>.outputc                     s&   | |f  | i |€}| |S r   r   )r   r   r   )Ϊfr   r   r   r   Ϊf_monitored8   s    zmonitor.<locals>.f_monitoredr   )r   r   r   r   r   )r   r   r   r   r   r   Ϊmonitor   s    '

r   c                    s     d‘}dv rd= s rZtdkrHsHd   fdd}q^fdd}n}ddlm} | }| }| }|| }	|	dks|r|	S td	D ]^}
| }|  |  |  |  |  |  |  |  |  |  | }t|	|| d
 }	q|	S )zς
    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.
    Ϊoncer
   r	   c                      s    S r   r   r   )Ϊargr   r   r   r   M   r   ztiming.<locals>.<lambda>c                      s    i €S r   r   r   )r   r   r   r   r   r   O   r   )Ϊdefault_timerg©?ι   ι
   )ΪgetΪlenZtimeitr   ΪrangeΪmin)r   r   r   r   ΪgZclockΪt1r   Ϊt2ΪtΪir   )r   r   r   r   r   Ϊtiming?   s&    
<r$   N)r   r   )r   r$   r   r   r   r   Ϊ<module>   s   
=