
    ^MhV                     6   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Zd dlm	Z	m
Z
  G d dej                  Z G d d          Z G d d          Zd	 Zd
 Z G d d          Z	 	 d dddZd Zd Zde_        de_        d Zd Zde_        d Zde_        dS )!    N)
MapWrapper_FunctionWrapperc                   *     e Zd Zd Z fdZd Z xZS )LRUDictc                     || _         d S N)_LRUDict__max_size)selfmax_sizes     Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/integrate/_quad_vec.py__init__zLRUDict.__init__   s    "    c                     || v }t                                          ||           |r|                     |           d S t          |           | j        k    r|                     d           d S d S )NF)last)super__setitem__move_to_endlenr	   popitem)r
   keyvalueexisting_key	__class__s       r   r   zLRUDict.__setitem__   s}    tC''' 	%S!!!!!YY((LLeL$$$$$ )(r   c                     t                      r   )NotImplementedError)r
   others     r   updatezLRUDict.update   s    !###r   )__name__
__module____qualname__r   r   r   __classcell__)r   s   @r   r   r      sV        # # #% % % % %$ $ $ $ $ $ $r   r   c                   $    e Zd ZdZd Zd Zd ZdS )SemiInfiniteFuncz9
    Argument transform from (start, +-oo) to (0, 1)
    c                 r    || _         || _        |dk     rdnd| _        t          j        j        dz  | _        d S )Nr            ?)_func_start_sgnsys
float_infomin_tmin)r
   funcstartinftys       r   r   zSemiInfiniteFunc.__init__"   s:    
!))BB	 ^',


r   c                 Z    | j         || j        z
  z  dz   }|dk    rt          j        S d|z  S )Nr&   r   )r*   r)   npinf)r
   xzs      r   get_tzSemiInfiniteFunc.get_t*   s2    IT[)A-666M1ur   c                     || j         k     rdS | j        | j        d|z
  z  |z  z   }|                     |          }| j        ||z  z  |z  S N        r&   )r.   r)   r*   r(   r
   tr5   fs       r   __call__zSemiInfiniteFunc.__call__1   sS    tz>>3di1q51A55A

1A9A&**r   Nr   r   r    __doc__r   r7   r>    r   r   r#   r#      sK         - - -  + + + + +r   r#   c                   $    e Zd ZdZd Zd Zd ZdS )DoubleInfiniteFuncz6
    Argument transform from (-oo, oo) to (-1, 1)
    c                 F    || _         t          j        j        dz  | _        d S )Nr'   )r(   r+   r,   r-   r.   )r
   r/   s     r   r   zDoubleInfiniteFunc.__init__>   s     
 ^',


r   c                 @    |dk     rdnd}|t          |          dz   z  S )Nr   r%   r&   )abs)r
   r5   ss      r   r7   zDoubleInfiniteFunc.get_tD   s(    a%%BBQCFFQJr   c                     t          |          | j        k     rdS dt          |          z
  |z  }|                     |          }||z  |z  S r9   )rF   r.   r(   r;   s       r   r>   zDoubleInfiniteFunc.__call__H   sK    q66DJ3SVVq A

1AEQ;r   Nr?   rA   r   r   rC   rC   :   sK         - - -         r   rC   c                 D    t          j        t          |                     S r   )r3   amaxrF   )r5   s    r   	_max_normrK   Q   s    73q66??r   c                     	 t          j        |           S # t          $ r7 t          | d          r#t	          |                                           cY S Y dS w xY w)N
__sizeof__@   )r+   	getsizeof	TypeErrorhasattrintrM   )objs    r   _get_sizeofrT   U   si    }S!!!   3%% 	)s~~''(((((rr	s    ;AAc                       e Zd Zd Zd ZdS )_Bunchc                 \    |                                 | _         | j        j        di | d S )NrA   )keys_Bunch__keys__dict__r   )r
   kwargss     r   r   z_Bunch.__init__`   s2    kkmm&&v&&&&&r   c                 \     d                      fd j        D                       }d| dS )Nz, c              3   V   K   | ]#}| d t          j        |                    V  $dS )=N)reprrZ   ).0kr
   s     r   	<genexpr>z"_Bunch.__repr__.<locals>.<genexpr>e   sQ       $
 $
01q++4a())++$
 $
 $
 $
 $
 $
r   z_Bunch())joinrY   )r
   key_value_pairss   ` r   __repr__z_Bunch.__repr__d   sQ    )) $
 $
 $
 $
59[$
 $
 $
 
 
 ,++++r   N)r   r   r    r   rf   rA   r   r   rV   rV   _   s2        ' ' ', , , , ,r   rV   N~h:0yE>2    חA'  r&   FrA   )argsc                  >?@ t          |          }t          |          }|r(t          |t                    s|f}t          | |          } t	          |||||||	|
dn|
|	  	        }t          j        |          rUt          j        |          rAt          | ||          ?|	t          ?fd|	D                       |d<   t          ?ddfi |S t          j        |          rjt          j        |          rVt          | ||          ?|	t          ?fd	|	D                       |d<   t          ?ddfi |}|d          f|dd         z   S t          j        |          rt          j        |          r~||k     rd
nd}t          |           ?|	"dt          ?fd|	D                       z   |d<   nd|d<   ||k    rt          ?d
dfi |}nt          ?ddfi |}|d         |z  f|dd         z   S t          j        |          rt          j        |          st          d| d|           t          t          t
          j        j        d}t          |          r|}n||         }d}d}	 t           t           t"          t$          t$          d|
         }n%# t&          $ r}t          d|
          |d}~ww xY w|
dk    rd}t)          j        |t,          d           |	||fg}nl|}g }t/          |	          D ]A}t          |          }||cxk     r|k     r	n n||k    r(|                    ||f           |}B|                    ||f           d}d}d}d@g }d}|D ]\  }}  ||| | |          \  }!}"}#||j        z  }|t          |!t           t4          f          r!|t          t
          j        j        fv rt6          }|!}t          |"          }t          |#          }|t9          |!          z  }$t;          |$          @n||!z  }||"z  }||#z  }t=          j        |!          @|| f<   |                    |" || f           t?          j         |           d}%d}&d}'d}(|%d|&d|'d|(di})tC          |          5 }*|&}+|rtE          |          |k     rtG          || ||          z            },g }-d}.tI          |          D ]p}/|s nk|/dk    r|.||,dz  z
  k    r nWt?          j%        |          }0|0\  }1}}@&                    ||fd          }2|-                    |1 |||2f| ||f           |.|1 z  }.q |*tN          |-          D ]J}3|3\  }4}5}6}7}8||8z  }||4z  }||5z  }||6z  }|7D ])}9|9\  }} }!}"|!@|| f<   t?          j(        ||" || f           *KtE          |          |k    r1tG          || ||          z            },||,dz  k     r|%}+nJ||k     r|'}+nAt          j        |          rt          j        |          s|(}+n|rtE          |          |k     ddd           n# 1 swxY w Y   |}||z   }"|rt          j)        |          }:t          j*        |:j+        t
          j,        |:j-                  >t          j.        >@fd|D             |:j-                  };t          j.        d |D                       }<t          j.        d  |D                       }t_          ||+|%k    |+|)|+         ||;|<!          }=||"|=fS ||"fS )"ai  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()

    When using the argument `workers`, one should ensure
    that the main module is import-safe, for instance
    by rewriting the example above as:

    .. code-block:: python

        from scipy.integrate import quad_vec
        import numpy as np
        import matplotlib.pyplot as plt

        alpha = np.linspace(0.0, 2.0, num=30)
        x0, x1 = 0, 2
        def f(x):
            return x**alpha

        if __name__ == "__main__":
            y, err = quad_vec(f, x0, x1, workers=2)
    Ngk15)	epsabsepsrelnorm
cache_sizelimitworkerspoints
quadraturefull_output)r0   r1   c              3   B   K   | ]}                     |          V  d S r   r7   r`   xpf2s     r   rb   zquad_vec.<locals>.<genexpr>  -      $C$CbRXXb\\$C$C$C$C$C$Cr   ru   r   r&   c              3   B   K   | ]}                     |          V  d S r   ry   rz   s     r   rb   zquad_vec.<locals>.<genexpr>  r}   r   r%   r   c              3   B   K   | ]}                     |          V  d S r   ry   rz   s     r   rb   zquad_vec.<locals>.<genexpr>  s-      +J+JRBHHRLL+J+J+J+J+J+Jr   zinvalid integration bounds a=z, b=)Nmaxri         )Ngk21rn   trapz	trapezoidzunknown quadrature r   zz`quadrature='trapz'` is deprecated in favour of `quadrature='trapezoid' and will raise an error from SciPy 1.16.0 onwards.)
stacklevel   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                 X    g | ]&}                     |d          |d         f          'S r&   r   )get)r`   r6   dummyinterval_caches     r   
<listcomp>zquad_vec.<locals>.<listcomp>  sE     : : :*+ -00!A$!uEE : : :r   c                      g | ]}|d           S r   rA   r`   r6   s     r   r   zquad_vec.<locals>.<listcomp>  s    444QAaD5444r   c                 .    g | ]}|d          |d         gS r   rA   r   s     r   r   zquad_vec.<locals>.<listcomp>  s$    >>>qqtQqTl>>>r   )nevalsuccessstatusmessage	intervals	integralserrors)0float
isinstancetupler   dictr3   isfiniteisinfr#   quad_vecrC   
ValueErrorrK   linalgrq   callable_quadrature_gk21_quadrature_gk15_quadrature_trapezoidKeyErrorwarningswarnDeprecationWarningsortedappendnum_evalcomplexrF   rT   r   copyheapqheapifyr   r   r   rangeheappoppop_subdivide_intervalheappushasarrayfullshapenanr   arrayrV   )Ar=   abro   rp   rq   rr   rs   rt   ru   rv   rw   rl   r[   ressgn
norm_funcs	norm_funcparallel_countmin_intervals_quadratureemsginitial_intervalsprevpglobal_integralglobal_errorrounding_errorr   r   x1x2igerrrndcache_count	CONVERGEDNOT_CONVERGEDROUNDING_ERRORNOT_A_NUMBER
status_msg
mapwrapperiertol
to_processerr_sumjintervalneg_old_errold_intpartsdintderr
dround_errsubintdnevalr5   res_arrr   r   infor   r|   r   sA                                                                 @@@r   r   r   k   sH	   R 	aAaA &$&& 	7D Q%% '!'1'9VVz)+ + +F 
{1~~ E"(1++ Eaq222$$C$C$C$CF$C$C$CCCF8Aq++F+++	Q EBHQKK Eaq222$$C$C$C$CF$C$C$CCCF8r1a**6**QzCG##	! E! EEEbbq  ""#e+J+J+J+J6+J+J+J&J&JJF8#F8662r1////CC2q!..v..CAs
}s122w&&k!nn EQ ECCCCCDDD Y^ J
 ~~ %		t$	NMF-// 5$9	; ; <F	G
  F F F=z==>>AEF W 	c-!<<<< ~VH 	 	AaAIIIIAIIIII!t))$$dAY///DD  $+++OLNNIE# ) )B"{2r1i88C%%""ug.// $BIN ;;; #I O ::L"3ZZN$B7K$[11NNr!OCLc!N#'9R==Bx 3$B((((	M)IMNL 	.6V6	J 
G		 3
 0	C	NNU22ffYY%?%??@@CJG>** ( (  Eq55W|c!e';;;E =33$,!Q(,,aVT::!!"lAq'2Ay+N   K<' $$7DD 	> 	>9>6dJ4'$*, > >A&'OBB/1NB8,N9tRn====> 9~~..&&?)C)C"CDD#a%''#C.00(CK-- "+n2M2M "a  0	C	NNU223 3 3 3 3 3 3 3 3 3 3 3 3 3 3j C

'C *S//rvW]CCCH : : : : :/8: : :AHP P P	44)44455H>>I>>>??	E"i/ (o ) )#% % % S$Szs+   0'J 
J:"J55J:<FX##X'*X'c                    | \  }}}}|\  }}}}d||z   z  }	t          |dd          dk    r" t          j        |j                  |          } |||	||          \  }
}}|j        } ||	|||          \  }}}||j        z  }| |||||          \  }}}||j        z  }t          |dd          dk    r|                                j        }|
|z   |z
  }||z   |z
  }||z   }||	|
|f|	|||ff}|||||fS )Nr'   rr   r   )getattr	functools	lru_cacherr   r   
cache_infomisses)rl   r   r=   r   r   old_errr   r   r   cs1err1round1r   s2err2round2_r   r   r   subintervalss                         r   r   r     sT   *.'HaK%GQ7q1uA {L!,,q007I 677::"{1aI66Bf!F"{1aI66Bf
k""F#Aq!Y77A+&&{L!,,q00&7WD$; D&J2t$q!R&67Lz<77r   c                    d| |z   z  } ||           } ||          } ||          }d|| z
  z  |d|z  z   |z   z  }dt          || z
            z  t           ||                    dt           ||                    z  z   t           ||                    z   z  dz  }	d|| z
  z  ||z   z  }
dt           ||
|z
                      z  }|||	fS )z(
    Composite trapezoid quadrature
    r'   g      ?r   gؗҬ<gUUUUUU?)rF   r   )r   r   r=   r   x3f1r|   f3r   	round_errr   r   s               r   r   r     s    
b2gB	
2B	
2B	
2B	b	R!B$Y^	,Bs27||#uYYr]]';';)*52+?+?)?(@).yy}})=)=(> ?AFGI 
RBG	$B
iiR(())
)CsIr   	   r   c                    dgt          |          z  }d| |z   z  }d|| z
  z  }	d}
d}t          t          |                    D ]C} |||	||         z  z             }|||<   ||         }|
||z  z  }
||t          |          z  z  }Dd}t          t          |                    D ]}|||         |d|z  dz            z  z  }d}|
dz  }t          t          |                    D ]&}|||         t          ||         |z
            z  z  }'t           ||
|z
  |	z                      }t           |||	z                      }|dk    r"|dk    r|t	          dd|z  |z  d	z            z  }t
          j        j        }t           |d
|z  |	z  |z                      }|t
          j        j        k    rt          ||          }|	|
z  ||fS )z*
    Generic Gauss-Kronrod quadrature
    r:   r'   r   r&   g       @r   g      ?   g      ?2   )	r   r   rF   r   r-   r+   r,   epsilonr   )r   r   r=   r   r5   wvfvr   hs_ks_k_absiffvvs_gs_k_dabsy0r   dabsepsr   s                         r   _quadrature_gkr    s   
 s1vvBq1uAq1uA CG3q66]] 	  	 Qq1QqT6z]]1qT 	rBw2B< C3q66]] " "qtb1qk!! H	sB3q66]] + +AaD3r!urz??** 		39/**
+
+C8a<(())DqyySAXXSsSy4/#5666
.
 CiiS1w 67788I3>%%%#y!!s7C""r   c           	      8    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   r=   r   r5   r  r  s          r   r   r   4  s3    
	/A.		.A	.A, !Q9aA666r      c           	      8    d}d}d}t          | ||||||          S )z9
    Gauss-Kronrod 15 quadrature with error estimate
    )g	M ?g)b|_?g>'?g֡㛟?g$:?gb]?gw.?r:   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?r0  r/  r.  r-  r,  r+  r*  r#  r$  s          r   r   r   x  s3    
	/A"	.A	.A  !Q9aA666r      )	rg   rh   ri   rj   rk   r&   NNF)r+   r   r   collectionsr   r   numpyr3   scipy._lib._utilr   r   OrderedDictr   r#   rC   rK   rT   rV   r   r   r   rr   r   r  r   r   rA   r   r   <module>r6     s   



                9 9 9 9 9 9 9 9$ $ $ $ $k% $ $ $"+ + + + + + + +8       .    	, 	, 	, 	, 	, 	, 	, 	, HMOT^^ ^ ^ ^ ^B8 8 8:  ( $)   !"  0# 0# 0#f>7 >7 >7B   /7 /7 /7d     r   