a
    BCCfR                  	   @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 G dd dej
ZG dd dZG dd dZd	d
 Zdd ZG dd dZd(ddddZdd Zdd Zde_de_d d! Zd"d# Zd$e_d%d& Zd'e_dS ))    N)
MapWrapper_FunctionWrapperc                       s,   e Zd Zdd Z fddZdd Z  ZS )LRUDictc                 C   s
   || _ d S N)_LRUDict__max_size)selfmax_size r	   U/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/integrate/_quad_vec.py__init__   s    zLRUDict.__init__c                    sD   || v }t  || |r&| | nt| | jkr@| jdd d S )NF)last)super__setitem__move_to_endlenr   popitem)r   keyvalueZexisting_key	__class__r	   r
   r      s    zLRUDict.__setitem__c                 C   s
   t  d S r   )NotImplementedError)r   otherr	   r	   r
   update   s    zLRUDict.update)__name__
__module____qualname__r   r   r   __classcell__r	   r	   r   r
   r      s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	SemiInfiniteFuncz9
    Argument transform from (start, +-oo) to (0, 1)
    c                 C   s0   || _ || _|dk rdnd| _tjjd | _d S )Nr            ?)_func_start_sgnsys
float_infomin_tmin)r   funcstartinftyr	   r	   r
   r   !   s    zSemiInfiniteFunc.__init__c                 C   s*   | j || j  d }|dkr"tjS d| S )Nr   r   )r#   r"   npinf)r   xzr	   r	   r
   get_t)   s    zSemiInfiniteFunc.get_tc                 C   sF   || j k rdS | j| jd|  |  }| |}| j||  | S d S N        r   )r'   r"   r#   r!   r   tr-   fr	   r	   r
   __call__0   s
    

zSemiInfiniteFunc.__call__Nr   r   r   __doc__r   r/   r5   r	   r	   r	   r
   r      s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	DoubleInfiniteFuncz6
    Argument transform from (-oo, oo) to (-1, 1)
    c                 C   s   || _ tjjd | _d S )Nr    )r!   r$   r%   r&   r'   )r   r(   r	   r	   r
   r   =   s    zDoubleInfiniteFunc.__init__c                 C   s    |dk rdnd}|t |d  S )Nr   r   r   )abs)r   r-   sr	   r	   r
   r/   C   s    zDoubleInfiniteFunc.get_tc                 C   s<   t || jk rdS dt | | }| |}|| | S d S r0   )r9   r'   r!   r2   r	   r	   r
   r5   G   s
    
zDoubleInfiniteFunc.__call__Nr6   r	   r	   r	   r
   r8   9   s   r8   c                 C   s   t t| S r   )r+   Zamaxr9   )r-   r	   r	   r
   	_max_normP   s    r;   c                 C   s@   zt | W S  ty:   t| dr4t|   Y S Y dS 0 d S )N
__sizeof__@   )r$   	getsizeof	TypeErrorhasattrintr<   )objr	   r	   r
   _get_sizeofT   s    
rC   c                   @   s   e Zd Zdd Zdd ZdS )_Bunchc                 K   s    |  | _| jjf i | d S r   )keys_Bunch__keys__dict__r   )r   kwargsr	   r	   r
   r   _   s    
z_Bunch.__init__c                    s    d d fdd jD S )Nz
_Bunch({})z, c                 3   s&   | ]}| d t  j|  V  qdS )=N)reprrG   ).0kr   r	   r
   	<genexpr>d   s   z"_Bunch.__repr__.<locals>.<genexpr>)formatjoinrF   rM   r	   rM   r
   __repr__c   s    z_Bunch.__repr__N)r   r   r   r   rQ   r	   r	   r	   r
   rD   ^   s   rD   N~h:0yE>2    חA'  r   Fr	   )argsc          =         s  t |}t |}|r.t|ts$|f}t| |} t|||||||	|
du rJdn|
|d	}t|rt|rt| ||d|	durtfdd|	D |d< t	dd	fi |S t|r t|r t| ||d|	durtfd
d|	D |d< t	dd	fi |}|d  f|d	d  S t|rt|r||k rFdnd	}t
| |	dur|dtfdd|	D  |d< nd|d< ||krt	dd	fi |}nt	d	d	fi |}|d | f|d	d  S t|rt|std| d| tttjjd}t|r|}n|| }d}d}ztttttd|
 }W n6 ty| } ztd|
