def lambertw(z, k=<NUM_LIT:0>, tol=<NUM_LIT>):

return _lambertw(z, k, tol)<EOL>

r"""
    lambertw(z, k=0, tol=1e-8)

    Lambert W function [1]_.

    The Lambert W function `W(z)` is defined as the inverse function
    of ``w * exp(w)``. In other words, the value of ``W(z)`` is
    such that ``z = W(z) * exp(W(z))`` for any complex number
    ``z``.

    The Lambert W function is a multivalued function with infinitely
    many branches. Each branch gives a separate solution of the
    equation ``z = w exp(w)``. Here, the branches are indexed by the
    integer `k`.

    Parameters
    ----------
    z : array_like
        Input argument.
    k : int, optional
        Branch index.
    tol : float, optional
        Evaluation tolerance.

    Returns
    -------
    w : array
        `w` will have the same shape as `z`.

    Notes
    -----
    All branches are supported by `lambertw`:

    * ``lambertw(z)`` gives the principal solution (branch 0)
    * ``lambertw(z, k)`` gives the solution on branch `k`

    The Lambert W function has two partially real branches: the
    principal branch (`k = 0`) is real for real ``z > -1/e``, and the
    ``k = -1`` branch is real for ``-1/e < z < 0``. All branches except
    ``k = 0`` have a logarithmic singularity at ``z = 0``.

    **Possible issues**

    The evaluation can become inaccurate very close to the branch point
    at ``-1/e``. In some corner cases, `lambertw` might currently
    fail to converge, or can end up on the wrong branch.

    **Algorithm**

    Halley's iteration is used to invert ``w * exp(w)``, using a first-order
    asymptotic approximation (O(log(w)) or `O(w)`) as the initial estimate.

    The definition, implementation and choice of branches is based on [2]_.

    References
    ----------
    .. [1] http://en.wikipedia.org/wiki/Lambert_W_function
    .. [2] Corless et al, "On the Lambert W function", Adv. Comp. Math. 5
       (1996) 329-359.
       http://www.apmaths.uwo.ca/~djeffrey/Offprints/W-adv-cm.pdf

    Examples
    --------
    The Lambert W function is the inverse of ``w exp(w)``:

    >>> from scipy.special import lambertw
    >>> w = lambertw(1)
    >>> w
    (0.56714329040978384+0j)
    >>> w*exp(w)
    (1.0+0j)

    Any branch gives a valid inverse:

    >>> w = lambertw(1, k=3)
    >>> w
    (-2.8535817554090377+17.113535539412148j)
    >>> w*np.exp(w)
    (1.0000000000000002+1.609823385706477e-15j)

    **Applications to equation-solving**

    The Lambert W function may be used to solve various kinds of
    equations, such as finding the value of the infinite power
    tower :math:`z^{z^{z^{\ldots}}}`:

    >>> def tower(z, n):
    ...     if n == 0:
    ...         return z
    ...     return z ** tower(z, n-1)
    ...
    >>> tower(0.5, 100)
    0.641185744504986
    >>> -lambertw(-np.log(0.5)) / np.log(0.5)
    (0.64118574450498589+0j)


a = np.asarray(a)<EOL>if not np.isscalar(d) or (np.floor(d) != d):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if np.any(a <= <NUM_LIT:0.5> * (d - <NUM_LIT:1>)):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% (a, <NUM_LIT:0.5> * (d-<NUM_LIT:1>)))<EOL><DEDENT>res = (d * (d-<NUM_LIT:1>) * <NUM_LIT>) * np.log(np.pi)<EOL>res += np.sum(loggam([(a - (j - <NUM_LIT:1.>)/<NUM_LIT:2>) for j in range(<NUM_LIT:1>, d+<NUM_LIT:1>)]), axis=<NUM_LIT:0>)<EOL>return res<EOL>

Returns the log of multivariate gamma, also sometimes called the
    generalized gamma.

    Parameters
    ----------
    a : ndarray
        The multivariate gamma is computed for each item of `a`.
    d : int
        The dimension of the space of integration.

    Returns
    -------
    res : ndarray
        The values of the log multivariate gamma at the given points `a`.

    Notes
    -----
    The formal definition of the multivariate gamma of dimension d for a real a
    is::

        \Gamma_d(a) = \int_{A>0}{e^{-tr(A)\cdot{|A|}^{a - (m+1)/2}dA}}

    with the condition ``a > (d-1)/2``, and ``A > 0`` being the set of all the
    positive definite matrices of dimension s.  Note that a is a scalar: the
    integrand only is multivariate, the argument is not (the function is
    defined over a subset of the real set).

    This can be proven to be equal to the much friendlier equation::

        \Gamma_d(a) = \pi^{d(d-1)/4}\prod_{i=1}^{d}{\Gamma(a - (i-1)/2)}.

    References
    ----------
    R. J. Muirhead, Aspects of multivariate statistical theory (Wiley Series in
    probability and mathematical statistics).


def generate_loop(func_inputs, func_outputs, func_retval,<EOL>ufunc_inputs, ufunc_outputs):

if len(func_inputs) != len(ufunc_inputs):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(func_outputs) != len(ufunc_outputs) and not (<EOL>func_retval != "<STR_LIT:v>" and len(func_outputs)+<NUM_LIT:1> == len(ufunc_outputs)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>name = "<STR_LIT>" % (<EOL>func_retval, func_inputs, func_outputs, ufunc_inputs, ufunc_outputs<EOL>)<EOL>body = "<STR_LIT>" % name<EOL>body += "<STR_LIT>"<EOL>body += "<STR_LIT>"<EOL>body += "<STR_LIT>"<EOL>for j in range(len(ufunc_inputs)):<EOL><INDENT>body += "<STR_LIT>" % (j, j)<EOL><DEDENT>for j in range(len(ufunc_outputs)):<EOL><INDENT>body += "<STR_LIT>" % (j, j + len(ufunc_inputs))<EOL><DEDENT>ftypes = []<EOL>fvars = []<EOL>outtypecodes = []<EOL>for j in range(len(func_inputs)):<EOL><INDENT>ftypes.append(CY_TYPES[func_inputs[j]])<EOL>fvars.append("<STR_LIT>" % (<EOL>CY_TYPES[func_inputs[j]],<EOL>CY_TYPES[ufunc_inputs[j]], j))<EOL><DEDENT>if len(func_outputs)+<NUM_LIT:1> == len(ufunc_outputs):<EOL><INDENT>func_joff = <NUM_LIT:1><EOL>outtypecodes.append(func_retval)<EOL>body += "<STR_LIT>" % (CY_TYPES[func_retval],)<EOL><DEDENT>else:<EOL><INDENT>func_joff = <NUM_LIT:0><EOL><DEDENT>for j, outtype in enumerate(func_outputs):<EOL><INDENT>body += "<STR_LIT>" % (CY_TYPES[outtype], j+func_joff)<EOL>ftypes.append("<STR_LIT>" % CY_TYPES[outtype])<EOL>fvars.append("<STR_LIT>" % (j+func_joff))<EOL>outtypecodes.append(outtype)<EOL><DEDENT>body += "<STR_LIT>"<EOL>if len(func_outputs)+<NUM_LIT:1> == len(ufunc_outputs):<EOL><INDENT>rv = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>rv = "<STR_LIT>"<EOL><DEDENT>funcall = "<STR_LIT>" % (<EOL>rv, CY_TYPES[func_retval], "<STR_LIT:U+002CU+0020>".join(ftypes), "<STR_LIT:U+002CU+0020>".join(fvars))<EOL>input_checks = []<EOL>for j in range(len(func_inputs)):<EOL><INDENT>if (ufunc_inputs[j], func_inputs[j]) in DANGEROUS_DOWNCAST:<EOL><INDENT>chk = "<STR_LIT>" % (<EOL>CY_TYPES[func_inputs[j]], CY_TYPES[ufunc_inputs[j]], j,<EOL>CY_TYPES[ufunc_inputs[j]], j)<EOL>input_checks.append(chk)<EOL><DEDENT><DEDENT>if input_checks:<EOL><INDENT>body += "<STR_LIT>" % ("<STR_LIT>".join(input_checks))<EOL>body += "<STR_LIT:U+0020>" + funcall<EOL>body += "<STR_LIT>"<EOL>body += "<STR_LIT>"<EOL>for j, outtype in enumerate(outtypecodes):<EOL><INDENT>body += "<STR_LIT>" % (<EOL>j, CY_TYPES[outtype], NAN_VALUE[outtype])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>body += funcall<EOL><DEDENT>for j, (outtype, fouttype) in enumerate(zip(ufunc_outputs, outtypecodes)):<EOL><INDENT>if (fouttype, outtype) in DANGEROUS_DOWNCAST:<EOL><INDENT>body += "<STR_LIT>" % (j, CY_TYPES[outtype], j)<EOL>body += "<STR_LIT>" % (<EOL>CY_TYPES[outtype], j, CY_TYPES[outtype], j)<EOL>body += "<STR_LIT>"<EOL>body += "<STR_LIT>"<EOL>body += "<STR_LIT>" % (<EOL>CY_TYPES[outtype], j, CY_TYPES[outtype], NAN_VALUE[outtype])<EOL><DEDENT>else:<EOL><INDENT>body += "<STR_LIT>" % (<EOL>CY_TYPES[outtype], j, CY_TYPES[outtype], j)<EOL><DEDENT><DEDENT>for j in range(len(ufunc_inputs)):<EOL><INDENT>body += "<STR_LIT>" % (j, j)<EOL><DEDENT>for j in range(len(ufunc_outputs)):<EOL><INDENT>body += "<STR_LIT>" % (j, j + len(ufunc_inputs))<EOL><DEDENT>body += "<STR_LIT>"<EOL>return name, body<EOL>

Generate a UFunc loop function that calls a function given as its
data parameter with the specified input and output arguments and
return value.

This function can be passed to PyUFunc_FromFuncAndData.

Parameters
----------
func_inputs, func_outputs, func_retval : str
    Signature of the function to call, given as type codes of the
    input, output and return value arguments. These 1-character
    codes are given according to the CY_TYPES and TYPE_NAMES
    lists above.

    The corresponding C function signature to be called is:

        retval func(intype1 iv1, intype2 iv2, ..., outtype1 *ov1, ...);

    If len(ufunc_outputs) == len(func_outputs)+1, the return value
    is treated as the first output argument. Otherwise, the return
    value is ignored.

ufunc_inputs, ufunc_outputs : str
    Ufunc input and output signature.

    This does not have to exactly match the function signature,
    as long as the type casts work out on the C level.

Returns
-------
loop_name
    Name of the generated loop function.
loop_body
    Generated C code for the loop.


maps = [<EOL>('<STR_LIT:i>', '<STR_LIT:l>'),<EOL>]<EOL>maps = maps + [(a + '<STR_LIT>', b + '<STR_LIT>') for a, b in maps]<EOL>for src, dst in maps:<EOL><INDENT>new_inputs = inputs<EOL>new_outputs = outputs<EOL>for a, b in zip(src, dst):<EOL><INDENT>new_inputs = new_inputs.replace(a, b)<EOL>new_outputs = new_outputs.replace(a, b)<EOL><DEDENT>yield new_inputs, new_outputs<EOL><DEDENT>

Generate variants of UFunc signatures, by changing variable types,
within the limitation that the corresponding C types casts still
work out.

This does not generate all possibilities, just the ones required
for the ufunc to work properly with the most common data types.

Parameters
----------
inputs, outputs : str
    UFunc input and output signature strings

Yields
------
new_input, new_output : str
    Modified input and output strings.
    Also the original input/output pair is yielded.


def get_declaration(ufunc, c_name, c_proto, cy_proto, header, proto_h_filename):

defs = []<EOL>defs_h = []<EOL>var_name = c_name.replace('<STR_LIT:[>', '<STR_LIT:_>').replace('<STR_LIT:]>', '<STR_LIT:_>').replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>if header.endswith('<STR_LIT>'):<EOL><INDENT>defs.append("<STR_LIT>" % (<EOL>header[:-<NUM_LIT:4>], ufunc.cython_func_name(c_name, prefix="<STR_LIT>"),<EOL>ufunc.cython_func_name(c_name)))<EOL>proto_name = '<STR_LIT>' % var_name<EOL>defs.append("<STR_LIT>" % (cy_proto.replace('<STR_LIT>', proto_name)))<EOL>defs.append("<STR_LIT>" % (<EOL>proto_name, proto_name, ufunc.cython_func_name(c_name, specialized=True)))<EOL><DEDENT>else:<EOL><INDENT>new_name = "<STR_LIT>" % (ufunc.cython_func_name(c_name), c_name)<EOL>defs.append("<STR_LIT>" % proto_h_filename)<EOL>defs.append("<STR_LIT>" % (cy_proto.replace('<STR_LIT>', new_name)))<EOL>defs_h.append("<STR_LIT>" % header)<EOL>defs_h.append("<STR_LIT>" % (c_proto.replace('<STR_LIT>', c_name)))<EOL><DEDENT>return defs, defs_h, var_name<EOL>

Construct a Cython declaration of a function coming either from a
pxd or a header file. Do sufficient tricks to enable compile-time
type checking against the signature expected by the ufunc.


seen = set()<EOL>new_lst = []<EOL>for item in lst:<EOL><INDENT>if item in seen:<EOL><INDENT>continue<EOL><DEDENT>seen.add(item)<EOL>new_lst.append(item)<EOL><DEDENT>return new_lst<EOL>

Return a list without repeated entries (first occurrence is kept),
preserving order.


def _gen_roots_and_weights(n, mu0, an_func, bn_func, f, df, symmetrize, mu):

k = np.arange(n, dtype='<STR_LIT:d>')<EOL>c = np.zeros((<NUM_LIT:2>, n))<EOL>c[<NUM_LIT:0>,<NUM_LIT:1>:] = bn_func(k[<NUM_LIT:1>:])<EOL>c[<NUM_LIT:1>,:] = an_func(k)<EOL>x = linalg.eigvals_banded(c, overwrite_a_band=True)<EOL>y = f(n, x)<EOL>dy = df(n, x)<EOL>x -= y/dy<EOL>fm = f(n-<NUM_LIT:1>, x) <EOL>fm /= np.abs(fm).max()<EOL>dy /= np.abs(dy).max()<EOL>w = <NUM_LIT:1.0> / (fm * dy)<EOL>if symmetrize:<EOL><INDENT>w = (w + w[::-<NUM_LIT:1>]) / <NUM_LIT:2><EOL>x = (x - x[::-<NUM_LIT:1>]) / <NUM_LIT:2><EOL><DEDENT>w *= mu0 / w.sum()<EOL>if mu:<EOL><INDENT>return x, w, mu0<EOL><DEDENT>else:<EOL><INDENT>return x, w<EOL><DEDENT>

[x,w] = gen_roots_and_weights(n,an_func,sqrt_bn_func,mu)

    Returns the roots (x) of an nth order orthogonal polynomial,
    and weights (w) to use in appropriate Gaussian quadrature with that
    orthogonal polynomial.

    The polynomials have the recurrence relation
          P_n+1(x) = (x - A_n) P_n(x) - B_n P_n-1(x)

    an_func(n)          should return A_n
    sqrt_bn_func(n)     should return sqrt(B_n)
    mu ( = h_0 )        is the integral of the weight over the orthogonal
                        interval


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if alpha <= -<NUM_LIT:1> or beta <= -<NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if alpha == <NUM_LIT:0.0> and beta == <NUM_LIT:0.0>:<EOL><INDENT>return p_roots(m, mu)<EOL><DEDENT>if alpha == beta:<EOL><INDENT>return cg_roots(m, alpha+<NUM_LIT:0.5>, mu)<EOL><DEDENT>mu0 = <NUM_LIT>**(alpha+beta+<NUM_LIT:1>)*cephes.beta(alpha+<NUM_LIT:1>, beta+<NUM_LIT:1>)<EOL>a = alpha<EOL>b = beta<EOL>if a + b == <NUM_LIT:0.0>:<EOL><INDENT>an_func = lambda k: np.where(k == <NUM_LIT:0>, (b-a)/(<NUM_LIT:2>+a+b), <NUM_LIT:0.0>)<EOL><DEDENT>else:<EOL><INDENT>an_func = lambda k: np.where(k == <NUM_LIT:0>, (b-a)/(<NUM_LIT:2>+a+b),<EOL>(b*b - a*a) / ((<NUM_LIT>*k+a+b)*(<NUM_LIT>*k+a+b+<NUM_LIT:2>)))<EOL><DEDENT>bn_func = lambda k: <NUM_LIT> / (<NUM_LIT>*k+a+b)*np.sqrt((k+a)*(k+b) / (<NUM_LIT:2>*k+a+b+<NUM_LIT:1>))* np.where(k == <NUM_LIT:1>, <NUM_LIT:1.0>, np.sqrt(k*(k+a+b) / (<NUM_LIT>*k+a+b-<NUM_LIT:1>)))<EOL>f = lambda n, x: cephes.eval_jacobi(n, a, b, x)<EOL>df = lambda n, x: <NUM_LIT:0.5> * (n + a + b + <NUM_LIT:1>)* cephes.eval_jacobi(n-<NUM_LIT:1>, a+<NUM_LIT:1>, b+<NUM_LIT:1>, x)<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, False, mu)<EOL>

Gauss-Jacobi quadrature

    Computes the sample points and weights for Gauss-Jacobi quadrature. The
    sample points are the roots of the `n`th degree Jacobi polynomial,
    :math:`P^{\\alpha, \\beta}_n(x)`.  These sample points and weights
    correctly integrate polynomials of degree :math:`2*n - 1` or less over the
    interval :math:`[-1, 1]` with weight function
    :math:`f(x) = (1 - x)^{\\alpha} (1 + x)^{\\beta}`.

    Parameters
    ----------
    n : int
        quadrature order
    alpha : float
        alpha must be > -1
    beta : float
        beta must be > 0
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


def jacobi(n, alpha, beta, monic=False):

if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>wfunc = lambda x: (<NUM_LIT:1> - x)**alpha * (<NUM_LIT:1> + x)**beta<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return orthopoly1d([], [], <NUM_LIT:1.0>, <NUM_LIT:1.0>, wfunc, (-<NUM_LIT:1>, <NUM_LIT:1>), monic,<EOL>eval_func=np.ones_like)<EOL><DEDENT>x, w, mu = j_roots(n, alpha, beta, mu=True)<EOL>ab1 = alpha + beta + <NUM_LIT:1.0><EOL>hn = <NUM_LIT:2>**ab1 / (<NUM_LIT:2> * n + ab1) * _gam(n + alpha + <NUM_LIT:1>)<EOL>hn *= _gam(n + beta + <NUM_LIT:1.0>) / _gam(n + <NUM_LIT:1>) / _gam(n + ab1)<EOL>kn = _gam(<NUM_LIT:2> * n + ab1) / <NUM_LIT>**n / _gam(n + <NUM_LIT:1>) / _gam(n + ab1)<EOL>p = orthopoly1d(x, w, hn, kn, wfunc, (-<NUM_LIT:1>, <NUM_LIT:1>), monic,<EOL>lambda x: eval_jacobi(n, alpha, beta, x))<EOL>return p<EOL>

Returns the nth order Jacobi polynomial, P^(alpha,beta)_n(x)
    orthogonal over [-1,1] with weighting function
    (1-x)**alpha (1+x)**beta with alpha,beta > -1.


if (p1-q1) <= -<NUM_LIT:1> or q1 <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>xw = j_roots(n, p1-q1, q1-<NUM_LIT:1>, mu)<EOL>return ((xw[<NUM_LIT:0>] + <NUM_LIT:1>) / <NUM_LIT:2>,) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Jacobi (shifted) quadrature

    Computes the sample points and weights for Gauss-Jacobi (shifted)
    quadrature. The sample points are the roots of the `n`th degree shifted
    Jacobi polynomial, :math:`G^{p,q}_n(x)`.  These sample points and weights
    correctly integrate polynomials of degree :math:`2*n - 1` or less over the
    interval :math:`[0, 1]` with weight function
    :math:`f(x) = (1 - x)^{p-q} x^{q-1}`

    Parameters
    ----------
    n : int
        quadrature order
    p1 : float
        (p1 - q1) must be > -1
    q1 : float
        q1 must be > 0
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>wfunc = lambda x: (<NUM_LIT:1.0> - x)**(p - q) * (x)**(q - <NUM_LIT:1.>)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return orthopoly1d([], [], <NUM_LIT:1.0>, <NUM_LIT:1.0>, wfunc, (-<NUM_LIT:1>, <NUM_LIT:1>), monic,<EOL>eval_func=np.ones_like)<EOL><DEDENT>n1 = n<EOL>x, w, mu0 = js_roots(n1, p, q, mu=True)<EOL>hn = _gam(n + <NUM_LIT:1>) * _gam(n + q) * _gam(n + p) * _gam(n + p - q + <NUM_LIT:1>)<EOL>hn /= (<NUM_LIT:2> * n + p) * (_gam(<NUM_LIT:2> * n + p)**<NUM_LIT:2>)<EOL>kn = <NUM_LIT:1.0><EOL>pp = orthopoly1d(x, w, hn, kn, wfunc=wfunc, limits=(<NUM_LIT:0>, <NUM_LIT:1>), monic=monic,<EOL>eval_func=lambda x: eval_sh_jacobi(n, p, q, x))<EOL>return pp<EOL>

Returns the nth order Jacobi polynomial, G_n(p,q,x)
    orthogonal over [0,1] with weighting function
    (1-x)**(p-q) (x)**(q-1) with p>q-1 and q > 0.


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if alpha < -<NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>mu0 = cephes.gamma(alpha + <NUM_LIT:1>)<EOL>if m == <NUM_LIT:1>:<EOL><INDENT>x = np.array([alpha+<NUM_LIT:1.0>], '<STR_LIT:d>')<EOL>w = np.array([mu0], '<STR_LIT:d>')<EOL>if mu:<EOL><INDENT>return x, w, mu0<EOL><DEDENT>else:<EOL><INDENT>return x, w<EOL><DEDENT><DEDENT>an_func = lambda k: <NUM_LIT:2> * k + alpha + <NUM_LIT:1><EOL>bn_func = lambda k: -np.sqrt(k * (k + alpha))<EOL>f = lambda n, x: cephes.eval_genlaguerre(n, alpha, x)<EOL>df = lambda n, x: (n*cephes.eval_genlaguerre(n, alpha, x)<EOL>- (n + alpha)*cephes.eval_genlaguerre(n-<NUM_LIT:1>, alpha, x))/x<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, False, mu)<EOL>

Gauss-generalized Laguerre quadrature

    Computes the sample points and weights for Gauss-generalized Laguerre
    quadrature. The sample points are the roots of the `n`th degree generalized
    Laguerre polynomial, :math:`L^{\\alpha}_n(x)`.  These sample points and
    weights correctly integrate polynomials of degree :math:`2*n - 1` or less
    over the interval :math:`[0, inf]` with weight function
    :math:`f(x) = x^{\\alpha} e^{-x}`.

    Parameters
    ----------
    n : int
        quadrature order
    alpha : float
        alpha must be > -1
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


if any(alpha <= -<NUM_LIT:1>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = la_roots(n1, alpha, mu=True)<EOL>wfunc = lambda x: exp(-x) * x**alpha<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = _gam(n + alpha + <NUM_LIT:1>) / _gam(n + <NUM_LIT:1>)<EOL>kn = (-<NUM_LIT:1>)**n / _gam(n + <NUM_LIT:1>)<EOL>p = orthopoly1d(x, w, hn, kn, wfunc, (<NUM_LIT:0>, inf), monic,<EOL>lambda x: eval_genlaguerre(n, alpha, x))<EOL>return p<EOL>

Returns the nth order generalized (associated) Laguerre polynomial,
    L^(alpha)_n(x), orthogonal over [0,inf) with weighting function
    exp(-x) x**alpha with alpha > -1


return la_roots(n, <NUM_LIT:0.0>, mu=mu)<EOL>

Gauss-Laguerre quadrature

    Computes the sample points and weights for Gauss-Laguerre quadrature.
    The sample points are the roots of the `n`th degree Laguerre polynomial,
    :math:`L_n(x)`.  These sample points and weights correctly integrate
    polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[0, inf]` with weight function :math:`f(x) = e^{-x}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad
    numpy.polynomial.laguerre.laggauss


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = l_roots(n1, mu=True)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = <NUM_LIT:1.0><EOL>kn = (-<NUM_LIT:1>)**n / _gam(n + <NUM_LIT:1>)<EOL>p = orthopoly1d(x, w, hn, kn, lambda x: exp(-x), (<NUM_LIT:0>, inf), monic,<EOL>lambda x: eval_laguerre(n, x))<EOL>return p<EOL>

Return the nth order Laguerre polynoimal, L_n(x), orthogonal over
    [0,inf) with weighting function exp(-x)


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>mu0 = np.sqrt(np.pi)<EOL>an_func = lambda k: <NUM_LIT:0.0>*k<EOL>bn_func = lambda k: np.sqrt(k/<NUM_LIT>)<EOL>f = cephes.eval_hermite<EOL>df = lambda n, x: <NUM_LIT> * n * cephes.eval_hermite(n-<NUM_LIT:1>, x)<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, True, mu)<EOL>

Gauss-Hermite (physicst's) quadrature

    Computes the sample points and weights for Gauss-Hermite quadrature.
    The sample points are the roots of the `n`th degree Hermite polynomial,
    :math:`H_n(x)`.  These sample points and weights correctly integrate
    polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-inf, inf]` with weight function :math:`f(x) = e^{-x^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad
    numpy.polynomial.hermite.hermgauss


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = h_roots(n1, mu=True)<EOL>wfunc = lambda x: exp(-x * x)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = <NUM_LIT:2>**n * _gam(n + <NUM_LIT:1>) * sqrt(pi)<EOL>kn = <NUM_LIT:2>**n<EOL>p = orthopoly1d(x, w, hn, kn, wfunc, (-inf, inf), monic,<EOL>lambda x: eval_hermite(n, x))<EOL>return p<EOL>

Return the nth order Hermite polynomial, H_n(x), orthogonal over
    (-inf,inf) with weighting function exp(-x**2)


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>mu0 = np.sqrt(np.pi/<NUM_LIT>)<EOL>an_func = lambda k: <NUM_LIT:0.0>*k<EOL>bn_func = lambda k: np.sqrt(k)<EOL>f = cephes.eval_hermitenorm<EOL>df = lambda n, x: n * cephes.eval_hermitenorm(n-<NUM_LIT:1>, x)<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, True, mu)<EOL>

Gauss-Hermite (statistician's) quadrature

    Computes the sample points and weights for Gauss-Hermite quadrature.
    The sample points are the roots of the `n`th degree Hermite polynomial,
    :math:`He_n(x)`.  These sample points and weights correctly integrate
    polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-inf, inf]` with weight function :math:`f(x) = e^{-(x/2)^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad
    numpy.polynomial.hermite_e.hermegauss


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = he_roots(n1, mu=True)<EOL>wfunc = lambda x: exp(-x * x / <NUM_LIT>)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = sqrt(<NUM_LIT:2> * pi) * _gam(n + <NUM_LIT:1>)<EOL>kn = <NUM_LIT:1.0><EOL>p = orthopoly1d(x, w, hn, kn, wfunc=wfunc, limits=(-inf, inf), monic=monic,<EOL>eval_func=lambda x: eval_hermitenorm(n, x))<EOL>return p<EOL>

Return the nth order normalized Hermite polynomial, He_n(x), orthogonal
    over (-inf,inf) with weighting function exp(-(x/2)**2)


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if alpha < -<NUM_LIT:0.5>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif alpha == <NUM_LIT:0.0>:<EOL><INDENT>return t_roots(n, mu)<EOL><DEDENT>mu0 = np.sqrt(np.pi) * cephes.gamma(alpha + <NUM_LIT:0.5>) / cephes.gamma(alpha + <NUM_LIT:1>)<EOL>an_func = lambda k: <NUM_LIT:0.0> * k<EOL>bn_func = lambda k: np.sqrt(k * (k + <NUM_LIT:2> * alpha - <NUM_LIT:1>)<EOL>/ (<NUM_LIT:4> * (k + alpha) * (k + alpha - <NUM_LIT:1>)))<EOL>f = lambda n, x: cephes.eval_gegenbauer(n, alpha, x)<EOL>df = lambda n, x: (-n*x*cephes.eval_gegenbauer(n, alpha, x)<EOL>+ (n + <NUM_LIT:2>*alpha - <NUM_LIT:1>)*cephes.eval_gegenbauer(n-<NUM_LIT:1>, alpha, x))/(<NUM_LIT:1>-x**<NUM_LIT:2>)<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, True, mu)<EOL>

Gauss-Gegenbauer quadrature

    Computes the sample points and weights for Gauss-Gegenbauer quadrature.
    The sample points are the roots of the `n`th degree Gegenbauer polynomial,
    :math:`C^{\\alpha}_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-1, 1]` with weight function :math:`f(x) = (1-x^2)^{\\alpha-1/2}`.

    Parameters
    ----------
    n : int
        quadrature order
    alpha : float
        alpha must be > -0.5
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


base = jacobi(n, alpha - <NUM_LIT:0.5>, alpha - <NUM_LIT:0.5>, monic=monic)<EOL>if monic:<EOL><INDENT>return base<EOL><DEDENT>factor = (_gam(<NUM_LIT:2>*alpha + n) * _gam(alpha + <NUM_LIT:0.5>) /<EOL>_gam(<NUM_LIT:2>*alpha) / _gam(alpha + <NUM_LIT:0.5> + n))<EOL>base._scale(factor)<EOL>base.__dict__['<STR_LIT>'] = lambda x: eval_gegenbauer(float(n), alpha, x)<EOL>return base<EOL>

Return the nth order Gegenbauer (ultraspherical) polynomial,
    C^(alpha)_n(x), orthogonal over [-1,1] with weighting function
    (1-x**2)**(alpha-1/2) with alpha > -1/2


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>x = np.cos(np.arange(<NUM_LIT:2> * m - <NUM_LIT:1>, <NUM_LIT:0>, -<NUM_LIT:2>) * pi / (<NUM_LIT:2> * m))<EOL>w = np.empty_like(x)<EOL>w.fill(pi/m)<EOL>if mu:<EOL><INDENT>return x, w, pi<EOL><DEDENT>else:<EOL><INDENT>return x, w<EOL><DEDENT>

Gauss-Chebyshev (first kind) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree Chebyshev polynomial of
    the first kind, :math:`T_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-1, 1]` with weight function :math:`f(x) = 1/\sqrt{1 - x^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad
    numpy.polynomial.chebyshev.chebgauss


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>wfunc = lambda x: <NUM_LIT:1.0> / sqrt(<NUM_LIT:1> - x * x)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return orthopoly1d([], [], pi, <NUM_LIT:1.0>, wfunc, (-<NUM_LIT:1>, <NUM_LIT:1>), monic,<EOL>lambda x: eval_chebyt(n, x))<EOL><DEDENT>n1 = n<EOL>x, w, mu = t_roots(n1, mu=True)<EOL>hn = pi / <NUM_LIT:2><EOL>kn = <NUM_LIT:2>**(n - <NUM_LIT:1>)<EOL>p = orthopoly1d(x, w, hn, kn, wfunc, (-<NUM_LIT:1>, <NUM_LIT:1>), monic,<EOL>lambda x: eval_chebyt(n, x))<EOL>return p<EOL>

Return nth order Chebyshev polynomial of first kind, Tn(x).  Orthogonal
    over [-1,1] with weight function (1-x**2)**(-1/2).


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>t = np.arange(m, <NUM_LIT:0>, -<NUM_LIT:1>) * pi / (m + <NUM_LIT:1>)<EOL>x = np.cos(t)<EOL>w = pi * np.sin(t)**<NUM_LIT:2> / (m + <NUM_LIT:1>)<EOL>if mu:<EOL><INDENT>return x, w, pi / <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>return x, w<EOL><DEDENT>

Gauss-Chebyshev (second kind) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree Chebyshev polynomial of
    the second kind, :math:`U_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-1, 1]` with weight function :math:`f(x) = \sqrt{1 - x^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


base = jacobi(n, <NUM_LIT:0.5>, <NUM_LIT:0.5>, monic=monic)<EOL>if monic:<EOL><INDENT>return base<EOL><DEDENT>factor = sqrt(pi) / <NUM_LIT> * _gam(n + <NUM_LIT:2>) / _gam(n + <NUM_LIT>)<EOL>base._scale(factor)<EOL>return base<EOL>

Return nth order Chebyshev polynomial of second kind, Un(x).  Orthogonal
    over [-1,1] with weight function (1-x**2)**(1/2).


xw = t_roots(n, mu)<EOL>return (<NUM_LIT:2> * xw[<NUM_LIT:0>],) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Chebyshev (first kind) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree Chebyshev polynomial of
    the first kind, :math:`C_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-2, 2]` with weight function :math:`f(x) = 1/\sqrt{1 - (x/2)^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = c_roots(n1, mu=True)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = <NUM_LIT:4> * pi * ((n == <NUM_LIT:0>) + <NUM_LIT:1>)<EOL>kn = <NUM_LIT:1.0><EOL>p = orthopoly1d(x, w, hn, kn,<EOL>wfunc=lambda x: <NUM_LIT:1.0> / sqrt(<NUM_LIT:1> - x * x / <NUM_LIT>),<EOL>limits=(-<NUM_LIT:2>, <NUM_LIT:2>), monic=monic)<EOL>if not monic:<EOL><INDENT>p._scale(<NUM_LIT> / p(<NUM_LIT:2>))<EOL>p.__dict__['<STR_LIT>'] = lambda x: eval_chebyc(n, x)<EOL><DEDENT>return p<EOL>

Return nth order Chebyshev polynomial of first kind, Cn(x).  Orthogonal
    over [-2,2] with weight function (1-(x/2)**2)**(-1/2).


xw = u_roots(n, mu)<EOL>return (<NUM_LIT:2> * xw[<NUM_LIT:0>],) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Chebyshev (second kind) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree Chebyshev polynomial of
    the second kind, :math:`S_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-2, 2]` with weight function :math:`f(x) = \sqrt{1 - (x/2)^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = s_roots(n1, mu=True)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = pi<EOL>kn = <NUM_LIT:1.0><EOL>p = orthopoly1d(x, w, hn, kn,<EOL>wfunc=lambda x: sqrt(<NUM_LIT:1> - x * x / <NUM_LIT>),<EOL>limits=(-<NUM_LIT:2>, <NUM_LIT:2>), monic=monic)<EOL>if not monic:<EOL><INDENT>factor = (n + <NUM_LIT:1.0>) / p(<NUM_LIT:2>)<EOL>p._scale(factor)<EOL>p.__dict__['<STR_LIT>'] = lambda x: eval_chebys(n, x)<EOL><DEDENT>return p<EOL>

Return nth order Chebyshev polynomial of second kind, Sn(x).  Orthogonal
    over [-2,2] with weight function (1-(x/)**2)**(1/2).


xw = t_roots(n, mu)<EOL>return ((xw[<NUM_LIT:0>] + <NUM_LIT:1>) / <NUM_LIT:2>,) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Chebyshev (first kind, shifted) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree shifted Chebyshev
    polynomial of the first kind, :math:`T_n(x)`.  These sample points and
    weights correctly integrate polynomials of degree :math:`2*n - 1` or less
    over the interval :math:`[0, 1]` with weight function
    :math:`f(x) = 1/\sqrt{x - x^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


base = sh_jacobi(n, <NUM_LIT:0.0>, <NUM_LIT:0.5>, monic=monic)<EOL>if monic:<EOL><INDENT>return base<EOL><DEDENT>if n > <NUM_LIT:0>:<EOL><INDENT>factor = <NUM_LIT:4>**n / <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>factor = <NUM_LIT:1.0><EOL><DEDENT>base._scale(factor)<EOL>return base<EOL>

Return nth order shifted Chebyshev polynomial of first kind, Tn(x).
    Orthogonal over [0,1] with weight function (x-x**2)**(-1/2).


xw = u_roots(n, mu)<EOL>return ((xw[<NUM_LIT:0>] + <NUM_LIT:1>) / <NUM_LIT:2>,) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Chebyshev (second kind, shifted) quadrature

    Computes the sample points and weights for Gauss-Chebyshev quadrature.
    The sample points are the roots of the `n`th degree shifted Chebyshev
    polynomial of the second kind, :math:`U_n(x)`.  These sample points and
    weights correctly integrate polynomials of degree :math:`2*n - 1` or less
    over the interval :math:`[0, 1]` with weight function
    :math:`f(x) = \sqrt{x - x^2}`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


base = sh_jacobi(n, <NUM_LIT>, <NUM_LIT>, monic=monic)<EOL>if monic:<EOL><INDENT>return base<EOL><DEDENT>factor = <NUM_LIT:4>**n<EOL>base._scale(factor)<EOL>return base<EOL>

Return nth order shifted Chebyshev polynomial of second kind, Un(x).
    Orthogonal over [0,1] with weight function (x-x**2)**(1/2).


m = int(n)<EOL>if n < <NUM_LIT:1> or n != m:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>mu0 = <NUM_LIT><EOL>an_func = lambda k: <NUM_LIT:0.0> * k<EOL>bn_func = lambda k: k * np.sqrt(<NUM_LIT:1.0> / (<NUM_LIT:4> * k * k - <NUM_LIT:1>))<EOL>f = cephes.eval_legendre<EOL>df = lambda n, x: (-n*x*cephes.eval_legendre(n, x)<EOL>+ n*cephes.eval_legendre(n-<NUM_LIT:1>, x))/(<NUM_LIT:1>-x**<NUM_LIT:2>)<EOL>return _gen_roots_and_weights(m, mu0, an_func, bn_func, f, df, True, mu)<EOL>

Gauss-Legendre quadrature

    Computes the sample points and weights for Gauss-Legendre quadrature.
    The sample points are the roots of the `n`th degree Legendre polynomial
    :math:`P_n(x)`.  These sample points and weights correctly integrate
    polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[-1, 1]` with weight function :math:`f(x) = 1.0`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad
    numpy.polynomial.legendre.leggauss


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n == <NUM_LIT:0>:<EOL><INDENT>n1 = n + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>n1 = n<EOL><DEDENT>x, w, mu0 = p_roots(n1, mu=True)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>x, w = [], []<EOL><DEDENT>hn = <NUM_LIT> / (<NUM_LIT:2> * n + <NUM_LIT:1>)<EOL>kn = _gam(<NUM_LIT:2> * n + <NUM_LIT:1>) / _gam(n + <NUM_LIT:1>)**<NUM_LIT:2> / <NUM_LIT>**n<EOL>p = orthopoly1d(x, w, hn, kn, wfunc=lambda x: <NUM_LIT:1.0>, limits=(-<NUM_LIT:1>, <NUM_LIT:1>),<EOL>monic=monic, eval_func=lambda x: eval_legendre(n, x))<EOL>return p<EOL>

Legendre polynomial coefficients

Returns the nth-order Legendre polynomial, P_n(x), orthogonal over
[-1, 1] with weight function 1.

Parameters
----------
n
    Order of the polynomial
monic : bool, optional
    If True, output is a monic polynomial (normalized so the leading
    coefficient is 1).  Default is False.

Returns
-------
P : orthopoly1d
    The Legendre polynomial object

Examples
--------
Generate the 3rd-order Legendre polynomial 1/2*(5x^3 + 0x^2 - 3x + 0):

>>> legendre(3)
poly1d([ 2.5,  0. , -1.5, -0. ])


xw = p_roots(n, mu)<EOL>return ((xw[<NUM_LIT:0>] + <NUM_LIT:1>) / <NUM_LIT:2>,) + xw[<NUM_LIT:1>:]<EOL>

Gauss-Legendre (shifted) quadrature

    Computes the sample points and weights for Gauss-Legendre quadrature.
    The sample points are the roots of the `n`th degree shifted Legendre
    polynomial :math:`P^*_n(x)`.  These sample points and weights correctly
    integrate polynomials of degree :math:`2*n - 1` or less over the interval
    :math:`[0, 1]` with weight function :math:`f(x) = 1.0`.

    Parameters
    ----------
    n : int
        quadrature order
    mu : boolean
        If True, return the sum of the weights, optional.

    Returns
    -------
    x : ndarray
        Sample points
    w : ndarray
        Weights
    mu : float
        Sum of the weights

    See Also
    --------
    integrate.quadrature
    integrate.fixed_quad


if n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>wfunc = lambda x: <NUM_LIT:0.0> * x + <NUM_LIT:1.0><EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return orthopoly1d([], [], <NUM_LIT:1.0>, <NUM_LIT:1.0>, wfunc, (<NUM_LIT:0>, <NUM_LIT:1>), monic,<EOL>lambda x: eval_sh_legendre(n, x))<EOL><DEDENT>x, w, mu0 = ps_roots(n, mu=True)<EOL>hn = <NUM_LIT:1.0> / (<NUM_LIT:2> * n + <NUM_LIT:1.0>)<EOL>kn = _gam(<NUM_LIT:2> * n + <NUM_LIT:1>) / _gam(n + <NUM_LIT:1>)**<NUM_LIT:2><EOL>p = orthopoly1d(x, w, hn, kn, wfunc, limits=(<NUM_LIT:0>, <NUM_LIT:1>), monic=monic,<EOL>eval_func=lambda x: eval_sh_legendre(n, x))<EOL>return p<EOL>

Returns the nth order shifted Legendre polynomial, P^*_n(x), orthogonal
    over [0,1] with weighting function 1.


def dct(x, type=<NUM_LIT:2>, n=None, axis=-<NUM_LIT:1>, norm=None, overwrite_x=False):

if type == <NUM_LIT:1> and norm is not None:<EOL><INDENT>raise NotImplementedError(<EOL>"<STR_LIT>")<EOL><DEDENT>return _dct(x, type, n, axis, normalize=norm, overwrite_x=overwrite_x)<EOL>

Return the Discrete Cosine Transform of arbitrary type sequence x.

Parameters
----------
x : array_like
    The input array.
type : {1, 2, 3}, optional
    Type of the DCT (see Notes). Default type is 2.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis over which to compute the transform.
norm : {None, 'ortho'}, optional
    Normalization mode (see Notes). Default is None.
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
y : ndarray of real
    The transformed input array.

See Also
--------
idct : Inverse DCT

Notes
-----
For a single dimension array ``x``, ``dct(x, norm='ortho')`` is equal to
MATLAB ``dct(x)``.

There are theoretically 8 types of the DCT, only the first 3 types are
implemented in scipy. 'The' DCT generally refers to DCT type 2, and 'the'
Inverse DCT generally refers to DCT type 3.

**Type I**

There are several definitions of the DCT-I; we use the following
(for ``norm=None``)::

                                     N-2
  y[k] = x[0] + (-1)**k x[N-1] + 2 * sum x[n]*cos(pi*k*n/(N-1))
                                     n=1

Only None is supported as normalization mode for DCT-I. Note also that the
DCT-I is only supported for input size > 1

**Type II**

There are several definitions of the DCT-II; we use the following
(for ``norm=None``)::

            N-1
  y[k] = 2* sum x[n]*cos(pi*k*(2n+1)/(2*N)), 0 <= k < N.
            n=0

If ``norm='ortho'``, ``y[k]`` is multiplied by a scaling factor `f`::

  f = sqrt(1/(4*N)) if k = 0,
  f = sqrt(1/(2*N)) otherwise.

Which makes the corresponding matrix of coefficients orthonormal
(``OO' = Id``).

**Type III**

There are several definitions, we use the following
(for ``norm=None``)::

                    N-1
  y[k] = x[0] + 2 * sum x[n]*cos(pi*(k+0.5)*n/N), 0 <= k < N.
                    n=1

or, for ``norm='ortho'`` and 0 <= k < N::

                                      N-1
  y[k] = x[0] / sqrt(N) + sqrt(2/N) * sum x[n]*cos(pi*(k+0.5)*n/N)
                                      n=1

The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up
to a factor `2N`. The orthonormalized DCT-III is exactly the inverse of
the orthonormalized DCT-II.

References
----------
.. [1] 'A Fast Cosine Transform in One and Two Dimensions', by J.
       Makhoul, `IEEE Transactions on acoustics, speech and signal
       processing` vol. 28(1), pp. 27-34,
       http://dx.doi.org/10.1109/TASSP.1980.1163351 (1980).
.. [2] Wikipedia, "Discrete cosine transform",
       http://en.wikipedia.org/wiki/Discrete_cosine_transform

Examples
--------
The Type 1 DCT is equivalent to the FFT (though faster) for real,
even-symmetrical inputs.  The output is also real and even-symmetrical.
Half of the FFT input is used to generate half of the FFT output:

>>> fft(array([4., 3., 5., 10., 5., 3.])).real
array([ 30.,  -8.,   6.,  -2.,   6.,  -8.])
>>> dct(array([4., 3., 5., 10.]), 1)
array([ 30.,  -8.,   6.,  -2.])


def idct(x, type=<NUM_LIT:2>, n=None, axis=-<NUM_LIT:1>, norm=None, overwrite_x=False):

if type == <NUM_LIT:1> and norm is not None:<EOL><INDENT>raise NotImplementedError(<EOL>"<STR_LIT>")<EOL><DEDENT>_TP = {<NUM_LIT:1>:<NUM_LIT:1>, <NUM_LIT:2>:<NUM_LIT:3>, <NUM_LIT:3>:<NUM_LIT:2>}<EOL>return _dct(x, _TP[type], n, axis, normalize=norm, overwrite_x=overwrite_x)<EOL>

Return the Inverse Discrete Cosine Transform of an arbitrary type sequence.

Parameters
----------
x : array_like
    The input array.
type : {1, 2, 3}, optional
    Type of the DCT (see Notes). Default type is 2.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis over which to compute the transform.
norm : {None, 'ortho'}, optional
    Normalization mode (see Notes). Default is None.
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
idct : ndarray of real
    The transformed input array.

See Also
--------
dct : Forward DCT

Notes
-----
For a single dimension array `x`, ``idct(x, norm='ortho')`` is equal to
MATLAB ``idct(x)``.

'The' IDCT is the IDCT of type 2, which is the same as DCT of type 3.

IDCT of type 1 is the DCT of type 1, IDCT of type 2 is the DCT of type
3, and IDCT of type 3 is the DCT of type 2. For the definition of these
types, see `dct`.

Examples
--------
The Type 1 DCT is equivalent to the DFT for real, even-symmetrical
inputs.  The output is also real and even-symmetrical.  Half of the IFFT
input is used to generate half of the IFFT output:

>>> ifft(array([ 30.,  -8.,   6.,  -2.,   6.,  -8.])).real
array([  4.,   3.,   5.,  10.,   5.,   3.])
>>> idct(array([ 30.,  -8.,   6.,  -2.]), 1) / 6
array([  4.,   3.,   5.,  10.])


def _dct(x, type, n=None, axis=-<NUM_LIT:1>, overwrite_x=False, normalize=None):

tmp = np.asarray(x)<EOL>if not np.isrealobj(tmp):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if n is None:<EOL><INDENT>n = tmp.shape[axis]<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>if tmp.dtype == np.double:<EOL><INDENT>if type == <NUM_LIT:1>:<EOL><INDENT>f = _fftpack.ddct1<EOL><DEDENT>elif type == <NUM_LIT:2>:<EOL><INDENT>f = _fftpack.ddct2<EOL><DEDENT>elif type == <NUM_LIT:3>:<EOL><INDENT>f = _fftpack.ddct3<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT><DEDENT>elif tmp.dtype == np.float32:<EOL><INDENT>if type == <NUM_LIT:1>:<EOL><INDENT>f = _fftpack.dct1<EOL><DEDENT>elif type == <NUM_LIT:2>:<EOL><INDENT>f = _fftpack.dct2<EOL><DEDENT>elif type == <NUM_LIT:3>:<EOL><INDENT>f = _fftpack.dct3<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>if normalize:<EOL><INDENT>if normalize == "<STR_LIT>":<EOL><INDENT>nm = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % normalize)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>nm = <NUM_LIT:0><EOL><DEDENT>if type == <NUM_LIT:1> and n < <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>if axis == -<NUM_LIT:1> or axis == len(tmp.shape) - <NUM_LIT:1>:<EOL><INDENT>return f(tmp, n, nm, overwrite_x)<EOL><DEDENT>tmp = np.swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>tmp = f(tmp, n, nm, overwrite_x)<EOL>return np.swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>

Return Discrete Cosine Transform of arbitrary type sequence x.

Parameters
----------
x : array-like
    input array.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis along which the dct is computed. (default=-1)
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
z : real ndarray


def dst(x, type=<NUM_LIT:2>, n=None, axis=-<NUM_LIT:1>, norm=None, overwrite_x=False):

if type == <NUM_LIT:1> and norm is not None:<EOL><INDENT>raise NotImplementedError(<EOL>"<STR_LIT>")<EOL><DEDENT>return _dst(x, type, n, axis, normalize=norm, overwrite_x=overwrite_x)<EOL>

Return the Discrete Sine Transform of arbitrary type sequence x.

Parameters
----------
x : array_like
    The input array.
type : {1, 2, 3}, optional
    Type of the DST (see Notes). Default type is 2.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis over which to compute the transform.
norm : {None, 'ortho'}, optional
    Normalization mode (see Notes). Default is None.
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
dst : ndarray of reals
    The transformed input array.

See Also
--------
idst : Inverse DST

Notes
-----
For a single dimension array ``x``.

There are theoretically 8 types of the DST for different combinations of
even/odd boundary conditions and boundary off sets [1]_, only the first
3 types are implemented in scipy.

**Type I**

There are several definitions of the DST-I; we use the following
for ``norm=None``.  DST-I assumes the input is odd around n=-1 and n=N. ::

             N-1
  y[k] = 2 * sum x[n]*sin(pi*(k+1)*(n+1)/(N+1))
             n=0

Only None is supported as normalization mode for DCT-I. Note also that the
DCT-I is only supported for input size > 1
The (unnormalized) DCT-I is its own inverse, up to a factor `2(N+1)`.

**Type II**

There are several definitions of the DST-II; we use the following
for ``norm=None``.  DST-II assumes the input is odd around n=-1/2 and
n=N-1/2; the output is odd around k=-1 and even around k=N-1 ::

            N-1
  y[k] = 2* sum x[n]*sin(pi*(k+1)*(n+0.5)/N), 0 <= k < N.
            n=0

if ``norm='ortho'``, ``y[k]`` is multiplied by a scaling factor `f` ::

    f = sqrt(1/(4*N)) if k == 0
    f = sqrt(1/(2*N)) otherwise.

**Type III**

There are several definitions of the DST-III, we use the following
(for ``norm=None``).  DST-III assumes the input is odd around n=-1
and even around n=N-1 ::

                             N-2
  y[k] = x[N-1]*(-1)**k + 2* sum x[n]*sin(pi*(k+0.5)*(n+1)/N), 0 <= k < N.
                             n=0

The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up
to a factor `2N`.  The orthonormalized DST-III is exactly the inverse of
the orthonormalized DST-II.

.. versionadded:: 0.11.0

References
----------
.. [1] Wikipedia, "Discrete sine transform",
       http://en.wikipedia.org/wiki/Discrete_sine_transform


def idst(x, type=<NUM_LIT:2>, n=None, axis=-<NUM_LIT:1>, norm=None, overwrite_x=False):

if type == <NUM_LIT:1> and norm is not None:<EOL><INDENT>raise NotImplementedError(<EOL>"<STR_LIT>")<EOL><DEDENT>_TP = {<NUM_LIT:1>:<NUM_LIT:1>, <NUM_LIT:2>:<NUM_LIT:3>, <NUM_LIT:3>:<NUM_LIT:2>}<EOL>return _dst(x, _TP[type], n, axis, normalize=norm, overwrite_x=overwrite_x)<EOL>

Return the Inverse Discrete Sine Transform of an arbitrary type sequence.

Parameters
----------
x : array_like
    The input array.
type : {1, 2, 3}, optional
    Type of the DST (see Notes). Default type is 2.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis over which to compute the transform.
norm : {None, 'ortho'}, optional
    Normalization mode (see Notes). Default is None.
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
idst : ndarray of real
    The transformed input array.

See Also
--------
dst : Forward DST

Notes
-----
'The' IDST is the IDST of type 2, which is the same as DST of type 3.

IDST of type 1 is the DST of type 1, IDST of type 2 is the DST of type
3, and IDST of type 3 is the DST of type 2. For the definition of these
types, see `dst`.

.. versionadded:: 0.11.0


def _dst(x, type, n=None, axis=-<NUM_LIT:1>, overwrite_x=False, normalize=None):

tmp = np.asarray(x)<EOL>if not np.isrealobj(tmp):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if n is None:<EOL><INDENT>n = tmp.shape[axis]<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>if tmp.dtype == np.double:<EOL><INDENT>if type == <NUM_LIT:1>:<EOL><INDENT>f = _fftpack.ddst1<EOL><DEDENT>elif type == <NUM_LIT:2>:<EOL><INDENT>f = _fftpack.ddst2<EOL><DEDENT>elif type == <NUM_LIT:3>:<EOL><INDENT>f = _fftpack.ddst3<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT><DEDENT>elif tmp.dtype == np.float32:<EOL><INDENT>if type == <NUM_LIT:1>:<EOL><INDENT>f = _fftpack.dst1<EOL><DEDENT>elif type == <NUM_LIT:2>:<EOL><INDENT>f = _fftpack.dst2<EOL><DEDENT>elif type == <NUM_LIT:3>:<EOL><INDENT>f = _fftpack.dst3<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>if normalize:<EOL><INDENT>if normalize == "<STR_LIT>":<EOL><INDENT>nm = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % normalize)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>nm = <NUM_LIT:0><EOL><DEDENT>if type == <NUM_LIT:1> and n < <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>if axis == -<NUM_LIT:1> or axis == len(tmp.shape) - <NUM_LIT:1>:<EOL><INDENT>return f(tmp, n, nm, overwrite_x)<EOL><DEDENT>tmp = np.swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>tmp = f(tmp, n, nm, overwrite_x)<EOL>return np.swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>

Return Discrete Sine Transform of arbitrary type sequence x.

Parameters
----------
x : array-like
    input array.
n : int, optional
    Length of the transform.
axis : int, optional
    Axis along which the dst is computed. (default=-1)
overwrite_x : bool, optional
    If True the contents of x can be destroyed. (default=False)

Returns
-------
z : real ndarray


if arr is original:<EOL><INDENT>return False<EOL><DEDENT>if not isinstance(original, numpy.ndarray) and hasattr(original, '<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>return arr.base is None<EOL>

Strict check for `arr` not sharing any data with `original`,
under the assumption that arr = asarray(original)


n = int(n)<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return True<EOL><DEDENT>for c in (<NUM_LIT:3>, <NUM_LIT:5>):<EOL><INDENT>while n % c == <NUM_LIT:0>:<EOL><INDENT>n //= c<EOL><DEDENT><DEDENT>return not n & (n-<NUM_LIT:1>)<EOL>

Is the size of FFT such that FFTPACK can handle it in single precision
with sufficient accuracy?

Composite numbers of 2, 3, and 5 are accepted, as FFTPACK has those


if hasattr(x, "<STR_LIT>") and x.dtype.char in numpy.typecodes["<STR_LIT>"]:<EOL><INDENT>return x<EOL><DEDENT>else:<EOL><INDENT>ret = numpy.asarray(x)<EOL>if ret.dtype.char not in numpy.typecodes["<STR_LIT>"]:<EOL><INDENT>return numpy.asfarray(x)<EOL><DEDENT>return ret<EOL><DEDENT>

Like numpy asfarray, except that it does not modify x dtype if x is
    already an array with a float dtype, and do not cast complex types to
    real.


s = list(x.shape)<EOL>if s[axis] > n:<EOL><INDENT>index = [slice(None)]*len(s)<EOL>index[axis] = slice(<NUM_LIT:0>,n)<EOL>x = x[index]<EOL>return x, False<EOL><DEDENT>else:<EOL><INDENT>index = [slice(None)]*len(s)<EOL>index[axis] = slice(<NUM_LIT:0>,s[axis])<EOL>s[axis] = n<EOL>z = zeros(s,x.dtype.char)<EOL>z[index] = x<EOL>return z, True<EOL><DEDENT>

Internal auxiliary function for _raw_fft, _raw_fftnd.


def _raw_fft(x, n, axis, direction, overwrite_x, work_function):

if n is None:<EOL><INDENT>n = x.shape[axis]<EOL><DEDENT>elif n != x.shape[axis]:<EOL><INDENT>x, copy_made = _fix_shape(x,n,axis)<EOL>overwrite_x = overwrite_x or copy_made<EOL><DEDENT>if n < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % n)<EOL><DEDENT>if axis == -<NUM_LIT:1> or axis == len(x.shape)-<NUM_LIT:1>:<EOL><INDENT>r = work_function(x,n,direction,overwrite_x=overwrite_x)<EOL><DEDENT>else:<EOL><INDENT>x = swapaxes(x, axis, -<NUM_LIT:1>)<EOL>r = work_function(x,n,direction,overwrite_x=overwrite_x)<EOL>r = swapaxes(r, axis, -<NUM_LIT:1>)<EOL><DEDENT>return r<EOL>

Internal auxiliary function for fft, ifft, rfft, irfft.


def fft(x, n=None, axis=-<NUM_LIT:1>, overwrite_x=False):

tmp = _asfarray(x)<EOL>try:<EOL><INDENT>work_function = _DTYPE_TO_FFT[tmp.dtype]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>if not (istype(tmp, numpy.complex64) or istype(tmp, numpy.complex128)):<EOL><INDENT>overwrite_x = <NUM_LIT:1><EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>if n is None:<EOL><INDENT>n = tmp.shape[axis]<EOL><DEDENT>elif n != tmp.shape[axis]:<EOL><INDENT>tmp, copy_made = _fix_shape(tmp,n,axis)<EOL>overwrite_x = overwrite_x or copy_made<EOL><DEDENT>if n < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % n)<EOL><DEDENT>if axis == -<NUM_LIT:1> or axis == len(tmp.shape) - <NUM_LIT:1>:<EOL><INDENT>return work_function(tmp,n,<NUM_LIT:1>,<NUM_LIT:0>,overwrite_x)<EOL><DEDENT>tmp = swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>tmp = work_function(tmp,n,<NUM_LIT:1>,<NUM_LIT:0>,overwrite_x)<EOL>return swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>

Return discrete Fourier transform of real or complex sequence.

The returned complex array contains ``y(0), y(1),..., y(n-1)`` where

``y(j) = (x * exp(-2*pi*sqrt(-1)*j*np.arange(n)/n)).sum()``.

Parameters
----------
x : array_like
    Array to Fourier transform.
n : int, optional
    Length of the Fourier transform.  If ``n < x.shape[axis]``, `x` is
    truncated.  If ``n > x.shape[axis]``, `x` is zero-padded. The
    default results in ``n = x.shape[axis]``.
axis : int, optional
    Axis along which the fft's are computed; the default is over the
    last axis (i.e., ``axis=-1``).
overwrite_x : bool, optional
    If True, the contents of `x` can be destroyed; the default is False.

Returns
-------
z : complex ndarray
    with the elements::

        [y(0),y(1),..,y(n/2),y(1-n/2),...,y(-1)]        if n is even
        [y(0),y(1),..,y((n-1)/2),y(-(n-1)/2),...,y(-1)]  if n is odd

    where::

        y(j) = sum[k=0..n-1] x[k] * exp(-sqrt(-1)*j*k* 2*pi/n), j = 0..n-1

    Note that ``y(-j) = y(n-j).conjugate()``.

See Also
--------
ifft : Inverse FFT
rfft : FFT of a real sequence

Notes
-----
The packing of the result is "standard": If ``A = fft(a, n)``, then
``A[0]`` contains the zero-frequency term, ``A[1:n/2]`` contains the
positive-frequency terms, and ``A[n/2:]`` contains the negative-frequency
terms, in order of decreasingly negative frequency. So for an 8-point
transform, the frequencies of the result are [0, 1, 2, 3, -4, -3, -2, -1].
To rearrange the fft output so that the zero-frequency component is
centered, like [-4, -3, -2, -1,  0,  1,  2,  3], use `fftshift`.

For `n` even, ``A[n/2]`` contains the sum of the positive and
negative-frequency terms.  For `n` even and `x` real, ``A[n/2]`` will
always be real.

This function is most efficient when `n` is a power of two, and least
efficient when `n` is prime.

If the data type of `x` is real, a "real FFT" algorithm is automatically
used, which roughly halves the computation time.  To increase efficiency
a little further, use `rfft`, which does the same calculation, but only
outputs half of the symmetrical spectrum.  If the data is both real and
symmetrical, the `dct` can again double the efficiency, by generating
half of the spectrum from half of the signal.

Examples
--------
>>> from scipy.fftpack import fft, ifft
>>> x = np.arange(5)
>>> np.allclose(fft(ifft(x)), x, atol=1e-15)  # within numerical accuracy.
True


def ifft(x, n=None, axis=-<NUM_LIT:1>, overwrite_x=False):

tmp = _asfarray(x)<EOL>try:<EOL><INDENT>work_function = _DTYPE_TO_FFT[tmp.dtype]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>if not (istype(tmp, numpy.complex64) or istype(tmp, numpy.complex128)):<EOL><INDENT>overwrite_x = <NUM_LIT:1><EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>if n is None:<EOL><INDENT>n = tmp.shape[axis]<EOL><DEDENT>elif n != tmp.shape[axis]:<EOL><INDENT>tmp, copy_made = _fix_shape(tmp,n,axis)<EOL>overwrite_x = overwrite_x or copy_made<EOL><DEDENT>if n < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % n)<EOL><DEDENT>if axis == -<NUM_LIT:1> or axis == len(tmp.shape) - <NUM_LIT:1>:<EOL><INDENT>return work_function(tmp,n,-<NUM_LIT:1>,<NUM_LIT:1>,overwrite_x)<EOL><DEDENT>tmp = swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>tmp = work_function(tmp,n,-<NUM_LIT:1>,<NUM_LIT:1>,overwrite_x)<EOL>return swapaxes(tmp, axis, -<NUM_LIT:1>)<EOL>

Return discrete inverse Fourier transform of real or complex sequence.

The returned complex array contains ``y(0), y(1),..., y(n-1)`` where

``y(j) = (x * exp(2*pi*sqrt(-1)*j*np.arange(n)/n)).mean()``.

Parameters
----------
x : array_like
    Transformed data to invert.
n : int, optional
    Length of the inverse Fourier transform.  If ``n < x.shape[axis]``,
    `x` is truncated.  If ``n > x.shape[axis]``, `x` is zero-padded.
    The default results in ``n = x.shape[axis]``.
axis : int, optional
    Axis along which the ifft's are computed; the default is over the
    last axis (i.e., ``axis=-1``).
overwrite_x : bool, optional
    If True, the contents of `x` can be destroyed; the default is False.

Returns
-------
ifft : ndarray of floats
    The inverse discrete Fourier transform.

See Also
--------
fft : Forward FFT

Notes
-----
This function is most efficient when `n` is a power of two, and least
efficient when `n` is prime.

If the data type of `x` is real, a "real IFFT" algorithm is automatically
used, which roughly halves the computation time.


def rfft(x, n=None, axis=-<NUM_LIT:1>, overwrite_x=False):

tmp = _asfarray(x)<EOL>if not numpy.isrealobj(tmp):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>work_function = _DTYPE_TO_RFFT[tmp.dtype]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>return _raw_fft(tmp,n,axis,<NUM_LIT:1>,overwrite_x,work_function)<EOL>

Discrete Fourier transform of a real sequence.

Parameters
----------
x : array_like, real-valued
    The data to transform.
n : int, optional
    Defines the length of the Fourier transform.  If `n` is not specified
    (the default) then ``n = x.shape[axis]``.  If ``n < x.shape[axis]``,
    `x` is truncated, if ``n > x.shape[axis]``, `x` is zero-padded.
axis : int, optional
    The axis along which the transform is applied.  The default is the
    last axis.
overwrite_x : bool, optional
    If set to true, the contents of `x` can be overwritten. Default is
    False.

Returns
-------
z : real ndarray
    The returned real array contains::

      [y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2))]              if n is even
      [y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2)),Im(y(n/2))]   if n is odd

    where::

      y(j) = sum[k=0..n-1] x[k] * exp(-sqrt(-1)*j*k*2*pi/n)
      j = 0..n-1

    Note that ``y(-j) == y(n-j).conjugate()``.

See Also
--------
fft, irfft, scipy.fftpack.basic

Notes
-----
Within numerical accuracy, ``y == rfft(irfft(y))``.

Examples
--------
>>> a = [9, -9, 1, 3]
>>> fft(a)
array([  4. +0.j,   8.+12.j,  16. +0.j,   8.-12.j])
>>> rfft(a)
array([  4.,   8.,  12.,  16.])


def irfft(x, n=None, axis=-<NUM_LIT:1>, overwrite_x=False):

tmp = _asfarray(x)<EOL>if not numpy.isrealobj(tmp):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>work_function = _DTYPE_TO_RFFT[tmp.dtype]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % tmp.dtype)<EOL><DEDENT>overwrite_x = overwrite_x or _datacopied(tmp, x)<EOL>return _raw_fft(tmp,n,axis,-<NUM_LIT:1>,overwrite_x,work_function)<EOL>

Return inverse discrete Fourier transform of real sequence x.

The contents of `x` are interpreted as the output of the `rfft`
function.

Parameters
----------
x : array_like
    Transformed data to invert.
n : int, optional
    Length of the inverse Fourier transform.
    If n < x.shape[axis], x is truncated.
    If n > x.shape[axis], x is zero-padded.
    The default results in n = x.shape[axis].
axis : int, optional
    Axis along which the ifft's are computed; the default is over
    the last axis (i.e., axis=-1).
overwrite_x : bool, optional
    If True, the contents of `x` can be destroyed; the default is False.

Returns
-------
irfft : ndarray of floats
    The inverse discrete Fourier transform.

See Also
--------
rfft, ifft

Notes
-----
The returned real array contains::

    [y(0),y(1),...,y(n-1)]

where for n is even::

    y(j) = 1/n (sum[k=1..n/2-1] (x[2*k-1]+sqrt(-1)*x[2*k])
                                 * exp(sqrt(-1)*j*k* 2*pi/n)
                + c.c. + x[0] + (-1)**(j) x[n-1])

and for n is odd::

    y(j) = 1/n (sum[k=1..(n-1)/2] (x[2*k-1]+sqrt(-1)*x[2*k])
                                 * exp(sqrt(-1)*j*k* 2*pi/n)
                + c.c. + x[0])

c.c. denotes complex conjugate of preceding expression.

For details on input parameters, see `rfft`.


def _raw_fftnd(x, s, axes, direction, overwrite_x, work_function):

if s is None:<EOL><INDENT>if axes is None:<EOL><INDENT>s = x.shape<EOL><DEDENT>else:<EOL><INDENT>s = numpy.take(x.shape, axes)<EOL><DEDENT><DEDENT>s = tuple(s)<EOL>if axes is None:<EOL><INDENT>noaxes = True<EOL>axes = list(range(-x.ndim, <NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>noaxes = False<EOL><DEDENT>if len(axes) != len(s):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>for dim in s:<EOL><INDENT>if dim < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % (s,))<EOL><DEDENT><DEDENT>if noaxes:<EOL><INDENT>for i in axes:<EOL><INDENT>x, copy_made = _fix_shape(x, s[i], i)<EOL>overwrite_x = overwrite_x or copy_made<EOL><DEDENT>return work_function(x,s,direction,overwrite_x=overwrite_x)<EOL><DEDENT>id = numpy.argsort(axes)<EOL>axes = [axes[i] for i in id]<EOL>s = [s[i] for i in id]<EOL>for i in range(<NUM_LIT:1>, len(axes)+<NUM_LIT:1>):<EOL><INDENT>x = numpy.swapaxes(x, axes[-i], -i)<EOL><DEDENT>waxes = list(range(x.ndim - len(axes), x.ndim))<EOL>shape = numpy.ones(x.ndim)<EOL>shape[waxes] = s<EOL>for i in range(len(waxes)):<EOL><INDENT>x, copy_made = _fix_shape(x, s[i], waxes[i])<EOL>overwrite_x = overwrite_x or copy_made<EOL><DEDENT>r = work_function(x, shape, direction, overwrite_x=overwrite_x)<EOL>for i in range(len(axes), <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>r = numpy.swapaxes(r, -i, axes[-i])<EOL><DEDENT>return r<EOL>

Internal auxiliary function for fftnd, ifftnd.


def fftn(x, shape=None, axes=None, overwrite_x=False):

return _raw_fftn_dispatch(x, shape, axes, overwrite_x, <NUM_LIT:1>)<EOL>

Return multidimensional discrete Fourier transform.

The returned array contains::

  y[j_1,..,j_d] = sum[k_1=0..n_1-1, ..., k_d=0..n_d-1]
     x[k_1,..,k_d] * prod[i=1..d] exp(-sqrt(-1)*2*pi/n_i * j_i * k_i)

where d = len(x.shape) and n = x.shape.
Note that ``y[..., -j_i, ...] = y[..., n_i-j_i, ...].conjugate()``.

Parameters
----------
x : array_like
    The (n-dimensional) array to transform.
shape : tuple of ints, optional
    The shape of the result.  If both `shape` and `axes` (see below) are
    None, `shape` is ``x.shape``; if `shape` is None but `axes` is
    not None, then `shape` is ``scipy.take(x.shape, axes, axis=0)``.
    If ``shape[i] > x.shape[i]``, the i-th dimension is padded with zeros.
    If ``shape[i] < x.shape[i]``, the i-th dimension is truncated to
    length ``shape[i]``.
axes : array_like of ints, optional
    The axes of `x` (`y` if `shape` is not None) along which the
    transform is applied.
overwrite_x : bool, optional
    If True, the contents of `x` can be destroyed.  Default is False.

Returns
-------
y : complex-valued n-dimensional numpy array
    The (n-dimensional) DFT of the input array.

See Also
--------
ifftn

Examples
--------
>>> y = (-np.arange(16), 8 - np.arange(16), np.arange(16))
>>> np.allclose(y, fftn(ifftn(y)))
True


def ifftn(x, shape=None, axes=None, overwrite_x=False):

return _raw_fftn_dispatch(x, shape, axes, overwrite_x, -<NUM_LIT:1>)<EOL>

Return inverse multi-dimensional discrete Fourier transform of
arbitrary type sequence x.

The returned array contains::

  y[j_1,..,j_d] = 1/p * sum[k_1=0..n_1-1, ..., k_d=0..n_d-1]
     x[k_1,..,k_d] * prod[i=1..d] exp(sqrt(-1)*2*pi/n_i * j_i * k_i)

where ``d = len(x.shape)``, ``n = x.shape``, and ``p = prod[i=1..d] n_i``.

For description of parameters see `fftn`.

See Also
--------
fftn : for detailed information.


def fft2(x, shape=None, axes=(-<NUM_LIT:2>,-<NUM_LIT:1>), overwrite_x=False):

return fftn(x,shape,axes,overwrite_x)<EOL>

2-D discrete Fourier transform.

Return the two-dimensional discrete Fourier transform of the 2-D argument
`x`.

See Also
--------
fftn : for detailed information.


def ifft2(x, shape=None, axes=(-<NUM_LIT:2>,-<NUM_LIT:1>), overwrite_x=False):

return ifftn(x,shape,axes,overwrite_x)<EOL>

2-D discrete inverse Fourier transform of real or complex sequence.

Return inverse two-dimensional discrete Fourier transform of
arbitrary type sequence x.

See `ifft` for more information.

See also
--------
fft2, ifft


if not isinstance(n, int) or n < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>" % n)<EOL><DEDENT>return (arange(<NUM_LIT:1>, n + <NUM_LIT:1>, dtype=int) // <NUM_LIT:2>) / float(n * d)<EOL>

DFT sample frequencies (for usage with rfft, irfft).

    The returned float array contains the frequency bins in
    cycles/unit (with zero at the start) given a window length `n` and a
    sample spacing `d`::

      f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2]/(d*n)   if n is even
      f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2]/(d*n)   if n is odd

    Parameters
    ----------
    n : int
        Window length.
    d : scalar, optional
        Sample spacing. Default is 1.

    Returns
    -------
    out : ndarray
        The array of length `n`, containing the sample frequencies.

    Examples
    --------
    >>> from scipy import fftpack
    >>> sig = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
    >>> sig_fft = fftpack.rfft(sig)
    >>> n = sig_fft.size
    >>> timestep = 0.1
    >>> freq = fftpack.rfftfreq(n, d=timestep)
    >>> freq
    array([ 0.  ,  1.25,  1.25,  2.5 ,  2.5 ,  3.75,  3.75,  5.  ])


tmp = asarray(x)<EOL>if order == <NUM_LIT:0>:<EOL><INDENT>return tmp<EOL><DEDENT>if iscomplexobj(tmp):<EOL><INDENT>return diff(tmp.real,order,period)+<NUM_LIT>*diff(tmp.imag,order,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>c = <NUM_LIT:2>*pi/period<EOL><DEDENT>else:<EOL><INDENT>c = <NUM_LIT:1.0><EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,order,c))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,order=order,c=c):<EOL><INDENT>if k:<EOL><INDENT>return pow(c*k,order)<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=order,<EOL>zero_nyquist=<NUM_LIT:1>)<EOL>_cache[(n,order,c)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=order % <NUM_LIT:2>,<EOL>overwrite_x=overwrite_x)<EOL>

Return k-th derivative (or integral) of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = pow(sqrt(-1)*j*2*pi/period, order) * x_j
  y_0 = 0 if order is not 0.

Parameters
----------
x : array_like
    Input array.
order : int, optional
    The order of differentiation. Default order is 1. If order is
    negative, then integration is carried out under the assumption
    that ``x_0 == 0``.
period : float, optional
    The assumed period of the sequence. Default is ``2*pi``.

Notes
-----
If ``sum(x, axis=0) = 0`` then ``diff(diff(x, k), -k) == x`` (within
numerical accuracy).

For odd order and even ``len(x)``, the Nyquist mode is taken zero.


def tilbert(x, h, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return tilbert(tmp.real, h, period) +<NUM_LIT> * tilbert(tmp.imag, h, period)<EOL><DEDENT>if period is not None:<EOL><INDENT>h = h * <NUM_LIT:2> * pi / period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n, h))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k, h=h):<EOL><INDENT>if k:<EOL><INDENT>return <NUM_LIT:1.0>/tanh(h*k)<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n, kernel, d=<NUM_LIT:1>)<EOL>_cache[(n,h)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>

Return h-Tilbert transform of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

    y_j = sqrt(-1)*coth(j*h*2*pi/period) * x_j
    y_0 = 0

Parameters
----------
x : array_like
    The input array to transform.
h : float
    Defines the parameter of the Tilbert transform.
period : float, optional
    The assumed period of the sequence.  Default period is ``2*pi``.

Returns
-------
tilbert : ndarray
    The result of the transform.

Notes
-----
If ``sum(x, axis=0) == 0`` and ``n = len(x)`` is odd then
``tilbert(itilbert(x)) == x``.

If ``2 * pi * h / period`` is approximately 10 or larger, then
numerically ``tilbert == hilbert``
(theoretically oo-Tilbert == Hilbert).

For even ``len(x)``, the Nyquist mode of ``x`` is taken zero.


tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return itilbert(tmp.real,h,period) +<NUM_LIT>*itilbert(tmp.imag,h,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>h = h*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,h))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,h=h):<EOL><INDENT>if k:<EOL><INDENT>return -tanh(h*k)<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=<NUM_LIT:1>)<EOL>_cache[(n,h)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>

Return inverse h-Tilbert transform of a periodic sequence x.

If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = -sqrt(-1)*tanh(j*h*2*pi/period) * x_j
  y_0 = 0

For more details, see `tilbert`.


tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return hilbert(tmp.real)+<NUM_LIT>*hilbert(tmp.imag)<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get(n)<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k):<EOL><INDENT>if k > <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>elif k < <NUM_LIT:0>:<EOL><INDENT>return -<NUM_LIT:1.0><EOL><DEDENT>return <NUM_LIT:0.0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=<NUM_LIT:1>)<EOL>_cache[n] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>

Return Hilbert transform of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = sqrt(-1)*sign(j) * x_j
  y_0 = 0

Parameters
----------
x : array_like
    The input array, should be periodic.
_cache : dict, optional
    Dictionary that contains the kernel used to do a convolution with.

Returns
-------
y : ndarray
    The transformed input.

Notes
-----
If ``sum(x, axis=0) == 0`` then ``hilbert(ihilbert(x)) == x``.

For even len(x), the Nyquist mode of x is taken zero.

The sign of the returned transform does not have a factor -1 that is more
often than not found in the definition of the Hilbert transform.  Note also
that ``scipy.signal.hilbert`` does have an extra -1 factor compared to this
function.


return -hilbert(x)<EOL>

Return inverse Hilbert transform of a periodic sequence x.

If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = -sqrt(-1)*sign(j) * x_j
  y_0 = 0


def cs_diff(x, a, b, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return cs_diff(tmp.real,a,b,period) +<NUM_LIT>*cs_diff(tmp.imag,a,b,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>a = a*<NUM_LIT:2>*pi/period<EOL>b = b*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,a,b))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,a=a,b=b):<EOL><INDENT>if k:<EOL><INDENT>return -cosh(a*k)/sinh(b*k)<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=<NUM_LIT:1>)<EOL>_cache[(n,a,b)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>

Return (a,b)-cosh/sinh pseudo-derivative of a periodic sequence.

If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = -sqrt(-1)*cosh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
  y_0 = 0

Parameters
----------
x : array_like
    The array to take the pseudo-derivative from.
a, b : float
    Defines the parameters of the cosh/sinh pseudo-differential
    operator.
period : float, optional
    The period of the sequence. Default period is ``2*pi``.

Returns
-------
cs_diff : ndarray
    Pseudo-derivative of periodic sequence `x`.

Notes
-----
For even len(`x`), the Nyquist mode of `x` is taken as zero.


def sc_diff(x, a, b, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return sc_diff(tmp.real,a,b,period) +<NUM_LIT>*sc_diff(tmp.imag,a,b,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>a = a*<NUM_LIT:2>*pi/period<EOL>b = b*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,a,b))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,a=a,b=b):<EOL><INDENT>if k:<EOL><INDENT>return sinh(a*k)/cosh(b*k)<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel,d=<NUM_LIT:1>)<EOL>_cache[(n,a,b)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,swap_real_imag=<NUM_LIT:1>,overwrite_x=overwrite_x)<EOL>

Return (a,b)-sinh/cosh pseudo-derivative of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = sqrt(-1)*sinh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j
  y_0 = 0

Parameters
----------
x : array_like
    Input array.
a,b : float
    Defines the parameters of the sinh/cosh pseudo-differential
    operator.
period : float, optional
    The period of the sequence x. Default is 2*pi.

Notes
-----
``sc_diff(cs_diff(x,a,b),b,a) == x``
For even ``len(x)``, the Nyquist mode of x is taken as zero.


def ss_diff(x, a, b, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return ss_diff(tmp.real,a,b,period) +<NUM_LIT>*ss_diff(tmp.imag,a,b,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>a = a*<NUM_LIT:2>*pi/period<EOL>b = b*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,a,b))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,a=a,b=b):<EOL><INDENT>if k:<EOL><INDENT>return sinh(a*k)/sinh(b*k)<EOL><DEDENT>return float(a)/b<EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel)<EOL>_cache[(n,a,b)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,overwrite_x=overwrite_x)<EOL>

Return (a,b)-sinh/sinh pseudo-derivative of a periodic sequence x.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = sinh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
  y_0 = a/b * x_0

Parameters
----------
x : array_like
    The array to take the pseudo-derivative from.
a,b
    Defines the parameters of the sinh/sinh pseudo-differential
    operator.
period : float, optional
    The period of the sequence x. Default is ``2*pi``.

Notes
-----
``ss_diff(ss_diff(x,a,b),b,a) == x``


def cc_diff(x, a, b, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return cc_diff(tmp.real,a,b,period) +<NUM_LIT>*cc_diff(tmp.imag,a,b,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>a = a*<NUM_LIT:2>*pi/period<EOL>b = b*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,a,b))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel(k,a=a,b=b):<EOL><INDENT>return cosh(a*k)/cosh(b*k)<EOL><DEDENT>omega = convolve.init_convolution_kernel(n,kernel)<EOL>_cache[(n,a,b)] = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve(tmp,omega,overwrite_x=overwrite_x)<EOL>

Return (a,b)-cosh/cosh pseudo-derivative of a periodic sequence.

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

  y_j = cosh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j

Parameters
----------
x : array_like
    The array to take the pseudo-derivative from.
a,b : float
    Defines the parameters of the sinh/sinh pseudo-differential
    operator.
period : float, optional
    The period of the sequence x. Default is ``2*pi``.

Returns
-------
cc_diff : ndarray
    Pseudo-derivative of periodic sequence `x`.

Notes
-----
``cc_diff(cc_diff(x,a,b),b,a) == x``


def shift(x, a, period=None, _cache=_cache):

tmp = asarray(x)<EOL>if iscomplexobj(tmp):<EOL><INDENT>return shift(tmp.real,a,period)+<NUM_LIT>*shift(tmp.imag,a,period)<EOL><DEDENT>if period is not None:<EOL><INDENT>a = a*<NUM_LIT:2>*pi/period<EOL><DEDENT>n = len(x)<EOL>omega = _cache.get((n,a))<EOL>if omega is None:<EOL><INDENT>if len(_cache) > <NUM_LIT:20>:<EOL><INDENT>while _cache:<EOL><INDENT>_cache.popitem()<EOL><DEDENT><DEDENT>def kernel_real(k,a=a):<EOL><INDENT>return cos(a*k)<EOL><DEDENT>def kernel_imag(k,a=a):<EOL><INDENT>return sin(a*k)<EOL><DEDENT>omega_real = convolve.init_convolution_kernel(n,kernel_real,d=<NUM_LIT:0>,<EOL>zero_nyquist=<NUM_LIT:0>)<EOL>omega_imag = convolve.init_convolution_kernel(n,kernel_imag,d=<NUM_LIT:1>,<EOL>zero_nyquist=<NUM_LIT:0>)<EOL>_cache[(n,a)] = omega_real,omega_imag<EOL><DEDENT>else:<EOL><INDENT>omega_real,omega_imag = omega<EOL><DEDENT>overwrite_x = _datacopied(tmp, x)<EOL>return convolve.convolve_z(tmp,omega_real,omega_imag,<EOL>overwrite_x=overwrite_x)<EOL>

Shift periodic sequence x by a: y(u) = x(u+a).

If x_j and y_j are Fourier coefficients of periodic functions x
and y, respectively, then::

      y_j = exp(j*a*2*pi/period*sqrt(-1)) * x_f

Parameters
----------
x : array_like
    The array to take the pseudo-derivative from.
a : float
    Defines the parameters of the sinh/sinh pseudo-differential
period : float, optional
    The period of the sequences x and y. Default period is ``2*pi``.


if obj is None:<EOL><INDENT>return obj<EOL><DEDENT>else:<EOL><INDENT>if dtype is None:<EOL><INDENT>obj = numpy.asarray(obj)<EOL><DEDENT>else:<EOL><INDENT>obj = numpy.asarray(obj, dtype)<EOL><DEDENT>if obj.shape == ():<EOL><INDENT>return obj.dtype.type(obj)<EOL><DEDENT>else:<EOL><INDENT>return obj<EOL><DEDENT><DEDENT>

Convert an object to the preferred form for input to the odr routine.


stopreason = ('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>')[info % <NUM_LIT:5>]<EOL>if info >= <NUM_LIT:5>:<EOL><INDENT>I = (info//<NUM_LIT> % <NUM_LIT:10>,<EOL>info//<NUM_LIT:1000> % <NUM_LIT:10>,<EOL>info//<NUM_LIT:100> % <NUM_LIT:10>,<EOL>info//<NUM_LIT:10> % <NUM_LIT:10>,<EOL>info % <NUM_LIT:10>)<EOL>problems = []<EOL>if I[<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>if I[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:2>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:3>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>problems.append(stopreason)<EOL><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:1>:<EOL><INDENT>if I[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:2>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:3>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:4>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>if I[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:2>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:3>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:4>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:3>:<EOL><INDENT>if I[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:2>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:3>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>if I[<NUM_LIT:4>] != <NUM_LIT:0>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:4>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:5>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>elif I[<NUM_LIT:0>] == <NUM_LIT:6>:<EOL><INDENT>problems.append('<STR_LIT>')<EOL><DEDENT>return problems<EOL><DEDENT>else:<EOL><INDENT>return [stopreason]<EOL><DEDENT>

Interprets the return code of the odr routine.

    Parameters
    ----------
    info : int
        The return code of the odr routine.

    Returns
    -------
    problems : list(str)
        A list of messages about why the odr() routine stopped.


self.meta.update(kwds)<EOL>

Update the metadata dictionary with the keywords and data provided
        by keywords.

        Examples
        --------
        >>> data.set_meta(lab="Ph 7; Lab 26", title="Ag110 + Ag108 Decay")


if attr in self.meta:<EOL><INDENT>return self.meta[attr]<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError("<STR_LIT>" % attr)<EOL><DEDENT>

Dispatch attribute access to the metadata dictionary.


return <NUM_LIT:1.>/numpy.power(sd, <NUM_LIT:2>)<EOL>


from numpy.dual import inv<EOL>if len(cov.shape) == <NUM_LIT:2>:<EOL><INDENT>return inv(cov)<EOL><DEDENT>else:<EOL><INDENT>weights = numpy.zeros(cov.shape, float)<EOL>for i in range(cov.shape[-<NUM_LIT:1>]):  <EOL><INDENT>weights[:,:,i] = inv(cov[:,:,i])<EOL><DEDENT>return weights<EOL><DEDENT>

Convert covariance matrix(-ices) to weights.


self.meta.update(kwds)<EOL>

Update the metadata dictionary with the keywords and data provided
        here.

        Examples
        --------
        set_meta(name="Exponential", equation="y = a exp(b x) + c")


Dispatch attribute access to the metadata.


print('<STR_LIT>', self.beta)<EOL>print('<STR_LIT>', self.sd_beta)<EOL>print('<STR_LIT>', self.cov_beta)<EOL>if hasattr(self, '<STR_LIT:info>'):<EOL><INDENT>print('<STR_LIT>',self.res_var)<EOL>print('<STR_LIT>', self.inv_condnum)<EOL>print('<STR_LIT>')<EOL>for r in self.stopreason:<EOL><INDENT>print('<STR_LIT>' % r)<EOL><DEDENT><DEDENT>


x_s = list(self.data.x.shape)<EOL>if isinstance(self.data.y, numpy.ndarray):<EOL><INDENT>y_s = list(self.data.y.shape)<EOL>if self.model.implicit:<EOL><INDENT>raise odr_error("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>y_s = [self.data.y, x_s[-<NUM_LIT:1>]]<EOL>if not self.model.implicit:<EOL><INDENT>raise odr_error("<STR_LIT>")<EOL><DEDENT>self.set_job(fit_type=<NUM_LIT:1>)<EOL><DEDENT>if x_s[-<NUM_LIT:1>] != y_s[-<NUM_LIT:1>]:<EOL><INDENT>raise odr_error("<STR_LIT>")<EOL><DEDENT>n = x_s[-<NUM_LIT:1>]<EOL>if len(x_s) == <NUM_LIT:2>:<EOL><INDENT>m = x_s[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>m = <NUM_LIT:1><EOL><DEDENT>if len(y_s) == <NUM_LIT:2>:<EOL><INDENT>q = y_s[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>q = <NUM_LIT:1><EOL><DEDENT>p = len(self.beta0)<EOL>fcn_perms = [(q, n)]<EOL>fjacd_perms = [(q, m, n)]<EOL>fjacb_perms = [(q, p, n)]<EOL>if q == <NUM_LIT:1>:<EOL><INDENT>fcn_perms.append((n,))<EOL>fjacd_perms.append((m, n))<EOL>fjacb_perms.append((p, n))<EOL><DEDENT>if m == <NUM_LIT:1>:<EOL><INDENT>fjacd_perms.append((q, n))<EOL><DEDENT>if p == <NUM_LIT:1>:<EOL><INDENT>fjacb_perms.append((q, n))<EOL><DEDENT>if m == q == <NUM_LIT:1>:<EOL><INDENT>fjacd_perms.append((n,))<EOL><DEDENT>if p == q == <NUM_LIT:1>:<EOL><INDENT>fjacb_perms.append((n,))<EOL><DEDENT>arglist = (self.beta0, self.data.x)<EOL>if self.model.extra_args is not None:<EOL><INDENT>arglist = arglist + self.model.extra_args<EOL><DEDENT>res = self.model.fcn(*arglist)<EOL>if res.shape not in fcn_perms:<EOL><INDENT>print(res.shape)<EOL>print(fcn_perms)<EOL>raise odr_error("<STR_LIT>" % y_s)<EOL><DEDENT>if self.model.fjacd is not None:<EOL><INDENT>res = self.model.fjacd(*arglist)<EOL>if res.shape not in fjacd_perms:<EOL><INDENT>raise odr_error(<EOL>"<STR_LIT>" % (q, m, n))<EOL><DEDENT><DEDENT>if self.model.fjacb is not None:<EOL><INDENT>res = self.model.fjacb(*arglist)<EOL>if res.shape not in fjacb_perms:<EOL><INDENT>raise odr_error(<EOL>"<STR_LIT>" % (q, p, n))<EOL><DEDENT><DEDENT>if self.delta0 is not None and self.delta0.shape != self.data.x.shape:<EOL><INDENT>raise odr_error(<EOL>"<STR_LIT>" % self.data.x.shape)<EOL><DEDENT>

Check the inputs for consistency, but don't bother checking things
        that the builtin function odr will check.


n = self.data.x.shape[-<NUM_LIT:1>]<EOL>p = self.beta0.shape[<NUM_LIT:0>]<EOL>if len(self.data.x.shape) == <NUM_LIT:2>:<EOL><INDENT>m = self.data.x.shape[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>m = <NUM_LIT:1><EOL><DEDENT>if self.model.implicit:<EOL><INDENT>q = self.data.y<EOL><DEDENT>elif len(self.data.y.shape) == <NUM_LIT:2>:<EOL><INDENT>q = self.data.y.shape[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>q = <NUM_LIT:1><EOL><DEDENT>if self.data.we is None:<EOL><INDENT>ldwe = ld2we = <NUM_LIT:1><EOL><DEDENT>elif len(self.data.we.shape) == <NUM_LIT:3>:<EOL><INDENT>ld2we, ldwe = self.data.we.shape[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>ldwe = <NUM_LIT:1><EOL>ld2we = self.data.we.shape[<NUM_LIT:1>]<EOL><DEDENT>if self.job % <NUM_LIT:10> < <NUM_LIT:2>:<EOL><INDENT>lwork = (<NUM_LIT> + <NUM_LIT:11>*p + p*p + m + m*m + <NUM_LIT:4>*n*q + <NUM_LIT:6>*n*m + <NUM_LIT:2>*n*q*p +<EOL><NUM_LIT:2>*n*q*m + q*q + <NUM_LIT:5>*q + q*(p+m) + ldwe*ld2we*q)<EOL><DEDENT>else:<EOL><INDENT>lwork = (<NUM_LIT> + <NUM_LIT:11>*p + p*p + m + m*m + <NUM_LIT:4>*n*q + <NUM_LIT:2>*n*m + <NUM_LIT:2>*n*q*p +<EOL><NUM_LIT:5>*q + q*(p+m) + ldwe*ld2we*q)<EOL><DEDENT>if isinstance(self.work, numpy.ndarray) and self.work.shape == (lwork,)and self.work.dtype.str.endswith('<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>self.work = numpy.zeros((lwork,), float)<EOL><DEDENT>

Generate a suitable work array if one does not already exist.


def set_job(self, fit_type=None, deriv=None, var_calc=None,<EOL>del_init=None, restart=None):

if self.job is None:<EOL><INDENT>job_l = [<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>job_l = [self.job // <NUM_LIT> % <NUM_LIT:10>,<EOL>self.job // <NUM_LIT:1000> % <NUM_LIT:10>,<EOL>self.job // <NUM_LIT:100> % <NUM_LIT:10>,<EOL>self.job // <NUM_LIT:10> % <NUM_LIT:10>,<EOL>self.job % <NUM_LIT:10>]<EOL><DEDENT>if fit_type in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>job_l[<NUM_LIT:4>] = fit_type<EOL><DEDENT>if deriv in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>):<EOL><INDENT>job_l[<NUM_LIT:3>] = deriv<EOL><DEDENT>if var_calc in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>job_l[<NUM_LIT:2>] = var_calc<EOL><DEDENT>if del_init in (<NUM_LIT:0>, <NUM_LIT:1>):<EOL><INDENT>job_l[<NUM_LIT:1>] = del_init<EOL><DEDENT>if restart in (<NUM_LIT:0>, <NUM_LIT:1>):<EOL><INDENT>job_l[<NUM_LIT:0>] = restart<EOL><DEDENT>self.job = (job_l[<NUM_LIT:0>]*<NUM_LIT> + job_l[<NUM_LIT:1>]*<NUM_LIT:1000> +<EOL>job_l[<NUM_LIT:2>]*<NUM_LIT:100> + job_l[<NUM_LIT:3>]*<NUM_LIT:10> + job_l[<NUM_LIT:4>])<EOL>

Sets the "job" parameter is a hopefully comprehensible way.

If an argument is not specified, then the value is left as is. The
default value from class initialization is for all of these options set
to 0.

Parameters
----------
fit_type : {0, 1, 2} int
    0 -> explicit ODR

    1 -> implicit ODR

    2 -> ordinary least-squares
deriv : {0, 1, 2, 3} int
    0 -> forward finite differences

    1 -> central finite differences

    2 -> user-supplied derivatives (Jacobians) with results
      checked by ODRPACK

    3 -> user-supplied derivatives, no checking
var_calc : {0, 1, 2} int
    0 -> calculate asymptotic covariance matrix and fit
         parameter uncertainties (V_B, s_B) using derivatives
         recomputed at the final solution

    1 -> calculate V_B and s_B using derivatives from last iteration

    2 -> do not calculate V_B and s_B
del_init : {0, 1} int
    0 -> initial input variable offsets set to 0

    1 -> initial offsets provided by user in variable "work"
restart : {0, 1} int
    0 -> fit is not a restart

    1 -> fit is a restart

Notes
-----
The permissible values are different from those given on pg. 31 of the
ODRPACK User's Guide only in that one cannot specify numbers greater than
the last value for each variable.

If one does not supply functions to compute the Jacobians, the fitting
procedure will change deriv to 0, finite differences, as a default. To
initialize the input variable offsets by yourself, set del_init to 1 and
put the offsets into the "work" variable correctly.


def set_iprint(self, init=None, so_init=None,<EOL>iter=None, so_iter=None, iter_step=None, final=None, so_final=None):

if self.iprint is None:<EOL><INDENT>self.iprint = <NUM_LIT:0><EOL><DEDENT>ip = [self.iprint // <NUM_LIT:1000> % <NUM_LIT:10>,<EOL>self.iprint // <NUM_LIT:100> % <NUM_LIT:10>,<EOL>self.iprint // <NUM_LIT:10> % <NUM_LIT:10>,<EOL>self.iprint % <NUM_LIT:10>]<EOL>ip2arg = [[<NUM_LIT:0>, <NUM_LIT:0>],  <EOL>[<NUM_LIT:1>, <NUM_LIT:0>],  <EOL>[<NUM_LIT:2>, <NUM_LIT:0>],  <EOL>[<NUM_LIT:1>, <NUM_LIT:1>],  <EOL>[<NUM_LIT:2>, <NUM_LIT:1>],  <EOL>[<NUM_LIT:1>, <NUM_LIT:2>],  <EOL>[<NUM_LIT:2>, <NUM_LIT:2>]]  <EOL>if (self.rptfile is None and<EOL>(so_init is not None or<EOL>so_iter is not None or<EOL>so_final is not None)):<EOL><INDENT>raise odr_error(<EOL>"<STR_LIT>")<EOL><DEDENT>iprint_l = ip2arg[ip[<NUM_LIT:0>]] + ip2arg[ip[<NUM_LIT:1>]] + ip2arg[ip[<NUM_LIT:3>]]<EOL>if init is not None:<EOL><INDENT>iprint_l[<NUM_LIT:0>] = init<EOL><DEDENT>if so_init is not None:<EOL><INDENT>iprint_l[<NUM_LIT:1>] = so_init<EOL><DEDENT>if iter is not None:<EOL><INDENT>iprint_l[<NUM_LIT:2>] = iter<EOL><DEDENT>if so_iter is not None:<EOL><INDENT>iprint_l[<NUM_LIT:3>] = so_iter<EOL><DEDENT>if final is not None:<EOL><INDENT>iprint_l[<NUM_LIT:4>] = final<EOL><DEDENT>if so_final is not None:<EOL><INDENT>iprint_l[<NUM_LIT:5>] = so_final<EOL><DEDENT>if iter_step in range(<NUM_LIT:10>):<EOL><INDENT>ip[<NUM_LIT:2>] = iter_step<EOL><DEDENT>ip[<NUM_LIT:0>] = ip2arg.index(iprint_l[<NUM_LIT:0>:<NUM_LIT:2>])<EOL>ip[<NUM_LIT:1>] = ip2arg.index(iprint_l[<NUM_LIT:2>:<NUM_LIT:4>])<EOL>ip[<NUM_LIT:3>] = ip2arg.index(iprint_l[<NUM_LIT:4>:<NUM_LIT:6>])<EOL>self.iprint = ip[<NUM_LIT:0>]*<NUM_LIT:1000> + ip[<NUM_LIT:1>]*<NUM_LIT:100> + ip[<NUM_LIT:2>]*<NUM_LIT:10> + ip[<NUM_LIT:3>]<EOL>

Set the iprint parameter for the printing of computation reports.

        If any of the arguments are specified here, then they are set in the
        iprint member. If iprint is not set manually or with this method, then
        ODRPACK defaults to no printing. If no filename is specified with the
        member rptfile, then ODRPACK prints to stdout. One can tell ODRPACK to
        print to stdout in addition to the specified filename by setting the
        so_* arguments to this function, but one cannot specify to print to
        stdout but not a file since one can do that by not specifying a rptfile
        filename.

        There are three reports: initialization, iteration, and final reports.
        They are represented by the arguments init, iter, and final
        respectively.  The permissible values are 0, 1, and 2 representing "no
        report", "short report", and "long report" respectively.

        The argument iter_step (0 <= iter_step <= 9) specifies how often to make
        the iteration report; the report will be made for every iter_step'th
        iteration starting with iteration one. If iter_step == 0, then no
        iteration report is made, regardless of the other arguments.

        If the rptfile is None, then any so_* arguments supplied will raise an
        exception.


args = (self.model.fcn, self.beta0, self.data.y, self.data.x)<EOL>kwds = {'<STR_LIT>': <NUM_LIT:1>}<EOL>kwd_l = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if self.delta0 is not None and self.job % <NUM_LIT:1000> // <NUM_LIT:10> == <NUM_LIT:1>:<EOL><INDENT>self._gen_work()<EOL>d0 = numpy.ravel(self.delta0)<EOL>self.work[:len(d0)] = d0<EOL><DEDENT>if self.model.fjacb is not None:<EOL><INDENT>kwds['<STR_LIT>'] = self.model.fjacb<EOL><DEDENT>if self.model.fjacd is not None:<EOL><INDENT>kwds['<STR_LIT>'] = self.model.fjacd<EOL><DEDENT>if self.data.we is not None:<EOL><INDENT>kwds['<STR_LIT>'] = self.data.we<EOL><DEDENT>if self.data.wd is not None:<EOL><INDENT>kwds['<STR_LIT>'] = self.data.wd<EOL><DEDENT>if self.model.extra_args is not None:<EOL><INDENT>kwds['<STR_LIT>'] = self.model.extra_args<EOL><DEDENT>for attr in kwd_l:<EOL><INDENT>obj = getattr(self, attr)<EOL>if obj is not None:<EOL><INDENT>kwds[attr] = obj<EOL><DEDENT><DEDENT>self.output = Output(odr(*args, **kwds))<EOL>return self.output<EOL>

Run the fitting routine with all of the information given.

        Returns
        -------
        output : Output instance
            This object is also assigned to the attribute .output .


if self.output is None:<EOL><INDENT>raise odr_error("<STR_LIT>")<EOL><DEDENT>self.set_job(restart=<NUM_LIT:1>)<EOL>self.work = self.output.work<EOL>self.iwork = self.output.iwork<EOL>self.maxit = iter<EOL>return self.run()<EOL>

Restarts the run with iter more iterations.

        Parameters
        ----------
        iter : int, optional
            ODRPACK's default for the number of new iterations is 10.

        Returns
        -------
        output : Output instance
            This object is also assigned to the attribute .output .


powers = np.asarray(order)<EOL>if powers.shape == ():<EOL><INDENT>powers = np.arange(<NUM_LIT:1>, powers + <NUM_LIT:1>)<EOL><DEDENT>powers.shape = (len(powers), <NUM_LIT:1>)<EOL>len_beta = len(powers) + <NUM_LIT:1><EOL>def _poly_est(data, len_beta=len_beta):<EOL><INDENT>return np.ones((len_beta,), float)<EOL><DEDENT>return Model(_poly_fcn, fjacd=_poly_fjacd, fjacb=_poly_fjacb,<EOL>estimate=_poly_est, extra_args=(powers,),<EOL>meta={'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>':'<STR_LIT>' % (len_beta-<NUM_LIT:1>),<EOL>'<STR_LIT>':'<STR_LIT>' %<EOL>(len_beta-<NUM_LIT:1>)})<EOL>

Factory function for a general polynomial model.

Parameters
----------
order : int or sequence
    If an integer, it becomes the order of the polynomial to fit. If
    a sequence of numbers, then these are the explicit powers in the
    polynomial.
    A constant term (power 0) is always included, so don't include 0.
    Thus, polynomial(n) is equivalent to polynomial(range(1, n+1)).

Returns
-------
polynomial : Model instance
    Model instance.