
    Ui!                     V    d dl mZmZ d dlmZ ddlmZ ddlmZ  G d de          Z	dS )	    )	np_compatarray_namespace)cached_property   )NestedFixedRule)GaussLegendreQuadraturec                   F    e Zd ZdZddZed             Zed             ZdS )GaussKronrodQuadratureaz
  
    Gauss-Kronrod quadrature.

    Gauss-Kronrod rules consist of two quadrature rules, one higher-order and one
    lower-order. The higher-order rule is used as the estimate of the integral and the
    difference between them is used as an estimate for the error.

    Gauss-Kronrod is a 1D rule. To use it for multidimensional integrals, it will be
    necessary to use ProductNestedFixed and multiple Gauss-Kronrod rules. See Examples.

    For n-node Gauss-Kronrod, the lower-order rule has ``n//2`` nodes, which are the
    ordinary Gauss-Legendre nodes with corresponding weights. The higher-order rule has
    ``n`` nodes, ``n//2`` of which are the same as the lower-order rule and the
    remaining nodes are the Kronrod extension of those nodes.

    Parameters
    ----------
    npoints : int
        Number of nodes for the higher-order rule.

    xp : array_namespace, optional
        The namespace for the node and weight arrays. Default is None, where NumPy is
        used.

    Attributes
    ----------
    lower : Rule
        Lower-order rule.

    References
    ----------
    .. [1] R. Piessens, E. de Doncker, Quadpack: A Subroutine Package for Automatic
        Integration, files: dqk21.f, dqk15.f (1983).

    Examples
    --------
    Evaluate a 1D integral. Note in this example that ``f`` returns an array, so the
    estimates will also be arrays, despite the fact that this is a 1D problem.

    >>> import numpy as np
    >>> from scipy.integrate import cubature
    >>> from scipy.integrate._rules import GaussKronrodQuadrature
    >>> def f(x):
    ...     return np.cos(x)
    >>> rule = GaussKronrodQuadrature(21) # Use 21-point GaussKronrod
    >>> a, b = np.array([0]), np.array([1])
    >>> rule.estimate(f, a, b) # True value sin(1), approximately 0.84147
     array([0.84147098])
    >>> rule.estimate_error(f, a, b)
     array([1.11022302e-16])

    Evaluate a 2D integral. Note that in this example ``f`` returns a float, so the
    estimates will also be floats.

    >>> import numpy as np
    >>> from scipy.integrate import cubature
    >>> from scipy.integrate._rules import (
    ...     ProductNestedFixed, GaussKronrodQuadrature
    ... )
    >>> def f(x):
    ...     # f(x) = cos(x_1) + cos(x_2)
    ...     return np.sum(np.cos(x), axis=-1)
    >>> rule = ProductNestedFixed(
    ...     [GaussKronrodQuadrature(15), GaussKronrodQuadrature(15)]
    ... ) # Use 15-point Gauss-Kronrod
    >>> a, b = np.array([0, 0]), np.array([1, 1])
    >>> rule.estimate(f, a, b) # True value 2*sin(1), approximately 1.6829
     np.float64(1.682941969615793)
    >>> rule.estimate_error(f, a, b)
     np.float64(2.220446049250313e-16)
    Nc                     |dk    r|dk    rt          d          || _        |t          }t          |                    d                    | _        t          |dz  | j                  | _        d S )N      zFGauss-Kronrod quadrature is currently onlysupported for 15 or 21 nodesr      )xp)NotImplementedErrornpointsr   r   emptyr   r   gauss)selfr   r   s      }/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/scipy/integrate/_rules/_gauss_kronrod.py__init__zGaussKronrodQuadrature.__init__R   sz     b==W]]% 'E F F F :B!"((1++..,WaZDGDDD


    c                 x   | j         dk    rQ| j                            g d| j        j                  }| j                            g d| j        j                  }n[| j         dk    rP| j                            g d| j        j                  }| j                            g d| j        j                  }||fS )Nr   )g*'il?g*>*?g?g^?gbltu?g"?g @?gj	?g7^)U?gzxP?r   gzxPÿg7^)Uҿgj	ۿg @g"gbltug^gg*>*g*'il)dtype)?[?B@v?碙?"75?牳׷?珁 ?-]+?Hi&>?la{F?o?g|+!?r#   r"   r!   r    r   r   r   r   r   r   r   )g	M ?g)b|_?g>'?g֡㛟?g$:?gb]?gw.?g        gw.ʿgb]ٿg$:g֡㛟g>'g)b|_g	M )ptg[|?a{&?HӺ?F ?\}f?ah]?؜*?g	O?r*   r)   r(   r'   r&   r%   r$   )r   r   asarrayfloat64)r   nodesweightss      r   nodes_and_weightsz(GaussKronrodQuadrature.nodes_and_weightsb   s     <2GOO  . go1 $  E6 goo  . go1 &  GG4 \RGOO  " go% $  E* goo  " go% &  G* g~r   c                     | j         j        S N)r   r/   )r   s    r   lower_nodes_and_weightsz.GaussKronrodQuadrature.lower_nodes_and_weights   s    z++r   r1   )	__name__
__module____qualname____doc__r   r   r/   propertyr2    r   r   r
   r
   	   ss        F FPE E E E  c c _cJ , , X, , ,r   r
   N)
scipy._lib._array_apir   r   	functoolsr   _baser   _gauss_legendrer   r
   r8   r   r   <module>r=      s    < < < < < < < < % % % % % % " " " " " " 4 4 4 4 4 4A, A, A, A, A,_ A, A, A, A, A,r   