|W Y d}~n
d}~0 0 |	du r||fg}nj|}g }t|	D ]J}t |}||  k r|k rn n
||krڐq|||f |}q|||f d}d}d}dg }d}|D ]\}}|||| |\} }!}"||j7 }|du rt| t tfrp|ttjjfv rpt}| }t |!}t |"}|t|  }#t|#n|| 7 }||!7 }||"7 }t| ||f< ||! ||f qt| d}$d	}%d}&d}'|$d|%d|&d|'di}(t|})|%}*|rt||k rt |||| }+g },d}-t!|D ]~}.|s^ q|.dkr|-||+d  kr qt"|}/|/\}0}}#||fd}1|,|0 |||1f| ||f |-|0 7 }-qN|)t$|,D ]l}2|2\}3}4}5}6}7||77 }||37 }||47 }||57 }|6D ]2}8|8\}}} }!| ||f< t%||! ||f qqt||krt |||| }+||+d k r||$}*q||k r|&}*qt|rt|s|'}*qqW d   n1 s0    Y  |}|| }!|rtt&|}9tj'|9j(tj)|9j*d tj+ fdd|D |9j*d}:t+dd |D };t+dd |D }t,||*|$k|*|(|* ||:|;d }<||!|<fS ||!fS dS )!a{  Adaptive integration of a vector-valued function.

    Parameters
    ----------
    f : callable
        Vector-valued function f(x) to integrate.
    a : float
        Initial point.
    b : float
        Final point.
    epsabs : float, optional
        Absolute tolerance.
    epsrel : float, optional
        Relative tolerance.
    norm : {'max', '2'}, optional
        Vector norm to use for error estimation.
    cache_size : int, optional
        Number of bytes to use for memoization.
    limit : float or int, optional
        An upper bound on the number of subintervals used in the adaptive
        algorithm.
    workers : int or map-like callable, optional
        If `workers` is an integer, part of the computation is done in
        parallel subdivided to this many tasks (using
        :class:`python:multiprocessing.pool.Pool`).
        Supply `-1` to use all cores available to the Process.
        Alternatively, supply a map-like callable, such as
        :meth:`python:multiprocessing.pool.Pool.map` for evaluating the
        population in parallel.
        This evaluation is carried out as ``workers(func, iterable)``.
    points : list, optional
        List of additional breakpoints.
    quadrature : {'gk21', 'gk15', 'trapezoid'}, optional
        Quadrature rule to use on subintervals.
        Options: 'gk21' (Gauss-Kronrod 21-point rule),
        'gk15' (Gauss-Kronrod 15-point rule),
        'trapezoid' (composite trapezoid rule).
        Default: 'gk21' for finite intervals and 'gk15' for (semi-)infinite
    full_output : bool, optional
        Return an additional ``info`` dictionary.
    args : tuple, optional
        Extra arguments to pass to function, if any.

        .. versionadded:: 1.8.0

    Returns
    -------
    res : {float, array-like}
        Estimate for the result
    err : float
        Error estimate for the result in the given norm
    info : dict
        Returned only when ``full_output=True``.
        Info dictionary. Is an object with the attributes:

            success : bool
                Whether integration reached target precision.
            status : int
                Indicator for convergence, success (0),
                failure (1), and failure due to rounding error (2).
            neval : int
                Number of function evaluations.
            intervals : ndarray, shape (num_intervals, 2)
                Start and end points of subdivision intervals.
            integrals : ndarray, shape (num_intervals, ...)
                Integral for each interval.
                Note that at most ``cache_size`` values are recorded,
                and the array may contains *nan* for missing items.
            errors : ndarray, shape (num_intervals,)
                Estimated integration error for each interval.

    Notes
    -----
    The algorithm mainly follows the implementation of QUADPACK's
    DQAG* algorithms, implementing global error control and adaptive
    subdivision.

    The algorithm here has some differences to the QUADPACK approach:

    Instead of subdividing one interval at a time, the algorithm
    subdivides N intervals with largest errors at once. This enables
    (partial) parallelization of the integration.

    The logic of subdividing "next largest" intervals first is then
    not implemented, and we rely on the above extension to avoid
    concentrating on "small" intervals only.

    The Wynn epsilon table extrapolation is not used (QUADPACK uses it
    for infinite intervals). This is because the algorithm here is
    supposed to work on vector-valued functions, in an user-specified
    norm, and the extension of the epsilon algorithm to this case does
    not appear to be widely agreed. For max-norm, using elementwise
    Wynn epsilon could be possible, but we do not do this here with
    the hope that the epsilon extrapolation is mainly useful in
    special cases.

    References
    ----------
    [1] R. Piessens, E. de Doncker, QUADPACK (1983).

    Examples
    --------
    We can compute integrations of a vector-valued function:

    >>> from scipy.integrate import quad_vec
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> alpha = np.linspace(0.0, 2.0, num=30)
    >>> f = lambda x: x**alpha
    >>> x0, x1 = 0, 2
    >>> y, err = quad_vec(f, x0, x1)
    >>> plt.plot(alpha, y)
    >>> plt.xlabel(r"$\alpha$")
    >>> plt.ylabel(r"$\int_{0}^{2} x^\alpha dx$")
    >>> plt.show()

    Ngk15)	epsabsepsrelnorm
cache_sizelimitworkerspoints
quadraturefull_output)r)   r*   c                 3   s   | ]}  |V  qd S r   r/   rK   Zxpf2r	   r
   rN          zquad_vec.<locals>.<genexpr>r_   r   r   c                 3   s   | ]}  |V  qd S r   rb   rc   rd   r	   r
   rN      rf   r   r   c                 3   s   | ]}  |V  qd S r   rb   rc   rd   r	   r
   rN     rf   zinvalid integration bounds a=z, b=)NmaxrT         )NZgk21rX   ZtrapzZ	trapezoidzunknown quadrature    zTarget precision reached.zTarget precision not reached.z<Target precision could not be reached due to rounding error.zNon-finite values encountered.   )dtypec                    s$   g | ]} |d  |d f qS r   rj   )getrK   r.   )dummyinterval_cacher	   r
   
