403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.37
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/integrate/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/integrate/__pycache__/_quadrature.cpython-311.pyc
�

d�cY�����ddlmZddlmZmZmZmZmZmZddl	Z	ddl
ZddlZddl
Z
ddlZddlmZddlmZddlmZmZddlmZgd�Zdrd�Zdrd�ZGd
�de��ZerddlmZGd�de��ZneZdsd�Zed���Ze ��e_!dtd�Z"dud�Z#		dvd �Z$d!�Z%dwd"�Z&dwd#�Z'd$�Z(dxd&�Z)dxd'�Z*dyd(�Z+d)�Z,d*�Z-d+�Z.		dzd.�Z/dd/ddgd
d0fdd1gd2�d
d3fd1d4gd5�d6d7fd/d8gd9�d:d;fdd<gd=�d>d?fdd@gdA�dBdCfdDdEgdF�dGdHfdIdJgdK�dLdMfdNdOgdP�dQdRfddSgdT�dUdVfdWdXgdY�dZd[fdd\gd]�d^d_fd`dagdb�dcddfdDdegdf�dgdhfdi�Z0d{dj�Z1dk�Z2edldmdng��Z3dod4ddddp�dq�Z4dS)|�)�annotations)�
TYPE_CHECKING�Callable�Dict�Tuple�Any�castN)�
namedtuple)�roots_legendre)�gammaln�	logsumexp)�
_rng_spawn)�
fixed_quad�
quadrature�romberg�romb�	trapezoid�trapz�simps�simpson�cumulative_trapezoid�cumtrapz�newton_cotes�AccuracyWarning��?���c��ttd��rtj||||���Stj||||���S)a�
    Integrate along the given axis using the composite trapezoidal rule.

    If `x` is provided, the integration happens in sequence along its
    elements - they are not sorted.

    Integrate `y` (`x`) along each 1d slice on the given axis, compute
    :math:`\int y(x) dx`.
    When `x` is specified, this integrates along the parametric curve,
    computing :math:`\int_t y(t) dt =
    \int_t y(t) \left.\frac{dx}{dt}\right|_{x=x(t)} dt`.

    Parameters
    ----------
    y : array_like
        Input array to integrate.
    x : array_like, optional
        The sample points corresponding to the `y` values. If `x` is None,
        the sample points are assumed to be evenly spaced `dx` apart. The
        default is None.
    dx : scalar, optional
        The spacing between sample points when `x` is None. The default is 1.
    axis : int, optional
        The axis along which to integrate.

    Returns
    -------
    trapezoid : float or ndarray
        Definite integral of `y` = n-dimensional array as approximated along
        a single axis by the trapezoidal rule. If `y` is a 1-dimensional array,
        then the result is a float. If `n` is greater than 1, then the result
        is an `n`-1 dimensional array.

    See Also
    --------
    cumulative_trapezoid, simpson, romb

    Notes
    -----
    Image [2]_ illustrates trapezoidal rule -- y-axis locations of points
    will be taken from `y` array, by default x-axis distances between
    points will be 1.0, alternatively they can be provided with `x` array
    or with `dx` scalar.  Return value will be equal to combined area under
    the red lines.

    References
    ----------
    .. [1] Wikipedia page: https://en.wikipedia.org/wiki/Trapezoidal_rule

    .. [2] Illustration image:
           https://en.wikipedia.org/wiki/File:Composite_trapezoidal_rule_illustration.png

    Examples
    --------
    Use the trapezoidal rule on evenly spaced points:

    >>> import numpy as np
    >>> from scipy import integrate
    >>> integrate.trapezoid([1, 2, 3])
    4.0

    The spacing between sample points can be selected by either the
    ``x`` or ``dx`` arguments:

    >>> integrate.trapezoid([1, 2, 3], x=[4, 6, 8])
    8.0
    >>> integrate.trapezoid([1, 2, 3], dx=2)
    8.0

    Using a decreasing ``x`` corresponds to integrating in reverse:

    >>> integrate.trapezoid([1, 2, 3], x=[8, 6, 4])
    -8.0

    More generally ``x`` is used to integrate along a parametric curve. We can
    estimate the integral :math:`\int_0^1 x^2 = 1/3` using:

    >>> x = np.linspace(0, 1, num=50)
    >>> y = x**2
    >>> integrate.trapezoid(y, x)
    0.33340274885464394

    Or estimate the area of a circle, noting we repeat the sample which closes
    the curve:

    >>> theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)
    >>> integrate.trapezoid(np.cos(theta), x=np.sin(theta))
    3.141571941375841

    ``trapezoid`` can be applied along a specified axis to do multiple
    computations in one call:

    >>> a = np.arange(6).reshape(2, 3)
    >>> a
    array([[0, 1, 2],
           [3, 4, 5]])
    >>> integrate.trapezoid(a, axis=0)
    array([1.5, 2.5, 3.5])
    >>> integrate.trapezoid(a, axis=1)
    array([2.,  8.])
    r��x�dx�axis)�hasattr�nprr��yrr r!s    �=/usr/lib/python3/dist-packages/scipy/integrate/_quadrature.pyrrsI��P�r�;���2��|�A��r��5�5�5�5��x��Q�2�D�1�1�1�1�c�(�t||||���S)z}An alias of `trapezoid`.

    `trapz` is kept for backwards compatibility. For new code, prefer
    `trapezoid` instead.
    r)rr$s    r&rr�s���Q�!���.�.�.�.r'c��eZdZdS)rN)�__name__�
__module__�__qualname__�r'r&rr�s�������Dr'r)�Protocolc��eZdZUded<dS)�CacheAttributeszDict[int, Tuple[Any, Any]]�cacheN)r*r+r,�__annotations__r-r'r&r0r0�s�������)�)�)�)�)�)r'r0�funcr�returnc�,�tt|��S�N)r	r0)r3s r&�cache_decoratorr7�s�����&�&�&r'c��|tjvrtj|St|��tj|<tj|S)zX
    Cache roots_legendre results to speed up calls of the fixed_quad
    function.
    )�_cached_roots_legendrer1r)�ns r&r9r9�sE��	�"�(�(�(�%�+�A�.�.�&4�Q�&7�&7�� ��#�!�'��*�*r'r-�c�4�t|��\}}tj|��}tj|��stj|��rt	d���||z
|dzzdz|z}||z
dztj|||g|�R�zd���zdfS)a
    Compute a definite integral using fixed-order Gaussian quadrature.

    Integrate `func` from `a` to `b` using Gaussian quadrature of
    order `n`.

    Parameters
    ----------
    func : callable
        A Python function or method to integrate (must accept vector inputs).
        If integrating a vector-valued function, the returned array must have
        shape ``(..., len(x))``.
    a : float
        Lower limit of integration.
    b : float
        Upper limit of integration.
    args : tuple, optional
        Extra arguments to pass to function, if any.
    n : int, optional
        Order of quadrature integration. Default is 5.

    Returns
    -------
    val : float
        Gaussian quadrature approximation to the integral
    none : None
        Statically returned value of None

    See Also
    --------
    quad : adaptive quadrature using QUADPACK
    dblquad : double integrals
    tplquad : triple integrals
    romberg : adaptive Romberg quadrature
    quadrature : adaptive Gaussian quadrature
    romb : integrators for sampled data
    simpson : integrators for sampled data
    cumulative_trapezoid : cumulative integration for sampled data
    ode : ODE integrator
    odeint : ODE integrator

    Examples
    --------
    >>> from scipy import integrate
    >>> import numpy as np
    >>> f = lambda x: x**8
    >>> integrate.fixed_quad(f, 0.0, 1.0, n=4)
    (0.1110884353741496, None)
    >>> integrate.fixed_quad(f, 0.0, 1.0, n=5)
    (0.11111111111111102, None)
    >>> print(1/9.0)  # analytical result
    0.1111111111111111

    >>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=4)
    (0.9999999771971152, None)
    >>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=5)
    (1.000000000039565, None)
    >>> np.sin(np.pi/2)-np.sin(0)  # analytical result
    1.0

    z8Gaussian quadrature is only available for finite limits.��@r�r!N)r9r#�real�isinf�
ValueError�sum)r3�a�b�argsr:r�wr%s        r&rr�s���|"�!�$�$�D�A�q�
���
�
�A�	�x��{�{�+�b�h�q�k�k�+��*�+�+�	+�	
�1��q��s��C��!��A�
�a�C��9�r�v�a���Q������.�R�8�8�8�8�$�>�>r'Fc�(���|r��fd�}n��fd�}|S)aoVectorize the call to a function.

    This is an internal utility function used by `romberg` and
    `quadrature` to create a vectorized version of a function.

    If `vec_func` is True, the function `func` is assumed to take vector
    arguments.

    Parameters
    ----------
    func : callable
        User defined function.
    args : tuple, optional
        Extra arguments for the function.
    vec_func : bool, optional
        True if the function func takes vector arguments.

    Returns
    -------
    vfunc : callable
        A function that will take a vector argument and return the
        result.

    c����|g��R�Sr6r-)rrFr3s ��r&�vfunczvectorize1.<locals>.vfuncs����4��>�D�>�>�>�!r'c�d��tj|��r	�|g��R�Stj|��}�|dg��R�}t|��}t	|dt|����}tj|f|���}||d<td|��D]}�||g��R�||<�|S)Nr�dtype�rLr=)r#�isscalar�asarray�len�getattr�type�empty�range)r�y0r:rL�output�irFr3s      ��r&rJzvectorize1.<locals>.vfuncs�����{�1�~�~�
&��t�A�~��~�~�~�%��
�1�
�
�A���a��d�"�T�"�"�"�B��A���A��B���b���2�2�E��X�q�d�%�0�0�0�F��F�1�I��1�a�[�[�
.�
.�� �D��1��-��-�-�-��q�	�	��Mr'r-)r3rF�vec_funcrJs``  r&�
vectorize1rY�sV����2��	"�	"�	"�	"�	"�	"�	"�	�	�	�	�	�	��Lr'��"��\�O>�2Tr=c	��t|t��s|f}t|||���}	tj}
tj}t|dz|��}t
||dz��D]M}t|	||d|��d}
t|
|
z
��}|
}
||ks||t|
��zkrn �Ntj
d||fzt��|
|fS)a�
    Compute a definite integral using fixed-tolerance Gaussian quadrature.

    Integrate `func` from `a` to `b` using Gaussian quadrature
    with absolute tolerance `tol`.

    Parameters
    ----------
    func : function
        A Python function or method to integrate.
    a : float
        Lower limit of integration.
    b : float
        Upper limit of integration.
    args : tuple, optional
        Extra arguments to pass to function.
    tol, rtol : float, optional
        Iteration stops when error between last two iterates is less than
        `tol` OR the relative change is less than `rtol`.
    maxiter : int, optional
        Maximum order of Gaussian quadrature.
    vec_func : bool, optional
        True or False if func handles arrays as arguments (is
        a "vector" function). Default is True.
    miniter : int, optional
        Minimum order of Gaussian quadrature.

    Returns
    -------
    val : float
        Gaussian quadrature approximation (within tolerance) to integral.
    err : float
        Difference between last two estimates of the integral.

    See Also
    --------
    romberg : adaptive Romberg quadrature
    fixed_quad : fixed-order Gaussian quadrature
    quad : adaptive quadrature using QUADPACK
    dblquad : double integrals
    tplquad : triple integrals
    romb : integrator for sampled data
    simpson : integrator for sampled data
    cumulative_trapezoid : cumulative integration for sampled data
    ode : ODE integrator
    odeint : ODE integrator

    Examples
    --------
    >>> from scipy import integrate
    >>> import numpy as np
    >>> f = lambda x: x**8
    >>> integrate.quadrature(f, 0.0, 1.0)
    (0.11111111111111106, 4.163336342344337e-17)
    >>> print(1/9.0)  # analytical result
    0.1111111111111111

    >>> integrate.quadrature(np.cos, 0.0, np.pi/2)
    (0.9999999999999536, 3.9611425250996035e-11)
    >>> np.sin(np.pi/2)-np.sin(0)  # analytical result
    1.0

    �rXr=r-rz-maxiter (%d) exceeded. Latest difference = %e)�
isinstance�tuplerYr#�inf�maxrTr�abs�warnings�warnr)r3rDrErF�tol�rtol�maxiterrX�miniterrJ�val�errr:�newvals              r&rr%s���B�d�E�"�"���w���t�T�H�5�5�5�E�
�&�C�
�&�C��'�!�)�W�%�%�G�
�7�G�A�I�
&�
&�
�
���E�1�a��Q�/�/��2���&��*�o�o������9�9��d�3�s�8�8�m�+�+��E�,�	�
�;�w��n�L��	�	�	���8�Or'c�H�t|��}|||<t|��Sr6)�listr_)�trW�value�ls    r&�tuplesetrqzs!���Q���A��A�a�D���8�8�Or'c�*�t|||||���S)z�An alias of `cumulative_trapezoid`.

    `cumtrapz` is kept for backwards compatibility. For new code, prefer
    `cumulative_trapezoid` instead.
    )rr r!�initial)r)r%rr r!rss     r&rr�s�� ��Q�2�D�'�J�J�J�Jr'c��tj|��}|�|}n�tj|��}|jdkr:tj|��}dg|jz}d||<|�|��}nOt|j��t|j��krtd���tj||���}|j||j|dz
krtd���t|j��}ttd��f|z|tdd����}ttd��f|z|tdd����}	tj
|||||	zzdz|���}
|�ntj|��std���t|
j��}d||<tj
tj|||
j�	��|
g|���}
|
S)
a
    Cumulatively integrate y(x) using the composite trapezoidal rule.

    Parameters
    ----------
    y : array_like
        Values to integrate.
    x : array_like, optional
        The coordinate to integrate along. If None (default), use spacing `dx`
        between consecutive elements in `y`.
    dx : float, optional
        Spacing between elements of `y`. Only used if `x` is None.
    axis : int, optional
        Specifies the axis to cumulate. Default is -1 (last axis).
    initial : scalar, optional
        If given, insert this value at the beginning of the returned result.
        Typically this value should be 0. Default is None, which means no
        value at ``x[0]`` is returned and `res` has one element less than `y`
        along the axis of integration.

    Returns
    -------
    res : ndarray
        The result of cumulative integration of `y` along `axis`.
        If `initial` is None, the shape is such that the axis of integration
        has one less value than `y`. If `initial` is given, the shape is equal
        to that of `y`.

    See Also
    --------
    numpy.cumsum, numpy.cumprod
    quad : adaptive quadrature using QUADPACK
    romberg : adaptive Romberg quadrature
    quadrature : adaptive Gaussian quadrature
    fixed_quad : fixed-order Gaussian quadrature
    dblquad : double integrals
    tplquad : triple integrals
    romb : integrators for sampled data
    ode : ODE integrators
    odeint : ODE integrators

    Examples
    --------
    >>> from scipy import integrate
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt

    >>> x = np.linspace(-2, 2, num=20)
    >>> y = x
    >>> y_int = integrate.cumulative_trapezoid(y, x, initial=0)
    >>> plt.plot(x, y_int, 'ro', x, y[0] + 0.5 * x**2, 'b-')
    >>> plt.show()

    Nr=r�2If given, shape of x must be 1-D or the same as y.r?�7If given, length of x along axis must be the same as y.r>z'`initial` parameter should be a scalar.rM)r#rO�ndim�diff�reshaperP�shaperBrq�slice�cumsumrNrm�concatenate�fullrL)r%rr r!rs�drz�nd�slice1�slice2�ress           r&rr�s���n	�
�1�
�
�A��y�����J�q�M�M���6�Q�;�;����
�
�A��C�!�&�L�E��E�$�K��	�	�%� � �A�A�
���\�\�S���\�\�
)�
)��*�+�+�
+�����%�%�%�A��7�4�=�A�G�D�M�A�-�-�-��*�+�+�
+�

�Q�W���B�
�u�T�{�{�n�R�'��u�Q��~�~�
>�
>�F�
�u�T�{�{�n�R�'��u�T�2���
?�
?�F�
�)�A��6��Q�v�Y�.�/�#�5�D�
A�
A�
A�C����{�7�#�#�	H��F�G�G�G��S�Y������d���n�b�g�e�W�C�I�F�F�F��L�"&�(�(�(���Jr'c��t|j��}|�d}d}td��f|z}t||t|||����}	t||t|dz|dz|����}
t||t|dz|dz|����}|�;t	j||	d||
zz||z|���}||dzz}�nht	j||���}
t||t|||����}t||t|dz|dz|����}t	j|
|��}t	j|
|��}||z}||z}t	j||t	j	|��|dk���}|dz||	d	t	jd
|t	j	|��|dk���z
z||
|t	j||t	j	|��|dk���zzz||d	|z
zzz}t	j||���}|S)Nr�r=�@r?�@)�out�whereg@r>r)
rPrzr{rqr#rCrx�float64�true_divide�
zeros_like)r%�start�stoprr r!r��step�	slice_all�slice0r�r��result�h�sl0�sl1�h0�h1�hsum�hprod�h0divh1�tmps                      r&�_basic_simpsonr��s_��	�Q�W���B��}����D��t����r�!�I�
�i��u�U�D�$�'?�'?�
@�
@�F�
�i��u�U�1�W�d�1�f�d�'C�'C�
D�
D�F�
�i��u�U�1�W�d�1�f�d�'C�'C�
D�
D�F��y����&�	�C��&�	�M�1�A�f�I�=�D�I�I�I���"�s�(����
�G�A�D�!�!�!���y�$��e�T�4�(@�(@�A�A���y�$��e�A�g�t�A�v�t�(D�(D�E�E��
�Z��#��
�
��
�Z��#��
�
���B�w���R����.��R�R�]�2�->�->�b�A�g�N�N�N���3�h�!�F�)�����W�46�M�'�4J�4J�6=��l�"D�"D�"D�D�E��F�)�t�')�~�d�E�:<�-��:M�:M�<A�Q�J�(H�(H�(H�(H�I�	I��F�)�s�W�}�5�6�7�����$�'�'�'���Mr'�avgc�*�t|||||���S)zyAn alias of `simpson`.

    `simps` is kept for backwards compatibility. For new code, prefer
    `simpson` instead.
    )rr r!�even)r)r%rr r!r�s     r&rrs���1��b�t�$�7�7�7�7r'c	��tj|��}t|j��}|j|}|}|}d}	|��tj|��}t|j��dkrBdg|z}
|jd|
|<|j}d}	|�t|
����}n9t|j��t|j��krt
d���|j||krt
d���|dzdk�rDd}d}
td��f|z}td��f|z}|dvrt
d	���|d
vrft||d��}t||d��}|�||||z
}|d
|z||||zzz
}t|d|dz
|||��}
|dvr�t||d��}t||d��}|�+|t|��|t|��z
}|d
|z||||zzz
}|
t|d|dz
|||��z
}
|dkr
|dz}|
dz}
|
|z}
nt|d|dz
|||��}
|	r|�|��}|
S)a�	
    Integrate y(x) using samples along the given axis and the composite
    Simpson's rule. If x is None, spacing of dx is assumed.

    If there are an even number of samples, N, then there are an odd
    number of intervals (N-1), but Simpson's rule requires an even number
    of intervals. The parameter 'even' controls how this is handled.

    Parameters
    ----------
    y : array_like
        Array to be integrated.
    x : array_like, optional
        If given, the points at which `y` is sampled.
    dx : float, optional
        Spacing of integration points along axis of `x`. Only used when
        `x` is None. Default is 1.
    axis : int, optional
        Axis along which to integrate. Default is the last axis.
    even : str {'avg', 'first', 'last'}, optional
        'avg' : Average two results:1) use the first N-2 intervals with
                  a trapezoidal rule on the last interval and 2) use the last
                  N-2 intervals with a trapezoidal rule on the first interval.

        'first' : Use Simpson's rule for the first N-2 intervals with
                a trapezoidal rule on the last interval.

        'last' : Use Simpson's rule for the last N-2 intervals with a
               trapezoidal rule on the first interval.

    Returns
    -------
    float
        The estimated integral computed with the composite Simpson's rule.

    See Also
    --------
    quad : adaptive quadrature using QUADPACK
    romberg : adaptive Romberg quadrature
    quadrature : adaptive Gaussian quadrature
    fixed_quad : fixed-order Gaussian quadrature
    dblquad : double integrals
    tplquad : triple integrals
    romb : integrators for sampled data
    cumulative_trapezoid : cumulative integration for sampled data
    ode : ODE integrators
    odeint : ODE integrators

    Notes
    -----
    For an odd number of samples that are equally spaced the result is
    exact if the function is a polynomial of order 3 or less. If
    the samples are not equally spaced, then the result is exact only
    if the function is a polynomial of order 2 or less.

    Examples
    --------
    >>> from scipy import integrate
    >>> import numpy as np
    >>> x = np.arange(0, 10)
    >>> y = np.arange(0, 10)

    >>> integrate.simpson(y, x)
    40.5

    >>> y = np.power(x, 3)
    >>> integrate.simpson(y, x)
    1642.5
    >>> integrate.quad(lambda x: x**3, 0, 9)[0]
    1640.25

    >>> integrate.simpson(y, x, even='first')
    1644.5

    rNr=rurvr�g)r��last�firstz3Parameter 'even' must be 'avg', 'last', or 'first'.)r�r�r�����?�)r�r�r�r>)
r#rOrPrzryr_rBr{rqr�)r%rr r!r�r��N�last_dx�first_dx�returnshape�shapex�	saveshaperir�r�r�s                r&rrs���X	�
�1�
�
�A�	�Q�W���B�	���
�A��G��H��K��}��J�q�M�M���q�w�<�<�1����S�2�X�F��7�1�:�F�4�L���I��K��	�	�%��-�-�(�(�A�A�
���\�\�S���\�\�
)�
)��*�+�+�
+��7�4�=�A����*�+�+�
+��1�u��z�z�������+�+���"����+�+���"���/�/�/��:�;�;�
;��#�#�#��f�d�B�/�/�F��f�d�B�/�/�F��}��F�)�a��i�/���3�w�;��&�	�!�F�)� 3�4�4�C�#�A�q�!�A�#�q�"�d�;�;�F��?�"�"��f�d�A�.�.�F��f�d�A�.�.�F��}��U�6�]�]�+�a��f�
�
�.>�>���3�x�<��6��1�V�9�!4�5�5�C��n�Q��1�Q�3��2�t�<�<�<�F��5�=�=��3�J�C��c�M�F��#������1�a��c�1�b�$�7�7���!�
�I�I�i� � ���Mr'c
��tj|��}t|j��}|j|}|dz
}d}d}||kr|dz}|dz
}||k�||krt	d���i}	td��f|z}
t
|
|d��}t
|
|d��}|tj|t���z}
||||zdz|
z|	d<|
}|x}x}}td|dz��D]�}|dz}t
||t|||����}|dz}d	|	|dz
df|
||�	|�
��zzz|	|df<td|dz��D]6}|	||dz
f}|||	|dz
|dz
fz
dd|zzdz
zz|	||f<�7|
dz}
��|�rtj
|	d��std��n�	|d}n#ttf$rd
}YnwxYw	|d}n#ttf$rd}YnwxYwd||fz}d}t|dt|��zdd���t|dz��D]A}t|dz��D]}t||	||fzd����t���Btdt|��z��|	||fS)a�
    Romberg integration using samples of a function.

    Parameters
    ----------
    y : array_like
        A vector of ``2**k + 1`` equally-spaced samples of a function.
    dx : float, optional
        The sample spacing. Default is 1.
    axis : int, optional
        The axis along which to integrate. Default is -1 (last axis).
    show : bool, optional
        When `y` is a single 1-D array, then if this argument is True
        print the table showing Richardson extrapolation from the
        samples. Default is False.

    Returns
    -------
    romb : ndarray
        The integrated result for `axis`.

    See Also
    --------
    quad : adaptive quadrature using QUADPACK
    romberg : adaptive Romberg quadrature
    quadrature : adaptive Gaussian quadrature
    fixed_quad : fixed-order Gaussian quadrature
    dblquad : double integrals
    tplquad : triple integrals
    simpson : integrators for sampled data
    cumulative_trapezoid : cumulative integration for sampled data
    ode : ODE integrators
    odeint : ODE integrators

    Examples
    --------
    >>> from scipy import integrate
    >>> import numpy as np
    >>> x = np.arange(10, 14.25, 0.25)
    >>> y = np.arange(3, 12)

    >>> integrate.romb(y)
    56.0

    >>> y = np.sin(np.power(x, 2.5))
    >>> integrate.romb(y)
    -0.742561336672229

    >>> integrate.romb(y, show=True)
    Richardson Extrapolation Table for Romberg Integration
    ======================================================
    -0.81576
     4.63862  6.45674
    -1.10581 -3.02062 -3.65245
    -2.57379 -3.06311 -3.06595 -3.05664
    -1.34093 -0.92997 -0.78776 -0.75160 -0.74256
    ======================================================
    -0.742561336672229  # may vary

    r=rz=Number of samples must be one plus a non-negative power of 2.NrrMr>)rrr�r?r�zE*** Printing table only supported for integrals of a single data set.r;�z%%%d.%dfz6Richardson Extrapolation Table for Romberg Integration�=�
)�sep�end� �r�)r#rOrPrzrBr{rq�floatrTrCrN�print�	TypeError�
IndexError)r%r r!�showr��Nsamps�Nintervr:�k�Rr�r��slicem1r��slice_Rr�r�r�rW�j�prev�precis�width�formstr�titles                         r&rr�sl��z	�
�1�
�
�A�	�Q�W���B�
�W�T�]�F��Q�h�G�	�A�	�A�
�g�+�+�	�a���	�Q����g�+�+�	�G�|�|��4�5�5�	5�	�A��t�����#�I�
�i��q�
)�
)�F��y�$��+�+�G��"�*�R�u�-�-�-�-�A��6��Q�w�Z�'��,�Q�.�A�f�I��G�!�!�E�!�D�4�
�1�a��c�]�]����
�!����7�D�%��t�T�*B�*B�C�C����
����A�a�C��8��q��7����T��)B�)B�'B�B�C��1�a�&�	��q�!�A�#���	G�	G�A��a��1��X�;�D���Q��!��Q�q�S�z�]� 2��a��c�
�A�~�F�F�A�q�!�f�I�I�	�S�����$��{�1�V�9�%�%�	$��+�
,�
,�
,�
,�
��a������z�*�
�
�
�����
����
��Q������z�*�
�
�
�����
���� �E�6�?�2�G�L�E��%��s�5�z�z�)�t��>�>�>�>��1�Q�3�Z�Z�
�
���q��s���8�8�A��'�A�q�!�f�I�-�3�7�7�7�7�7�������#��E�
�
�"�#�#�#��a��V�9�s$�G�G2�1G2�6G?�?H�Hc�b�|dkrtd���|dkr&d||d��||d��zzS|dz}t|d|dz
��|z}|dd|zz}||tj|��zz}tj||��d���}|S)aU
    Perform part of the trapezoidal rule to integrate a function.
    Assume that we had called difftrap with all lower powers-of-2
    starting with 1. Calling difftrap only returns the summation
    of the new ordinates. It does _not_ multiply by the width
    of the trapezoids. This must be performed by the caller.
        'function' is the function to evaluate (must accept vector arguments).
        'interval' is a sequence with lower and upper limits
                   of integration.
        'numtraps' is the number of trapezoids to use (must be a
                   power-of-2).
    rz#numtraps must be > 0 in difftrap().r=r�r�r?)rBr�r#�arangerC)�function�interval�numtraps�numtosumr��lox�points�ss        r&�	_difftrapr�s����1�}�}��>�?�?�?�	�Q����H�H�X�a�[�)�)�(�(�8�A�;�*?�*?�?�@�@��A�:���(�1�+�h�q�k�)�*�*�8�3���q�k�C�!�G�#���q�2�9�X�.�.�.�.���F�8�8�F�#�#�!�,�,�,���r'c�(�d|z}||z|z
|dz
zS)z�
    Compute the differences for the Romberg quadrature corrections.
    See Forman Acton's "Real Computing Made Real," p 143.
    r�rr-)rE�cr�r�s    r&�
_romberg_diffr�6s$��
�q�&�C��!�G�a�K�#��)�$�$r'c�x�dx}}tdt|��d���td|��td��tddz��tt|����D]t}td	d
|z|d|dz
d|zzfzd���t|dz��D]"}td
|||zd����#td���utd��td|||d���tdd
t|��dz
zdzd��dS)NrzRomberg integration ofr�r��from�z%6s %9s %9s)�Steps�StepSize�Resultsz%6d %9fr�r=r>z%9fzThe final result is�afterzfunction evaluations.)r��reprrTrP)r�r��resmatrWr�s     r&�_printresmatr�?sI��
�I�A��	�
"�D��N�N��<�<�<�<�	�&�(����	�"�I�I�I�	�-�:�
:�;�;�;�
�3�v�;�;�
�
����
�i�1�a�4�(�1�+�h�q�k�"9�B��E�!B�C�C��M�M�M�M��q��s���	3�	3�A��%�6�!�9�Q�<�(�c�2�2�2�2�2�
�b�	�	�	�	�	�"�I�I�I�	�
����1��3�7�7�7�7�	�'�1�s�6�{�{�1�}�%�a�'�)@�A�A�A�A�Ar'�`s��b�O>�
c	
� �tj|��stj|��rtd���t|||���}	d}
||g}||z
}t	|	||
��}
||
z}|gg}tj}|d}t
d|dz��D]�}|
dz}
|
t	|	||
��z
}
||
z|
zg}t
|��D]5}|�t|||||dz�����6||}||dz
}|r|�|��t||z
��}||ks||t|��zkrn"|}��tjd||fzt��|rt|	||��|S)a�

    Romberg integration of a callable function or method.

    Returns the integral of `function` (a function of one variable)
    over the interval (`a`, `b`).

    If `show` is 1, the triangular array of the intermediate results
    will be printed. If `vec_func` is True (default is False), then
    `function` is assumed to support vector arguments.

    Parameters
    ----------
    function : callable
        Function to be integrated.
    a : float
        Lower limit of integration.
    b : float
        Upper limit of integration.

    Returns
    -------
    results : float
        Result of the integration.

    Other Parameters
    ----------------
    args : tuple, optional
        Extra arguments to pass to function. Each element of `args` will
        be passed as a single argument to `func`. Default is to pass no
        extra arguments.
    tol, rtol : float, optional
        The desired absolute and relative tolerances. Defaults are 1.48e-8.
    show : bool, optional
        Whether to print the results. Default is False.
    divmax : int, optional
        Maximum order of extrapolation. Default is 10.
    vec_func : bool, optional
        Whether `func` handles arrays as arguments (i.e., whether it is a
        "vector" function). Default is False.

    See Also
    --------
    fixed_quad : Fixed-order Gaussian quadrature.
    quad : Adaptive quadrature using QUADPACK.
    dblquad : Double integrals.
    tplquad : Triple integrals.
    romb : Integrators for sampled data.
    simpson : Integrators for sampled data.
    cumulative_trapezoid : Cumulative integration for sampled data.
    ode : ODE integrator.
    odeint : ODE integrator.

    References
    ----------
    .. [1] 'Romberg's method' https://en.wikipedia.org/wiki/Romberg%27s_method

    Examples
    --------
    Integrate a gaussian from 0 to 1 and compare to the error function.

    >>> from scipy import integrate
    >>> from scipy.special import erf
    >>> import numpy as np
    >>> gaussian = lambda x: 1/np.sqrt(np.pi) * np.exp(-x**2)
    >>> result = integrate.romberg(gaussian, 0, 1, show=True)
    Romberg integration of <function vfunc at ...> from [0, 1]

    ::

       Steps  StepSize  Results
           1  1.000000  0.385872
           2  0.500000  0.412631  0.421551
           4  0.250000  0.419184  0.421368  0.421356
           8  0.125000  0.420810  0.421352  0.421350  0.421350
          16  0.062500  0.421215  0.421350  0.421350  0.421350  0.421350
          32  0.031250  0.421317  0.421350  0.421350  0.421350  0.421350  0.421350

    The final result is 0.421350396475 after 33 function evaluations.

    >>> print("%g %g" % (2*result, erf(1)))
    0.842701 0.842701

    z5Romberg integration only available for finite limits.r]r=rr�z,divmax (%d) exceeded. Latest difference = %e)r#rArBrYr�r`rT�appendr�rbrcrdrr�)r�rDrErFrerfr��divmaxrXrJr:r��intrange�ordsumr�r�rj�last_rowrW�rowr��
