<commit_before># Author: <NAME>

__all__ = ['fixed_quad','quadrature','romberg','trapz','simps','romb','cumtrapz']

from scipy.special.orthogonal import p_roots
from scipy_base import sum, array, ones, add, diff, isinf, isscalar, asarray

def fixed_quad(func,a,b,args=(),n=5):
    """Compute a definite integral using fixed-order Gaussian quadrature.

  Description:

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

  Inputs:

    func -- a Python function or method to integrate
            (must accept vector inputs)
    a -- lower limit of integration
    b -- upper limit of integration
    args -- extra arguments to pass to function.
    n -- order of quadrature integration.

  Outputs: (val, None)

    val -- Gaussian quadrature approximation to the integral.
    
    """
    [x,w] = p_roots(n)
    ainf, binf = map(isinf,(a,b))    
    if ainf or binf:
        raise ValueError, "Gaussian quadrature is only available for finite limits."
    y = (b-a)*(x+1)/2.0 + a
    return (b-a)/2.0*sum(w*func(y,*args)), None

def vec_func(x,func,*args):
    try:
        return asarray([func(xx,*args) for xx in x])
    except TypeError:
        return func(x,*args)
    
def quadrature(func,a,b,args=(),tol=1.49e-8,maxiter=50):
    """Compute a definite integral using fixed-tolerance Gaussian quadrature.

  Description:

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

  Inputs:

    func -- a Python function or method to integrate.
    a -- lower limit of integration.
    b -- upper limit of integration.
    args -- extra arguments to pass to function.
    tol -- iteration stops when error between last two iterates is less than
           tolerance.
    maxiter -- maximum number of iterations.

  Outputs: (val, err)<commit_msg>Fixed Issue159 with quadrature<commit_after># Author: <NAME>

__all__ = ['fixed_quad','quadrature','romberg','trapz','simps','romb','cumtrapz']

from scipy.special.orthogonal import p_roots
from scipy_base import sum, array, ones, add, diff, isinf, isscalar, \
     asarray, real

def fixed_quad(func,a,b,args=(),n=5):
    """Compute a definite integral using fixed-order Gaussian quadrature.

  Description:

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

  Inputs:

    func -- a Python function or method to integrate
            (must accept vector inputs)
    a -- lower limit of integration
    b -- upper limit of integration
    args -- extra arguments to pass to function.
    n -- order of quadrature integration.

  Outputs: (val, None)

    val -- Gaussian quadrature approximation to the integral.
    
    """
    [x,w] = p_roots(n)
    x = real(x)
    ainf, binf = map(isinf,(a,b))    
    if ainf or binf:
        raise ValueError, "Gaussian quadrature is only available for finite limits."
    y = (b-a)*(x+1)/2.0 + a
    return (b-a)/2.0*sum(w*func(y,*args)), None

def vec_func(x,func,*args):
    try:
        return asarray([func(xx,*args) for xx in x])
    except TypeError:
        return func(x,*args)
    
def quadrature(func,a,b,args=(),tol=1.49e-8,maxiter=50):
    """Compute a definite integral using fixed-tolerance Gaussian quadrature.

  Description:

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

  Inputs:

    func -- a Python function or method to integrate.
    a -- lower limit of integration.
    b -- upper limit of integration.
    args -- extra arguments to pass to function.
    tol -- iteration stops when error between last two iterates is less than
           tolerance.
    maxiter -- maximum number of iterations.

  Outputs: (val, err)
{'fraction_non_alphanumeric': 0.10585339168490153, 'fraction_numerical': 0.00738512035010941, 'mean_word_length': 2.9535135135135135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5908474', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1095, 'n_words': 399}