<listcomp>  s   zquad_vec.<locals>.<listcomp>c                 S   s   g | ]}|d   qS rg   r	   rp   r	   r	   r
   rs     rf   c                 S   s   g | ]}|d  |d gqS rn   r	   rp   r	   r	   r
   rs     rf   )nevalsuccessstatusmessage	intervals	integralserrors)-float
isinstancetupler   dictr+   isfiniteisinfr   quad_vecr8   
ValueErrorr;   Zlinalgr[   callable_quadrature_gk21_quadrature_gk15_quadrature_trapezoidKeyErrorsortedappendnum_evalcomplexr9   rC   r   copyheapqheapifyr   r   rh   rangeheappoppop_subdivide_intervalheappushZasarrayfullshapenanrm   arrayrD   )=r4   abrY   rZ   r[   r\   r]   r^   r_   r`   ra   rW   rH   resZsgnZ
norm_funcs	norm_funcZparallel_countZmin_intervals_quadratureeZinitial_intervalsprevpZglobal_integralZglobal_errorZrounding_errorrx   rt   x1x2ZigerrZrndZcache_countZ	CONVERGEDZNOT_CONVERGEDZROUNDING_ERRORZNOT_A_NUMBERZ
status_msgZ
mapwrapperZierZtolZ
to_processZerr_sumjintervalZneg_old_errold_intpartsdintderr
dround_errZsubintdnevalr-   Zres_arrry   rz   infor	   )rq   re   rr   r
   r   h   sH   x

	
 

&
&






(

r   c                 C   s  | \}}}}|\}}}}d||  }	t |dddkrDt|j|}|||	||\}
}}|j}||	|||\}}}||j7 }|d u r|||||\}}}||j7 }t |dddkr| j}|
| | }|| | }|| }||	|
|f|	|||ff}|||||fS )Nr    r\   r   )getattr	functools	lru_cacher\   r   
cache_infomisses)rW   r   r4   r   r   Zold_errr   r   r   cs1Zerr1Zround1r   s2Zerr2Zround2_r   r   r   Zsubintervalsr	   r	   r
   r     s&    


r   c                 C   s   d| |  }|| }||}||}d||   |d|  |  }dt ||   t||dt||  t||  d }	d||   ||  }
dt||
|  }|||	fS )z(
    Composite trapezoid quadrature
    r    g      ?rj   gؗҬ<gUUUUUU?)r9   r{   )r   r   r4   r   Zx3f1re   Zf3r   	round_errr   r   r	   r	   r
   r     s    
r   	   rk   c                 C   s  dgt | }d| |  }d||   }	d}
d}tt |D ]D}|||	||   }|||< || }|
|| 7 }
||t| 7 }q:d}tt |D ] }||| |d| d   7 }qd}|
d }tt |D ] }||| t|| |  7 }qt||
| |	 }t|||	 }|dkr>|dkr>|tdd| | d	  }tjj}t|d
| |	 | }|tjjkrvt||}|	|
 ||fS )z*
    Generic Gauss-Kronrod quadrature
    r1   r    rj   r   g       @r   g      ?   g      ?2   )	r   r   r9   r{   r&   r$   r%   epsilonrh   )r   r   r4   r   r-   wvZfvr   hZs_kZs_k_absiffvvZs_gZs_k_dabsZy0r   ZdabsZepsr   r	   r	   r
   _quadrature_gk  s6    
r   c                 C   s    d}d}d}t | ||||||S )z9
    Gauss-Kronrod 21 quadrature with error estimate
    )g*'il?g*>*?g?g^?gbltu?g"?g @?gj	?g7^)U?gzxP?r   gzxPÿg7^)Uҿgj	ۿg @g"gbltug^gg*>*g*'il)
b_?x8!?1 ?Uz;?p?r   r   r   r   r   )?[?B@v?碙?"75?牳׷?珁 ?-]+?Hi&>?la{F?o?g|+!?r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r   r-   r   r   r	   r	   r
   r     s    r      c                 C   s    d}d}d}t | ||||||S )z9
    Gauss-Kronrod 15 quadrature with error estimate
    )g	M ?g)b|_?g>'?g֡㛟?g$:?gb]?gw.?r1   gw.ʿgb]ٿg$:g֡㛟g>'g)b|_g	M )Wm?D=q?=+No?g/<׿?r   r   r   )ptg[|?a{&?HӺ?F ?\}f?ah]?؜*?g	O?r   r   r   r   r   r   r   r   r   r	   r	   r
   r   ^  s    	r      )	rR   rS   rT   rU   rV   r   NNF)r$   r   r   collectionsr   numpyr+   Zscipy._lib._utilr   r   OrderedDictr   r   r8   r;   rC   rD   r   r   r   r\   r   r   r   r   r	   r	   r	   r
   <module>   s8   

    L3A2