lastresults                      r&rrPs���j
�x��{�{�/�b�h�q�k�k�/��.�/�/�	/��x���9�9�9�E�	�A��1�v�H��1�u�H�
�u�h��
*�
*�F�
��
�F��h�Z�F�
�&�C��a�y�H�
�1�f�Q�h�
�
����	�Q����)�E�8�Q�/�/�/���&� �1�$�%���q���	@�	@�A��J�J�}�X�a�[�#�a�&�!�A�#�>�>�?�?�?�?��Q����a��c�]�
��	��M�M�#�����&�:�%�&�&����9�9��d�S��[�[�0�0�0��E�����
�:�f�c�]�J��	�	�	��.��U�H�f�-�-�-��Mr'r��r�)r=�r=�Zr�)r=r�r�r=����P�-)�� r�r�r�i����i�i )��Kr[r[r�r�i��i@/�)�)���ir�r�r�i����ixr�i�C)���
�+�r�r�r�r�i	�i�r�i_7)	����`����)iD�r�r�r�r�i����i?#�	i^)
�)�}=�8�K�rrr�r�r�i��iip�)��>�<��sB���(�:��ih�rrrrrii���i�0�	�i�0)�I"!����������j�m��i�r
rrr
r	rl�����&	l7�iR0P)
���@���7���@!�!N��d7ipR�rrrrrri<�ic]
�
l`5]v)�
v[O�=H/54����+w�"�-����Mp:���{�>����$MY(rrrrrrrl�����`�:l@	Al@d@*)�i�`�p�`*�o����Fg!����f���\�a����L�Rl@`�r"r!r rrrrl�����x�=l�7-�)r=r�r�r�r;�r�r�r�r�rr�r�c���	t|��dz
}|rtj|dz��}n,tjtj|��dk��rd}n+#t
$r|}tj|dz��}d}YnwxYw|rQ|tvrHt|\}}}}}|tj|t���z|z}|t|��|zfS|ddks|d|krtd���|t|��z}	d|	zdz
}
tj|dz��}|
|dd�tj
fz}tj�|��}
td��D]0}d|
z|
�|���|
��z
}
�1d|ddd�dzz}|
dd�ddd�f�|��|dzz}|dzdkr|r||d	zz}|dz}n
||dzz}|dz}|tj|	|z|��z
}|dz}|tj|��zt#|��z
}tj|��}|||zfS)
a�
    Return weights and error coefficient for Newton-Cotes integration.

    Suppose we have (N+1) samples of f at the positions
    x_0, x_1, ..., x_N. Then an N-point Newton-Cotes formula for the
    integral between x_0 and x_N is:

    :math:`\int_{x_0}^{x_N} f(x)dx = \Delta x \sum_{i=0}^{N} a_i f(x_i)
    + B_N (\Delta x)^{N+2} f^{N+1} (\xi)`

    where :math:`\xi \in [x_0,x_N]`
    and :math:`\Delta x = \frac{x_N-x_0}{N}` is the average samples spacing.

    If the samples are equally-spaced and N is even, then the error
    term is :math:`B_N (\Delta x)^{N+3} f^{N+2}(\xi)`.

    Parameters
    ----------
    rn : int
        The integer order for equally-spaced data or the relative positions of
        the samples with the first sample at 0 and the last at N, where N+1 is
        the length of `rn`. N is the order of the Newton-Cotes integration.
    equal : int, optional
        Set to 1 to enforce equally spaced data.

    Returns
    -------
    an : ndarray
        1-D array of weights to apply to the function at the provided sample
        positions.
    B : float
        Error coefficient.

    Notes
    -----
    Normally, the Newton-Cotes rules are used on smaller integration
    regions and a composite rule is used to return the total integral.

    Examples
    --------
    Compute the integral of sin(x) in [0, :math:`\pi`]:

    >>> from scipy.integrate import newton_cotes
    >>> import numpy as np
    >>> def f(x):
    ...     return np.sin(x)
    >>> a = 0
    >>> b = np.pi
    >>> exact = 2
    >>> for N in [2, 4, 6, 8, 10]:
    ...     x = np.linspace(a, b, N + 1)
    ...     an, B = newton_cotes(N, 1)
    ...     dx = (b - a) / N
    ...     quad = dx * np.sum(an * f(x))
    ...     error = abs(quad - exact)
    ...     print('{:2d}  {:10.9f}  {:.5e}'.format(N, quad, error))
    ...
     2   2.094395102   9.43951e-02
     4   1.998570732   1.42927e-03
     6   2.000017814   1.78136e-05
     8   1.999999835   1.64725e-07
    10   2.000000001   1.14677e-09

    r=rMrrz1The sample positions must start at 0 and end at Nr�Nr>r�)rPr#r��allrx�	Exception�_builtincoeffs�arrayr�rB�newaxis�linalg�invrT�dot�math�logr�exp)�rn�equalr��na�da�vi�nb�db�an�yi�ti�nvec�C�CinvrW�vec�ai�BN�power�p1�facs                     r&rrs���B	���G�G�A�I���	���1�Q�3���B�B�
�V�B�G�B�K�K�1�$�
%�
%�	��E���������
�Y�q��s�^�^����������

� ��n�$�$�+�A�.���B��B��
�"�(�2�U�+�+�+�
+�b�
0���5��9�9�R�<���
�1���
�
��2��!����)�*�*�	*�	�e�A�h�h��B�	
�R��!��B�
�9�Q�q�S�>�>�D�
�d�1�1�1�b�j�=�!�!�A�
�9�=�=����D�
�1�X�X�.�.����v����������-�-�-���

��c�c��c��1��
�C�	
�a�a�a���1��f��	�	�#�	�	�!�b�&�	)�B�	�A���
�
��
�
��"��X���!����
��"��X���!���	�b�f�R��Y��#�#�	#�B�	�q��B�
������
�g�b�k�k�
)�C�
�(�3�-�-�C�
�r�#�v�:�s�AA�%B�Bc	����ttd��sddlm}|t_ntj}t	���sd}t|���t
j|�����}t
j|�����}t
j	||��\}}|j
d}		�||zdz��n$#t$r}
d}t|��|
�d}
~
wwxYw	�t
j
||g�����}n8#t$r+}
d|
�d�}tj|d	�
���fd�}Yd}
~
nd}
~
wwxYwt
j|��}||krd}t|���t
j|��}
||
krd
}t|���|�|j�|	��}n+t'||jj��sd}t|���|j|j
dkrd}t|���t-|dd��}|j�|��}|dvrd}t|���|||||
||||f	S)N�qmcr)�statsz`func` must be callable.r�z�`func` must evaluate the integrand at points within the integration range; e.g. `func( (a + b) / 2)` must return the integrand at the centroid of the integration volume.zAException encountered when attempting vectorized call to `func`: z�. `func` should accept two-dimensional array with shape `(n_points, len(a))` and return an array with the integrand value at each of the `n_points` for better performance.r���
stacklevelc�2��tj�d|���S)Nr)r!�arr)r#�apply_along_axis)rr3s �r&rJz_qmc_quad_iv.<locals>.vfunc�s����&�t�"�!�<�<�<�<r'z`n_points` must be an integer.z!`n_estimates` must be an integer.z8`qrng` must be an instance of scipy.stats.qmc.QMCEngine.z�`qrng` must be initialized with dimensionality equal to the number of variables in `a`, i.e., `qrng.random().shape[-1]` must equal `a.shape[0]`.�rng_seed>FTz*`log` must be boolean (`True` or `False`).)r"�	_qmc_quad�scipyrF�callabler�r#�
atleast_1d�copy�broadcast_arraysrzr'rBr)rcrd�int64rE�Haltonr^�	QMCEnginerrQ�_qmc�check_random_state)r3rDrE�n_points�n_estimates�qrngr/rF�message�dim�erJ�n_points_int�n_estimates_intrL�rngs`               r&�_qmc_quad_ivrass�����9�e�$�$� ��������	�������D�>�>�!�,���� � � �	�
�a�������A�
�
�a�������A�
��q�!�$�$�D�A�q�
�'�!�*�C�)���a�!�e�q�[�������)�)�)�)����!�!�q�(�����)����=���R�X�q�!�f�
�
���������	=�	=�	=�"��"�"�"��
	�
�g�!�,�,�,�,�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�����	=�����8�H�%�%�L��<���2���� � � ��h�{�+�+�O��o�%�%�5���� � � ��|��y����$�$���
��e�i�1�
2�
2�!�L���� � � ��v�������H����!�!�!��t�Z��.�.�H�
�*�
'�
'��
1�
1�C�
�-���>���� � � ��1�a����c�3��N�Ns0�C�
C;�$C6�6C;�?!D!�!
E�+!E�E�
QMCQuadResult�integral�standard_errori)rXrYrZr/rFc	���t|||||||��}|\	}}}}}}}}}	tj||k��r7d}
tj|
d���t|r
tjndd��S||k}d|�d���z}||||c||<||<tj||z
��}
|
|z}tj	|��}t|j|��}t|��D]�}|�
|��}|	j�|||��}||��}|r%t!|��tj|��z}ntj||z��}|||<t%|��d	d||i|j��}��tj|��}|r|dkr|tjdzzn||z}|	�|��}t||��S)
a�
    Compute an integral in N-dimensions using Quasi-Monte Carlo quadrature.

    Parameters
    ----------
    func : callable
        The integrand. Must accept a single arguments `x`, an array which
        specifies the point at which to evaluate the integrand. For efficiency,
        the function should be vectorized to compute the integrand for each
        element an array of shape ``(n_points, n)``, where ``n`` is number of
        variables.
    a, b : array-like
        One-dimensional arrays specifying the lower and upper integration
        limits, respectively, of each of the ``n`` variables.
    n_points, n_estimates : int, optional
        One QMC sample of `n_points` (default: 256) points will be generated
        by `qrng`, and `n_estimates` (default: 8) statistically independent
        estimates of the integral will be produced. The total number of points
        at which the integrand `func` will be evaluated is
        ``n_points * n_estimates``. See Notes for details.
    qrng : `~scipy.stats.qmc.QMCEngine`, optional
        An instance of the QMCEngine from which to sample QMC points.
        The QMCEngine must be initialized to a number of dimensions
        corresponding with the number of variables ``x0, ..., xn`` passed to
        `func`.
        The provided QMCEngine is used to produce the first integral estimate.
        If `n_estimates` is greater than one, additional QMCEngines are
        spawned from the first (with scrambling enabled, if it is an option.)
        If a QMCEngine is not provided, the default `scipy.stats.qmc.Halton`
        will be initialized with the number of dimensions determine from
        `a`.
    log : boolean, default: False
        When set to True, `func` returns the log of the integrand, and
        the result object contains the log of the integral.

    Returns
    -------
    result : object
        A result object with attributes:

        integral : float
            The estimate of the integral.
        standard_error :
            The error estimate. See Notes for interpretation.

    Notes
    -----
    Values of the integrand at each of the `n_points` points of a QMC sample
    are used to produce an estimate of the integral. This estimate is drawn
    from a population of possible estimates of the integral, the value of
    which we obtain depends on the particular points at which the integral
    was evaluated. We perform this process `n_estimates` times, each time
    evaluating the integrand at different scrambled QMC points, effectively
    drawing i.i.d. random samples from the population of integral estimates.
    The sample mean :math:`m` of these integral estimates is an
    unbiased estimator of the true value of the integral, and the standard
    error of the mean :math:`s` of these estimates may be used to generate
    confidence intervals using the t distribution with ``n_estimates - 1``
    degrees of freedom. Perhaps counter-intuitively, increasing `n_points`
    while keeping the total number of function evaluation points
    ``n_points * n_estimates`` fixed tends to reduce the actual error, whereas
    increasing `n_estimates` tends to decrease the error estimate.

    Examples
    --------
    QMC quadrature is particularly useful for computing integrals in higher
    dimensions. An example integrand is the probability density function
    of a multivariate normal distribution.

    >>> import numpy as np
    >>> from scipy import stats
    >>> dim = 8
    >>> mean = np.zeros(dim)
    >>> cov = np.eye(dim)
    >>> def func(x):
    ...     return stats.multivariate_normal.pdf(x, mean, cov)

    To compute the integral over the unit hypercube:

    >>> from scipy.integrate import qmc_quad
    >>> a = np.zeros(dim)
    >>> b = np.ones(dim)
    >>> rng = np.random.default_rng()
    >>> qrng = stats.qmc.Halton(d=dim, seed=rng)
    >>> n_estimates = 8
    >>> res = qmc_quad(func, a, b, n_estimates=n_estimates, qrng=qrng)
    >>> res.integral, res.standard_error
    (0.00018441088533413305, 1.1255608140911588e-07)

    A two-sided, 99% confidence interval for the integral may be estimated
    as:

    >>> t = stats.t(df=n_estimates-1, loc=res.integral,
    ...             scale=res.standard_error)
    >>> t.interval(0.99)
    (0.00018401699720722663, 0.00018480477346103947)

    Indeed, the value reported by `scipy.stats.multivariate_normal` is
    within this range.

    >>> stats.multivariate_normal.cdf(b, mean, cov, lower_limit=a)
    0.00018430867675187443

    z^A lower limit was equal to an upper limit, so the value of the integral is zero by definition.r�rGrrr?�seedy�?r-)rar#�anyrcrdrbr`rC�prod�zerosrr`rT�randomrE�scaler
r/rR�
_init_quad�mean�pi�sem)r3rDrErXrYrZr/rFr`rFr[�i_swap�sign�A�dA�	estimates�rngsrW�sampler�
integrands�estimatercrds                        r&rMrM�s��T��a��H�k�4��E�E�D�?C�<�D�!�Q��+�t�S�#�u�

�v�a�1�f�~�~�7�<���
�g�!�,�,�,�,���2�b�f�W�W��A�6�6�6�
��U�F��&�*�*�"�*�%�%�&�D��V�9�a��i��A�f�I�q��y�
���A����A�	
�X��B����%�%�I��d�h��,�,�D�
�;�
�
�;�;�����X�&�&���I�O�O�F�A�q�)�)���T�!�W�W�
��	/� ��,�,�r�v�b�z�z�9�H�H��v�j�2�o�.�.�H��	�!���t�D�z�z�:�:�t�A�w�:�$�/�:�:����w�y�!�!�H�'*�K�t�a�x�x�x�"�%��(�"�"�h�t�m�H��Y�Y�y�)�)�N���>�2�2�2r')Nrr)r3rr4r0)r-r;)r-F)r-rZrZr[Tr=)NrrN)Nrrr�)rrF)r-r�r�Fr�F)r)5�
__future__r�typingrrrrrr	�	functools�numpyr#r.�typesrc�collectionsr
�
scipy.specialrrr
�scipy._lib._utilr�__all__rr�Warningrr.r0r7r9�dictr1rrYrrqrrr�rrrr�r�r�rr(rrarbrMr-r'r&�<module>r�s���"�"�"�"�"�"�B�B�B�B�B�B�B�B�B�B�B�B�B�B�B�B���������������������"�"�"�"�"�"�(�(�(�(�(�(�,�,�,�,�,�,�,�,�'�'�'�'�'�'�����k2�k2�k2�k2�`/�/�/�/�	�	�	�	�	�g�	�	�	��� ������*�*�*�*�*�(�*�*�*�*��O�'�'�'�'��	+�	+���	+� $�t�v�v���D?�D?�D?�D?�N*�*�*�*�ZHJ�&'�R�R�R�R�j���K�K�K�K�Z�Z�Z�Z�z"�"�"�N8�8�8�8�@�@�@�@�Fs�s�s�s�B���4%�%�%�B�B�B�"FK� %�v�v�v�v�h	
�!�Q�q�E�"�R��	�!�G�G�G�B�r��	�!�I�I�I�b���	�"�^�^�^�B�s�#�	�#�!�!�!�$�u�-�	�#�'�'�'��4�0�	�%�7�7�7��f�E�	�%�?�?�?�
�f��	�%����#�V�-�	
�6�7�7�7�	�)�	�
�H�(�(�(�)4�l�	D�
�G�0�0�0�16��	@�
�\�3�3�3�5@�	�	�
�J�8�8�8�:E�	�		�7 � ��Fj�j�j�j�ZGO�GO�GO�T�
�?�Z�9I�,J�K�K�
�'+����d�P3�P3�P3�P3�P3�P3�P3r'

Youez - 2016 - github.com/yon3zu
LinuXploit