def hermfit(x, y, deg, rcond=None, full=False, w=None):

order = int(deg) + <NUM_LIT:1><EOL>x = np.asarray(x) + <NUM_LIT:0.0><EOL>y = np.asarray(y) + <NUM_LIT:0.0><EOL>if deg < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if x.ndim != <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if x.size == <NUM_LIT:0>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if y.ndim < <NUM_LIT:1> or y.ndim > <NUM_LIT:2>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(x) != len(y):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>lhs = hermvander(x, deg).T<EOL>rhs = y.T<EOL>if w is not None:<EOL><INDENT>w = np.asarray(w) + <NUM_LIT:0.0><EOL>if w.ndim != <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(x) != len(w):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>lhs = lhs * w<EOL>rhs = rhs * w<EOL><DEDENT>if rcond is None:<EOL><INDENT>rcond = len(x)*np.finfo(x.dtype).eps<EOL><DEDENT>if issubclass(lhs.dtype.type, np.complexfloating):<EOL><INDENT>scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>scl = np.sqrt(np.square(lhs).sum(<NUM_LIT:1>))<EOL><DEDENT>scl[scl == <NUM_LIT:0>] = <NUM_LIT:1><EOL>c, resids, rank, s = la.lstsq(lhs.T/scl, rhs.T, rcond)<EOL>c = (c.T/scl).T<EOL>if rank != order and not full:<EOL><INDENT>msg = "<STR_LIT>"<EOL>warnings.warn(msg, pu.RankWarning)<EOL><DEDENT>if full:<EOL><INDENT>return c, [resids, rank, s, rcond]<EOL><DEDENT>else:<EOL><INDENT>return c<EOL><DEDENT>

Least squares fit of Hermite series to data.

Return the coefficients of a Hermite series of degree `deg` that is the
least squares fit to the data values `y` given at points `x`. If `y` is
1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
fits are done, one for each column of `y`, and the resulting
coefficients are stored in the corresponding columns of a 2-D return.
The fitted polynomial(s) are in the form

.. math::  p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x),

where `n` is `deg`.

Parameters
----------
x : array_like, shape (M,)
    x-coordinates of the M sample points ``(x[i], y[i])``.
y : array_like, shape (M,) or (M, K)
    y-coordinates of the sample points. Several data sets of sample
    points sharing the same x-coordinates can be fitted at once by
    passing in a 2D-array that contains one dataset per column.
deg : int
    Degree of the fitting polynomial
rcond : float, optional
    Relative condition number of the fit. Singular values smaller than
    this relative to the largest singular value will be ignored. The
    default value is len(x)*eps, where eps is the relative precision of
    the float type, about 2e-16 in most cases.
full : bool, optional
    Switch determining nature of return value. When it is False (the
    default) just the coefficients are returned, when True diagnostic
    information from the singular value decomposition is also returned.
w : array_like, shape (`M`,), optional
    Weights. If not None, the contribution of each point
    ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the
    weights are chosen so that the errors of the products ``w[i]*y[i]``
    all have the same variance.  The default value is None.

Returns
-------
coef : ndarray, shape (M,) or (M, K)
    Hermite coefficients ordered from low to high. If `y` was 2-D,
    the coefficients for the data in column k  of `y` are in column
    `k`.

[residuals, rank, singular_values, rcond] : list
    These values are only returned if `full` = True

    resid -- sum of squared residuals of the least squares fit
    rank -- the numerical rank of the scaled Vandermonde matrix
    sv -- singular values of the scaled Vandermonde matrix
    rcond -- value of `rcond`.

    For more details, see `linalg.lstsq`.

Warns
-----
RankWarning
    The rank of the coefficient matrix in the least-squares fit is
    deficient. The warning is only raised if `full` = False.  The
    warnings can be turned off by

    >>> import warnings
    >>> warnings.simplefilter('ignore', RankWarning)

See Also
--------
chebfit, legfit, lagfit, polyfit, hermefit
hermval : Evaluates a Hermite series.
hermvander : Vandermonde matrix of Hermite series.
hermweight : Hermite weight function
linalg.lstsq : Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline : Computes spline fits.

Notes
-----
The solution is the coefficients of the Hermite series `p` that
minimizes the sum of the weighted squared errors

.. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,

where the :math:`w_j` are the weights. This problem is solved by
setting up the (typically) overdetermined matrix equation

.. math:: V(x) * c = w * y,

where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
coefficients to be solved for, `w` are the weights, `y` are the
observed values.  This equation is then solved using the singular value
decomposition of `V`.

If some of the singular values of `V` are so small that they are
neglected, then a `RankWarning` will be issued. This means that the
coefficient values may be poorly determined. Using a lower order fit
will usually get rid of the warning.  The `rcond` parameter can also be
set to a value smaller than its default, but the resulting fit may be
spurious and have large contributions from roundoff error.

Fits using Hermite series are probably most useful when the data can be
approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the Hermite
weight. In that case the weight ``sqrt(w(x[i])`` should be used
together with data values ``y[i]/sqrt(w(x[i])``. The weight function is
available as `hermweight`.

References
----------
.. [1] Wikipedia, "Curve fitting",
       http://en.wikipedia.org/wiki/Curve_fitting

Examples
--------
>>> from numpy.polynomial.hermite import hermfit, hermval
>>> x = np.linspace(-10, 10)
>>> err = np.random.randn(len(x))/10
>>> y = hermval(x, [1, 2, 3]) + err
>>> hermfit(x, y, 2)
array([ 0.97902637,  1.99849131,  3.00006   ])


<EOL>[c] = pu.as_series([c])<EOL>if len(c) < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if len(c) == <NUM_LIT:2>:<EOL><INDENT>return np.array([[-<NUM_LIT>*c[<NUM_LIT:0>]/c[<NUM_LIT:1>]]])<EOL><DEDENT>n = len(c) - <NUM_LIT:1><EOL>mat = np.zeros((n, n), dtype=c.dtype)<EOL>scl = np.hstack((<NUM_LIT:1.>, np.sqrt(<NUM_LIT>*np.arange(<NUM_LIT:1>, n))))<EOL>scl = np.multiply.accumulate(scl)<EOL>top = mat.reshape(-<NUM_LIT:1>)[<NUM_LIT:1>::n+<NUM_LIT:1>]<EOL>bot = mat.reshape(-<NUM_LIT:1>)[n::n+<NUM_LIT:1>]<EOL>top[...] = np.sqrt(<NUM_LIT>*np.arange(<NUM_LIT:1>, n))<EOL>bot[...] = top<EOL>mat[:, -<NUM_LIT:1>] -= (c[:-<NUM_LIT:1>]/c[-<NUM_LIT:1>])*(scl/scl[-<NUM_LIT:1>])*<NUM_LIT><EOL>return mat<EOL>

Return the scaled companion matrix of c.

    The basis polynomials are scaled so that the companion matrix is
    symmetric when `c` is an Hermite basis polynomial. This provides
    better eigenvalue estimates than the unscaled case and for basis
    polynomials the eigenvalues are guaranteed to be real if
    `numpy.linalg.eigvalsh` is used to obtain them.

    Parameters
    ----------
    c : array_like
        1-D array of Hermite series coefficients ordered from low to high
        degree.

    Returns
    -------
    mat : ndarray
        Scaled companion matrix of dimensions (deg, deg).

    Notes
    -----

    .. versionadded::1.7.0


<EOL>[c] = pu.as_series([c])<EOL>if len(c) <= <NUM_LIT:1>:<EOL><INDENT>return np.array([], dtype=c.dtype)<EOL><DEDENT>if len(c) == <NUM_LIT:2>:<EOL><INDENT>return np.array([-<NUM_LIT>*c[<NUM_LIT:0>]/c[<NUM_LIT:1>]])<EOL><DEDENT>m = hermcompanion(c)<EOL>r = la.eigvals(m)<EOL>r.sort()<EOL>return r<EOL>

Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
    1-D array of coefficients.

Returns
-------
out : ndarray
    Array of the roots of the series. If all the roots are real,
    then `out` is also real, otherwise it is complex.

See Also
--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of `x` so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([ 0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([ -1.00000000e+00,  -1.38777878e-17,   1.00000000e+00])


ideg = int(deg)<EOL>if ideg != deg or ideg < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>c = np.array([<NUM_LIT:0>]*deg + [<NUM_LIT:1>])<EOL>m = hermcompanion(c)<EOL>x = la.eigvals(m)<EOL>x.sort()<EOL>dy = hermval(x, c)<EOL>df = hermval(x, hermder(c))<EOL>x -= dy/df<EOL>fm = hermval(x, c[<NUM_LIT:1>:])<EOL>fm /= np.abs(fm).max()<EOL>df /= np.abs(df).max()<EOL>w = <NUM_LIT:1>/(fm * df)<EOL>w = (w + w[::-<NUM_LIT:1>])/<NUM_LIT:2><EOL>x = (x - x[::-<NUM_LIT:1>])/<NUM_LIT:2><EOL>w *= np.sqrt(np.pi) / w.sum()<EOL>return x, w<EOL>

Gauss-Hermite quadrature.

Computes the sample points and weights for Gauss-Hermite quadrature.
These sample points and weights will correctly integrate polynomials of
degree :math:`2*deg - 1` or less over the interval :math:`[-\inf, \inf]`
with the weight function :math:`f(x) = \exp(-x^2)`.

Parameters
----------
deg : int
    Number of sample points and weights. It must be >= 1.

Returns
-------
x : ndarray
    1-D ndarray containing the sample points.
y : ndarray
    1-D ndarray containing the weights.

Notes
-----

.. versionadded::1.7.0

The results have only been tested up to degree 100, higher degrees may
be problematic. The weights are determined by using the fact that

.. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k))

where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
is the k'th root of :math:`H_n`, and then scaling the results to get
the right value when integrating 1.


w = np.exp(-x**<NUM_LIT:2>)<EOL>return w<EOL>

Weight function of the Hermite polynomials.

The weight function is :math:`\exp(-x^2)` and the interval of
integration is :math:`[-\inf, \inf]`. the Hermite polynomials are
orthogonal, but not normalized, with respect to this weight function.

Parameters
----------
x : array_like
   Values at which the weight function will be computed.

Returns
-------
w : ndarray
   The weight function at `x`.

Notes
-----

.. versionadded::1.7.0


if len(self.coef) != len(other.coef):<EOL><INDENT>return False<EOL><DEDENT>elif not np.all(self.coef == other.coef):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>

Check if coefficients match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``coef`` attribute.

        Returns
        -------
        bool : boolean
            True if the coefficients are the same, False otherwise.


return np.all(self.domain == other.domain)<EOL>

Check if domains match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``domain`` attribute.

        Returns
        -------
        bool : boolean
            True if the domains are the same, False otherwise.


return np.all(self.window == other.window)<EOL>

Check if windows match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``window`` attribute.

        Returns
        -------
        bool : boolean
            True if the windows are the same, False otherwise.


return isinstance(other, self.__class__)<EOL>

Check if types match.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        other : object
            Class instance.

        Returns
        -------
        bool : boolean
            True if other is same class as self


if isinstance(other, ABCPolyBase):<EOL><INDENT>if not isinstance(other, self.__class__):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>elif not np.all(self.domain == other.domain):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>elif not np.all(self.window == other.window):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>return other.coef<EOL><DEDENT>return other<EOL>

Interpret other as polynomial coefficients.

        The `other` argument is checked to see if it is of the same
        class as self with identical domain and window. If so,
        return its coefficients, otherwise return `other`.

        .. versionadded:: 1.9.0

        Parameters
        ----------
        other : anything
            Object to be checked.

        Returns
        -------
        coef:
            The coefficients of`other` if it is a compatible instance,
            of ABCPolyBase, otherwise `other`.

        Raises
        ------
        TypeError:
            When `other` is an incompatible instance of ABCPolyBase.


return self.__class__(self.coef, self.domain, self.window)<EOL>

Return a copy.

        Returns
        -------
        new_series : series
            Copy of self.


return len(self) - <NUM_LIT:1><EOL>

The degree of the series.

        .. versionadded:: 1.5.0

        Returns
        -------
        degree : int
            Degree of the series, one less than the number of coefficients.


return self.truncate(deg + <NUM_LIT:1>)<EOL>

Truncate series to the given degree.

        Reduce the degree of the series to `deg` by discarding the
        high order terms. If `deg` is greater than the current degree a
        copy of the current series is returned. This can be useful in least
        squares where the coefficients of the high degree terms may be very
        small.

        .. versionadded:: 1.5.0

        Parameters
        ----------
        deg : non-negative int
            The series is reduced to degree `deg` by discarding the high
            order terms. The value of `deg` must be a non-negative integer.

        Returns
        -------
        new_series : series
            New instance of series with reduced degree.


coef = pu.trimcoef(self.coef, tol)<EOL>return self.__class__(coef, self.domain, self.window)<EOL>

Remove trailing coefficients

        Remove trailing coefficients until a coefficient is reached whose
        absolute value greater than `tol` or the beginning of the series is
        reached. If all the coefficients would be removed the series is set
        to ``[0]``. A new series instance is returned with the new
        coefficients.  The current instance remains unchanged.

        Parameters
        ----------
        tol : non-negative number.
            All trailing coefficients less than `tol` will be removed.

        Returns
        -------
        new_series : series
            Contains the new set of coefficients.


isize = int(size)<EOL>if isize != size or isize < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if isize >= len(self.coef):<EOL><INDENT>coef = self.coef<EOL><DEDENT>else:<EOL><INDENT>coef = self.coef[:isize]<EOL><DEDENT>return self.__class__(coef, self.domain, self.window)<EOL>

Truncate series to length `size`.

        Reduce the series to length `size` by discarding the high
        degree terms. The value of `size` must be a positive integer. This
        can be useful in least squares where the coefficients of the
        high degree terms may be very small.

        Parameters
        ----------
        size : positive int
            The series is reduced to length `size` by discarding the high
            degree terms. The value of `size` must be a positive integer.

        Returns
        -------
        new_series : series
            New instance of series with truncated coefficients.


def convert(self, domain=None, kind=None, window=None):

if kind is None:<EOL><INDENT>kind = self.__class__<EOL><DEDENT>if domain is None:<EOL><INDENT>domain = kind.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = kind.window<EOL><DEDENT>return self(kind.identity(domain, window=window))<EOL>

Convert series to a different kind and/or domain and/or window.

        Parameters
        ----------
        domain : array_like, optional
            The domain of the converted series. If the value is None,
            the default domain of `kind` is used.
        kind : class, optional
            The polynomial series type class to which the current instance
            should be converted. If kind is None, then the class of the
            current instance is used.
        window : array_like, optional
            The window of the converted series. If the value is None,
            the default window of `kind` is used.

        Returns
        -------
        new_series : series
            The returned class can be of different type than the current
            instance and/or have a different domain and/or different
            window.

        Notes
        -----
        Conversion between domains and class types can result in
        numerically ill defined series.

        Examples
        --------


return pu.mapparms(self.domain, self.window)<EOL>

Return the mapping parameters.

        The returned values define a linear map ``off + scl*x`` that is
        applied to the input arguments before the series is evaluated. The
        map depends on the ``domain`` and ``window``; if the current
        ``domain`` is equal to the ``window`` the resulting map is the
        identity.  If the coefficients of the series instance are to be
        used by themselves outside this class, then the linear function
        must be substituted for the ``x`` in the standard representation of
        the base polynomials.

        Returns
        -------
        off, scl : float or complex
            The mapping function is defined by ``off + scl*x``.

        Notes
        -----
        If the current domain is the interval ``[l1, r1]`` and the window
        is ``[l2, r2]``, then the linear mapping function ``L`` is
        defined by the equations::

            L(l1) = l2
            L(r1) = r2


def integ(self, m=<NUM_LIT:1>, k=[], lbnd=None):

off, scl = self.mapparms()<EOL>if lbnd is None:<EOL><INDENT>lbnd = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>lbnd = off + scl*lbnd<EOL><DEDENT>coef = self._int(self.coef, m, k, lbnd, <NUM_LIT:1.>/scl)<EOL>return self.__class__(coef, self.domain, self.window)<EOL>

Integrate.

        Return a series instance that is the definite integral of the
        current series.

        Parameters
        ----------
        m : non-negative int
            The number of integrations to perform.
        k : array_like
            Integration constants. The first constant is applied to the
            first integration, the second to the second, and so on. The
            list of values must less than or equal to `m` in length and any
            missing values are set to zero.
        lbnd : Scalar
            The lower bound of the definite integral.

        Returns
        -------
        new_series : series
            A new series representing the integral. The domain is the same
            as the domain of the integrated series.


off, scl = self.mapparms()<EOL>coef = self._der(self.coef, m, scl)<EOL>return self.__class__(coef, self.domain, self.window)<EOL>

Differentiate.

        Return a series instance of that is the derivative of the current
        series.

        Parameters
        ----------
        m : non-negative int
            The number of integrations to perform.

        Returns
        -------
        new_series : series
            A new series representing the derivative. The domain is the same
            as the domain of the differentiated series.


roots = self._roots(self.coef)<EOL>return pu.mapdomain(roots, self.window, self.domain)<EOL>

Return the roots of the series polynomial.

        Compute the roots for the series. Note that the accuracy of the
        roots decrease the further outside the domain they lie.

        Returns
        -------
        roots : ndarray
            Array containing the roots of the series.


def linspace(self, n=<NUM_LIT:100>, domain=None):

if domain is None:<EOL><INDENT>domain = self.domain<EOL><DEDENT>x = np.linspace(domain[<NUM_LIT:0>], domain[<NUM_LIT:1>], n)<EOL>y = self(x)<EOL>return x, y<EOL>

Return x, y values at equally spaced points in domain.

        Returns the x, y values at `n` linearly spaced points across the
        domain.  Here y is the value of the polynomial at the points x. By
        default the domain is the same as that of the series instance.
        This method is intended mostly as a plotting aid.

        .. versionadded:: 1.5.0

        Parameters
        ----------
        n : int, optional
            Number of point pairs to return. The default value is 100.
        domain : {None, array_like}, optional
            If not None, the specified domain is used instead of that of
            the calling instance. It should be of the form ``[beg,end]``.
            The default is None which case the class domain is used.

        Returns
        -------
        x, y : ndarray
            x is equal to linspace(self.domain[0], self.domain[1], n) and
            y is the series evaluated at element of x.


@classmethod<EOL><INDENT>def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None,<EOL>window=None):<DEDENT>

if domain is None:<EOL><INDENT>domain = pu.getdomain(x)<EOL><DEDENT>elif type(domain) is list and len(domain) == <NUM_LIT:0>:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>xnew = pu.mapdomain(x, domain, window)<EOL>res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full)<EOL>if full:<EOL><INDENT>[coef, status] = res<EOL>return cls(coef, domain=domain, window=window), status<EOL><DEDENT>else:<EOL><INDENT>coef = res<EOL>return cls(coef, domain=domain, window=window)<EOL><DEDENT>

Least squares fit to data.

        Return a series instance that is the least squares fit to the data
        `y` sampled at `x`. The domain of the returned instance can be
        specified and this will often result in a superior fit with less
        chance of ill conditioning.

        Parameters
        ----------
        x : array_like, shape (M,)
            x-coordinates of the M sample points ``(x[i], y[i])``.
        y : array_like, shape (M,) or (M, K)
            y-coordinates of the sample points. Several data sets of sample
            points sharing the same x-coordinates can be fitted at once by
            passing in a 2D-array that contains one dataset per column.
        deg : int
            Degree of the fitting polynomial.
        domain : {None, [beg, end], []}, optional
            Domain to use for the returned series. If ``None``,
            then a minimal domain that covers the points `x` is chosen.  If
            ``[]`` the class domain is used. The default value was the
            class domain in NumPy 1.4 and ``None`` in later versions.
            The ``[]`` option was added in numpy 1.5.0.
        rcond : float, optional
            Relative condition number of the fit. Singular values smaller
            than this relative to the largest singular value will be
            ignored. The default value is len(x)*eps, where eps is the
            relative precision of the float type, about 2e-16 in most
            cases.
        full : bool, optional
            Switch determining nature of return value. When it is False
            (the default) just the coefficients are returned, when True
            diagnostic information from the singular value decomposition is
            also returned.
        w : array_like, shape (M,), optional
            Weights. If not None the contribution of each point
            ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the
            weights are chosen so that the errors of the products
            ``w[i]*y[i]`` all have the same variance.  The default value is
            None.

            .. versionadded:: 1.5.0
        window : {[beg, end]}, optional
            Window to use for the returned series. The default
            value is the default class domain

            .. versionadded:: 1.6.0

        Returns
        -------
        new_series : series
            A series that represents the least squares fit to the data and
            has the domain specified in the call.

        [resid, rank, sv, rcond] : list
            These values are only returned if `full` = True

            resid -- sum of squared residuals of the least squares fit
            rank -- the numerical rank of the scaled Vandermonde matrix
            sv -- singular values of the scaled Vandermonde matrix
            rcond -- value of `rcond`.

            For more details, see `linalg.lstsq`.


@classmethod<EOL><INDENT>def fromroots(cls, roots, domain=[], window=None):<DEDENT>

[roots] = pu.as_series([roots], trim=False)<EOL>if domain is None:<EOL><INDENT>domain = pu.getdomain(roots)<EOL><DEDENT>elif type(domain) is list and len(domain) == <NUM_LIT:0>:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>deg = len(roots)<EOL>off, scl = pu.mapparms(domain, window)<EOL>rnew = off + scl*roots<EOL>coef = cls._fromroots(rnew) / scl**deg<EOL>return cls(coef, domain=domain, window=window)<EOL>

Return series instance that has the specified roots.

        Returns a series representing the product
        ``(x - r[0])*(x - r[1])*...*(x - r[n-1])``, where ``r`` is a
        list of roots.

        Parameters
        ----------
        roots : array_like
            List of roots.
        domain : {[], None, array_like}, optional
            Domain for the resulting series. If None the domain is the
            interval from the smallest root to the largest. If [] the
            domain is the class domain. The default is [].
        window : {None, array_like}, optional
            Window for the returned series. If None the class window is
            used. The default is None.

        Returns
        -------
        new_series : series
            Series with the specified roots.


@classmethod<EOL><INDENT>def identity(cls, domain=None, window=None):<DEDENT>

if domain is None:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>off, scl = pu.mapparms(window, domain)<EOL>coef = cls._line(off, scl)<EOL>return cls(coef, domain, window)<EOL>

Identity function.

        If ``p`` is the returned series, then ``p(x) == x`` for all
        values of x.

        Parameters
        ----------
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.

        Returns
        -------
        new_series : series
             Series of representing the identity.


@classmethod<EOL><INDENT>def basis(cls, deg, domain=None, window=None):<DEDENT>

if domain is None:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>ideg = int(deg)<EOL>if ideg != deg or ideg < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return cls([<NUM_LIT:0>]*ideg + [<NUM_LIT:1>], domain, window)<EOL>

Series basis polynomial of degree `deg`.

        Returns the series representing the basis polynomial of degree `deg`.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        deg : int
            Degree of the basis polynomial for the series. Must be >= 0.
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.

        Returns
        -------
        new_series : series
            A series with the coefficient of the `deg` term set to one and
            all others zero.


@classmethod<EOL><INDENT>def cast(cls, series, domain=None, window=None):<DEDENT>

if domain is None:<EOL><INDENT>domain = cls.domain<EOL><DEDENT>if window is None:<EOL><INDENT>window = cls.window<EOL><DEDENT>return series.convert(domain, cls, window)<EOL>

Convert series to series of this class.

        The `series` is expected to be an instance of some polynomial
        series of one of the types supported by by the numpy.polynomial
        module, but could be some other class that supports the convert
        method.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        series : series
            The series instance to be converted.
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.

        Returns
        -------
        new_series : series
            A series of the same kind as the calling class and equal to
            `series` when evaluated.

        See Also
        --------
        convert : similar instance method


if len(seq) == <NUM_LIT:0>:<EOL><INDENT>return seq<EOL><DEDENT>else:<EOL><INDENT>for i in range(len(seq) - <NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>if seq[i] != <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return seq[:i+<NUM_LIT:1>]<EOL><DEDENT>

Remove small Poly series coefficients.

    Parameters
    ----------
    seq : sequence
        Sequence of Poly series coefficients. This routine fails for
        empty sequences.

    Returns
    -------
    series : sequence
        Subsequence with trailing zeros removed. If the resulting sequence
        would be empty, return the first element. The returned sequence may
        or may not be a view.

    Notes
    -----
    Do not lose the type info if the sequence contains unknown objects.


arrays = [np.array(a, ndmin=<NUM_LIT:1>, copy=<NUM_LIT:0>) for a in alist]<EOL>if min([a.size for a in arrays]) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any([a.ndim != <NUM_LIT:1> for a in arrays]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if trim:<EOL><INDENT>arrays = [trimseq(a) for a in arrays]<EOL><DEDENT>if any([a.dtype == np.dtype(object) for a in arrays]):<EOL><INDENT>ret = []<EOL>for a in arrays:<EOL><INDENT>if a.dtype != np.dtype(object):<EOL><INDENT>tmp = np.empty(len(a), dtype=np.dtype(object))<EOL>tmp[:] = a[:]<EOL>ret.append(tmp)<EOL><DEDENT>else:<EOL><INDENT>ret.append(a.copy())<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>dtype = np.common_type(*arrays)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>ret = [np.array(a, copy=<NUM_LIT:1>, dtype=dtype) for a in arrays]<EOL><DEDENT>return ret<EOL>

Return argument as a list of 1-d arrays.

The returned list contains array(s) of dtype double, complex double, or
object.  A 1-d argument of shape ``(N,)`` is parsed into ``N`` arrays of
size one; a 2-d argument of shape ``(M,N)`` is parsed into ``M`` arrays
of size ``N`` (i.e., is "parsed by row"); and a higher dimensional array
raises a Value Error if it is not first reshaped into either a 1-d or 2-d
array.

Parameters
----------
a : array_like
    A 1- or 2-d array_like
trim : boolean, optional
    When True, trailing zeros are removed from the inputs.
    When False, the inputs are passed through intact.

Returns
-------
[a1, a2,...] : list of 1-D arrays
    A copy of the input data as a list of 1-d arrays.

Raises
------
ValueError
    Raised when `as_series` cannot convert its input to 1-d arrays, or at
    least one of the resulting arrays is empty.

Examples
--------
>>> from numpy import polynomial as P
>>> a = np.arange(4)
>>> P.as_series(a)
[array([ 0.]), array([ 1.]), array([ 2.]), array([ 3.])]
>>> b = np.arange(6).reshape((2,3))
>>> P.as_series(b)
[array([ 0.,  1.,  2.]), array([ 3.,  4.,  5.])]


if tol < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>[c] = as_series([c])<EOL>[ind] = np.where(np.abs(c) > tol)<EOL>if len(ind) == <NUM_LIT:0>:<EOL><INDENT>return c[:<NUM_LIT:1>]*<NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>return c[:ind[-<NUM_LIT:1>] + <NUM_LIT:1>].copy()<EOL><DEDENT>

Remove "small" "trailing" coefficients from a polynomial.

"Small" means "small in absolute value" and is controlled by the
parameter `tol`; "trailing" means highest order coefficient(s), e.g., in
``[0, 1, 1, 0, 0]`` (which represents ``0 + x + x**2 + 0*x**3 + 0*x**4``)
both the 3-rd and 4-th order coefficients would be "trimmed."

Parameters
----------
c : array_like
    1-d array of coefficients, ordered from lowest order to highest.
tol : number, optional
    Trailing (i.e., highest order) elements with absolute value less
    than or equal to `tol` (default value is zero) are removed.

Returns
-------
trimmed : ndarray
    1-d array with trailing zeros removed.  If the resulting series
    would be empty, a series containing a single zero is returned.

Raises
------
ValueError
    If `tol` < 0

See Also
--------
trimseq

Examples
--------
>>> from numpy import polynomial as P
>>> P.trimcoef((0,0,3,0,5,0,0))
array([ 0.,  0.,  3.,  0.,  5.])
>>> P.trimcoef((0,0,1e-3,0,1e-5,0,0),1e-3) # item == tol is trimmed
array([ 0.])
>>> i = complex(0,1) # works for complex
>>> P.trimcoef((3e-4,1e-3*(1-i),5e-4,2e-5*(1+i)), 1e-3)
array([ 0.0003+0.j   ,  0.0010-0.001j])


[x] = as_series([x], trim=False)<EOL>if x.dtype.char in np.typecodes['<STR_LIT>']:<EOL><INDENT>rmin, rmax = x.real.min(), x.real.max()<EOL>imin, imax = x.imag.min(), x.imag.max()<EOL>return np.array((complex(rmin, imin), complex(rmax, imax)))<EOL><DEDENT>else:<EOL><INDENT>return np.array((x.min(), x.max()))<EOL><DEDENT>

Return a domain suitable for given abscissae.

Find a domain suitable for a polynomial or Chebyshev series
defined at the values supplied.

Parameters
----------
x : array_like
    1-d array of abscissae whose domain will be determined.

Returns
-------
domain : ndarray
    1-d array containing two values.  If the inputs are complex, then
    the two returned points are the lower left and upper right corners
    of the smallest rectangle (aligned with the axes) in the complex
    plane containing the points `x`. If the inputs are real, then the
    two points are the ends of the smallest interval containing the
    points `x`.

See Also
--------
mapparms, mapdomain

Examples
--------
>>> from numpy.polynomial import polyutils as pu
>>> points = np.arange(4)**2 - 5; points
array([-5, -4, -1,  4])
>>> pu.getdomain(points)
array([-5.,  4.])
>>> c = np.exp(complex(0,1)*np.pi*np.arange(12)/6) # unit circle
>>> pu.getdomain(c)
array([-1.-1.j,  1.+1.j])


oldlen = old[<NUM_LIT:1>] - old[<NUM_LIT:0>]<EOL>newlen = new[<NUM_LIT:1>] - new[<NUM_LIT:0>]<EOL>off = (old[<NUM_LIT:1>]*new[<NUM_LIT:0>] - old[<NUM_LIT:0>]*new[<NUM_LIT:1>])/oldlen<EOL>scl = newlen/oldlen<EOL>return off, scl<EOL>

Linear map parameters between domains.

Return the parameters of the linear map ``offset + scale*x`` that maps
`old` to `new` such that ``old[i] -> new[i]``, ``i = 0, 1``.

Parameters
----------
old, new : array_like
    Domains. Each domain must (successfully) convert to a 1-d array
    containing precisely two values.

Returns
-------
offset, scale : scalars
    The map ``L(x) = offset + scale*x`` maps the first domain to the
    second.

See Also
--------
getdomain, mapdomain

Notes
-----
Also works for complex numbers, and thus can be used to calculate the
parameters required to map any line in the complex plane to any other
line therein.

Examples
--------
>>> from numpy import polynomial as P
>>> P.mapparms((-1,1),(-1,1))
(0.0, 1.0)
>>> P.mapparms((1,-1),(-1,1))
(0.0, -1.0)
>>> i = complex(0,1)
>>> P.mapparms((-i,-1),(1,i))
((1+1j), (1+0j))


x = np.asanyarray(x)<EOL>off, scl = mapparms(old, new)<EOL>return off + scl*x<EOL>

Apply linear map to input points.

The linear map ``offset + scale*x`` that maps the domain `old` to
the domain `new` is applied to the points `x`.

Parameters
----------
x : array_like
    Points to be mapped. If `x` is a subtype of ndarray the subtype
    will be preserved.
old, new : array_like
    The two domains that determine the map.  Each must (successfully)
    convert to 1-d arrays containing precisely two values.

Returns
-------
x_out : ndarray
    Array of points of the same shape as `x`, after application of the
    linear map between the two domains.

See Also
--------
getdomain, mapparms

Notes
-----
Effectively, this implements:

.. math ::
    x\\_out = new[0] + m(x - old[0])

where

.. math ::
    m = \\frac{new[1]-new[0]}{old[1]-old[0]}

Examples
--------
>>> from numpy import polynomial as P
>>> old_domain = (-1,1)
>>> new_domain = (0,2*np.pi)
>>> x = np.linspace(-1,1,6); x
array([-1. , -0.6, -0.2,  0.2,  0.6,  1. ])
>>> x_out = P.mapdomain(x, old_domain, new_domain); x_out
array([ 0.        ,  1.25663706,  2.51327412,  3.76991118,  5.02654825,
        6.28318531])
>>> x - P.mapdomain(x_out, new_domain, old_domain)
array([ 0.,  0.,  0.,  0.,  0.,  0.])

Also works for complex numbers (and thus can be used to map any line in
the complex plane to any other line therein).

>>> i = complex(0,1)
>>> old = (-1 - i, 1 + i)
>>> new = (-1 + i, 1 - i)
>>> z = np.linspace(old[0], old[1], 6); z
array([-1.0-1.j , -0.6-0.6j, -0.2-0.2j,  0.2+0.2j,  0.6+0.6j,  1.0+1.j ])
>>> new_z = P.mapdomain(z, old, new); new_z
array([-1.0+1.j , -0.6+0.6j, -0.2+0.2j,  0.2-0.2j,  0.6-0.6j,  1.0-1.j ])


@_memoize<EOL>def build_module(source_files, options=[], skip=[], only=[], module_name=None):

code = ("<STR_LIT>"<EOL>"<STR_LIT>" % repr(sys.path))<EOL>d = get_module_dir()<EOL>dst_sources = []<EOL>for fn in source_files:<EOL><INDENT>if not os.path.isfile(fn):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % fn)<EOL><DEDENT>dst = os.path.join(d, os.path.basename(fn))<EOL>shutil.copyfile(fn, dst)<EOL>dst_sources.append(dst)<EOL>fn = os.path.join(os.path.dirname(fn), '<STR_LIT>')<EOL>if os.path.isfile(fn):<EOL><INDENT>dst = os.path.join(d, os.path.basename(fn))<EOL>if not os.path.isfile(dst):<EOL><INDENT>shutil.copyfile(fn, dst)<EOL><DEDENT><DEDENT><DEDENT>if module_name is None:<EOL><INDENT>module_name = get_temp_module_name()<EOL><DEDENT>f2py_opts = ['<STR_LIT:-c>', '<STR_LIT>', module_name] + options + dst_sources<EOL>if skip:<EOL><INDENT>f2py_opts += ['<STR_LIT>'] + skip<EOL><DEDENT>if only:<EOL><INDENT>f2py_opts += ['<STR_LIT>'] + only<EOL><DEDENT>cwd = os.getcwd()<EOL>try:<EOL><INDENT>os.chdir(d)<EOL>cmd = [sys.executable, '<STR_LIT:-c>', code] + f2py_opts<EOL>p = subprocess.Popen(cmd, stdout=subprocess.PIPE,<EOL>stderr=subprocess.STDOUT)<EOL>out, err = p.communicate()<EOL>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>% (cmd[<NUM_LIT:4>:], asstr(out)))<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>os.chdir(cwd)<EOL>for fn in dst_sources:<EOL><INDENT>os.unlink(fn)<EOL><DEDENT><DEDENT>__import__(module_name)<EOL>return sys.modules[module_name]<EOL>

Compile and import a f2py module, built from the given files.


@_memoize<EOL>def build_code(source_code, options=[], skip=[], only=[], suffix=None,<EOL>module_name=None):

if suffix is None:<EOL><INDENT>suffix = '<STR_LIT>'<EOL><DEDENT>fd, tmp_fn = tempfile.mkstemp(suffix=suffix)<EOL>os.write(fd, asbytes(source_code))<EOL>os.close(fd)<EOL>try:<EOL><INDENT>return build_module([tmp_fn], options=options, skip=skip, only=only,<EOL>module_name=module_name)<EOL><DEDENT>finally:<EOL><INDENT>os.unlink(tmp_fn)<EOL><DEDENT>

Compile and import Fortran code using f2py.


@_memoize<EOL>def build_module_distutils(source_files, config_code, module_name, **kw):

from numpy.distutils.misc_util import Configuration<EOL>from numpy.distutils.core import setup<EOL>d = get_module_dir()<EOL>dst_sources = []<EOL>for fn in source_files:<EOL><INDENT>if not os.path.isfile(fn):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % fn)<EOL><DEDENT>dst = os.path.join(d, os.path.basename(fn))<EOL>shutil.copyfile(fn, dst)<EOL>dst_sources.append(dst)<EOL><DEDENT>config_code = textwrap.dedent(config_code).replace("<STR_LIT:\n>", "<STR_LIT>")<EOL>code =

Build a module via distutils and import it.


global wrap<EOL>if not util.has_c_compiler():<EOL><INDENT>raise nose.SkipTest("<STR_LIT>")<EOL><DEDENT>if wrap is None:<EOL><INDENT>config_code = """<STR_LIT>"""<EOL>d = os.path.dirname(__file__)<EOL>src = [os.path.join(d, '<STR_LIT:src>', '<STR_LIT>', '<STR_LIT>'),<EOL>os.path.join(d, '<STR_LIT:..>', '<STR_LIT:src>', '<STR_LIT>'),<EOL>os.path.join(d, '<STR_LIT:..>', '<STR_LIT:src>', '<STR_LIT>')]<EOL>wrap = util.build_module_distutils(src, config_code,<EOL>'<STR_LIT>')<EOL><DEDENT>

Build the required testing extension module


if self.obj is self.arr:<EOL><INDENT>return True<EOL><DEDENT>if not isinstance(self.obj, ndarray):<EOL><INDENT>return False<EOL><DEDENT>obj_attr = wrap.array_attrs(self.obj)<EOL>return obj_attr[<NUM_LIT:0>]==self.arr_attr[<NUM_LIT:0>]<EOL>

Check that created array shares data with input array.


crackfortran.reset_global_f2py_vars()<EOL>f2pydir=os.path.dirname(os.path.abspath(cfuncs.__file__))<EOL>fobjhsrc = os.path.join(f2pydir, '<STR_LIT:src>', '<STR_LIT>')<EOL>fobjcsrc = os.path.join(f2pydir, '<STR_LIT:src>', '<STR_LIT>')<EOL>files, options=scaninputline(comline_list)<EOL>auxfuncs.options=options<EOL>postlist=callcrackfortran(files, options)<EOL>isusedby={}<EOL>for i in range(len(postlist)):<EOL><INDENT>if '<STR_LIT>' in postlist[i]:<EOL><INDENT>for u in postlist[i]['<STR_LIT>'].keys():<EOL><INDENT>if u not in isusedby:<EOL><INDENT>isusedby[u]=[]<EOL><DEDENT>isusedby[u].append(postlist[i]['<STR_LIT:name>'])<EOL><DEDENT><DEDENT><DEDENT>for i in range(len(postlist)):<EOL><INDENT>if postlist[i]['<STR_LIT>']=='<STR_LIT>' and '<STR_LIT>' in postlist[i]['<STR_LIT:name>']:<EOL><INDENT>if postlist[i]['<STR_LIT:name>'] in isusedby:<EOL><INDENT>outmess('<STR_LIT>'%(postlist[i]['<STR_LIT:name>'], '<STR_LIT:U+002C>'.join(['<STR_LIT>'%s for s in isusedby[postlist[i]['<STR_LIT:name>']]])))<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in options:<EOL><INDENT>if options['<STR_LIT>']><NUM_LIT:1>:<EOL><INDENT>outmess('<STR_LIT>')<EOL>outmess('<STR_LIT>'%(os.path.basename(sys.argv[<NUM_LIT:0>]), options['<STR_LIT>']))<EOL><DEDENT>return<EOL><DEDENT>for i in range(len(postlist)):<EOL><INDENT>if postlist[i]['<STR_LIT>']!='<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' not in options:<EOL><INDENT>errmess('<STR_LIT>')<EOL><DEDENT>raise TypeError('<STR_LIT>'%(repr(postlist[i]['<STR_LIT>'])))<EOL><DEDENT><DEDENT>auxfuncs.debugoptions=options['<STR_LIT>']<EOL>f90mod_rules.options=options<EOL>auxfuncs.wrapfuncs=options['<STR_LIT>']<EOL>ret=buildmodules(postlist)<EOL>for mn in ret.keys():<EOL><INDENT>dict_append(ret[mn], {'<STR_LIT>':fobjcsrc,'<STR_LIT:h>':fobjhsrc})<EOL><DEDENT>return ret<EOL>

Run f2py as if string.join(comline_list,' ') is used as a command line.
    In case of using -h flag, return None.


filtered, rest = [], []<EOL>match = re.compile(prefix+r'<STR_LIT>'+suffix+r'<STR_LIT>').match<EOL>if remove_prefix:<EOL><INDENT>ind = len(prefix)<EOL><DEDENT>else:<EOL><INDENT>ind = <NUM_LIT:0><EOL><DEDENT>for file in [x.strip() for x in files]:<EOL><INDENT>if match(file): filtered.append(file[ind:])<EOL>else: rest.append(file)<EOL><DEDENT>return filtered, rest<EOL>


import tempfile<EOL>i = sys.argv.index('<STR_LIT:-c>')<EOL>del sys.argv[i]<EOL>remove_build_dir = <NUM_LIT:0><EOL>try: i = sys.argv.index('<STR_LIT>')<EOL>except ValueError: i=None<EOL>if i is not None:<EOL><INDENT>build_dir = sys.argv[i+<NUM_LIT:1>]<EOL>del sys.argv[i+<NUM_LIT:1>]<EOL>del sys.argv[i]<EOL><DEDENT>else:<EOL><INDENT>remove_build_dir = <NUM_LIT:1><EOL>build_dir = tempfile.mkdtemp()<EOL><DEDENT>_reg1 = re.compile(r'<STR_LIT>')<EOL>sysinfo_flags = [_m for _m in sys.argv[<NUM_LIT:1>:] if _reg1.match(_m)]<EOL>sys.argv = [_m for _m in sys.argv if _m not in sysinfo_flags]<EOL>if sysinfo_flags:<EOL><INDENT>sysinfo_flags = [f[<NUM_LIT:7>:] for f in sysinfo_flags]<EOL><DEDENT>_reg2 = re.compile(r'<STR_LIT>')<EOL>f2py_flags = [_m for _m in sys.argv[<NUM_LIT:1>:] if _reg2.match(_m)]<EOL>sys.argv = [_m for _m in sys.argv if _m not in f2py_flags]<EOL>f2py_flags2 = []<EOL>fl = <NUM_LIT:0><EOL>for a in sys.argv[<NUM_LIT:1>:]:<EOL><INDENT>if a in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>fl = <NUM_LIT:1><EOL><DEDENT>elif a=='<STR_LIT::>':<EOL><INDENT>fl = <NUM_LIT:0><EOL><DEDENT>if fl or a=='<STR_LIT::>':<EOL><INDENT>f2py_flags2.append(a)<EOL><DEDENT><DEDENT>if f2py_flags2 and f2py_flags2[-<NUM_LIT:1>]!='<STR_LIT::>':<EOL><INDENT>f2py_flags2.append('<STR_LIT::>')<EOL><DEDENT>f2py_flags.extend(f2py_flags2)<EOL>sys.argv = [_m for _m in sys.argv if _m not in f2py_flags2]<EOL>_reg3 = re.compile(r'<STR_LIT>')<EOL>flib_flags = [_m for _m in sys.argv[<NUM_LIT:1>:] if _reg3.match(_m)]<EOL>sys.argv = [_m for _m in sys.argv if _m not in flib_flags]<EOL>_reg4 = re.compile(r'<STR_LIT>')<EOL>fc_flags = [_m for _m in sys.argv[<NUM_LIT:1>:] if _reg4.match(_m)]<EOL>sys.argv = [_m for _m in sys.argv if _m not in fc_flags]<EOL>if <NUM_LIT:1>:<EOL><INDENT>del_list = []<EOL>for s in flib_flags:<EOL><INDENT>v = '<STR_LIT>'<EOL>if s[:len(v)]==v:<EOL><INDENT>from numpy.distutils import fcompiler<EOL>fcompiler.load_all_fcompiler_classes()<EOL>allowed_keys = list(fcompiler.fcompiler_class.keys())<EOL>nv = ov = s[len(v):].lower()<EOL>if ov not in allowed_keys:<EOL><INDENT>vmap = {} <EOL>try:<EOL><INDENT>nv = vmap[ov]<EOL><DEDENT>except KeyError:<EOL><INDENT>if ov not in vmap.values():<EOL><INDENT>print('<STR_LIT>' % (s[len(v):]))<EOL><DEDENT><DEDENT>nv = ov<EOL><DEDENT>i = flib_flags.index(s)<EOL>flib_flags[i] = '<STR_LIT>' + nv<EOL>continue<EOL><DEDENT><DEDENT>for s in del_list:<EOL><INDENT>i = flib_flags.index(s)<EOL>del flib_flags[i]<EOL><DEDENT>assert len(flib_flags)<=<NUM_LIT:2>, repr(flib_flags)<EOL><DEDENT>_reg5 = re.compile(r'<STR_LIT>')<EOL>setup_flags = [_m for _m in sys.argv[<NUM_LIT:1>:] if _reg5.match(_m)]<EOL>sys.argv = [_m for _m in sys.argv if _m not in setup_flags]<EOL>if '<STR_LIT>' in f2py_flags:<EOL><INDENT>setup_flags.append('<STR_LIT>')<EOL><DEDENT>modulename = '<STR_LIT>'<EOL>sources = sys.argv[<NUM_LIT:1>:]<EOL>for optname in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if optname in sys.argv:<EOL><INDENT>i = sys.argv.index (optname)<EOL>f2py_flags.extend (sys.argv[i:i+<NUM_LIT:2>])<EOL>del sys.argv[i+<NUM_LIT:1>], sys.argv[i]<EOL>sources = sys.argv[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>if '<STR_LIT>' in sys.argv:<EOL><INDENT>i = sys.argv.index('<STR_LIT>')<EOL>modulename = sys.argv[i+<NUM_LIT:1>]<EOL>del sys.argv[i+<NUM_LIT:1>], sys.argv[i]<EOL>sources = sys.argv[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>from numpy.distutils.command.build_src import get_f2py_modulename<EOL>pyf_files, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources)<EOL>sources = pyf_files + sources<EOL>for f in pyf_files:<EOL><INDENT>modulename = get_f2py_modulename(f)<EOL>if modulename:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>extra_objects, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources)<EOL>include_dirs, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources, remove_prefix=<NUM_LIT:1>)<EOL>library_dirs, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources, remove_prefix=<NUM_LIT:1>)<EOL>libraries, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources, remove_prefix=<NUM_LIT:1>)<EOL>undef_macros, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources, remove_prefix=<NUM_LIT:1>)<EOL>define_macros, sources = filter_files('<STR_LIT>', '<STR_LIT>', sources, remove_prefix=<NUM_LIT:1>)<EOL>using_numarray = <NUM_LIT:0><EOL>using_numeric = <NUM_LIT:0><EOL>for i in range(len(define_macros)):<EOL><INDENT>name_value = define_macros[i].split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>if len(name_value)==<NUM_LIT:1>:<EOL><INDENT>name_value.append(None)<EOL><DEDENT>if len(name_value)==<NUM_LIT:2>:<EOL><INDENT>define_macros[i] = tuple(name_value)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>', name_value)<EOL><DEDENT><DEDENT>from numpy.distutils.system_info import get_info<EOL>num_include_dir = None<EOL>num_info = {}<EOL>if num_info:<EOL><INDENT>include_dirs.extend(num_info.get('<STR_LIT>', []))<EOL><DEDENT>from numpy.distutils.core import setup, Extension<EOL>ext_args = {'<STR_LIT:name>': modulename, '<STR_LIT>': sources,<EOL>'<STR_LIT>': include_dirs,<EOL>'<STR_LIT>': library_dirs,<EOL>'<STR_LIT>': libraries,<EOL>'<STR_LIT>': define_macros,<EOL>'<STR_LIT>': undef_macros,<EOL>'<STR_LIT>': extra_objects,<EOL>'<STR_LIT>': f2py_flags,<EOL>}<EOL>if sysinfo_flags:<EOL><INDENT>from numpy.distutils.misc_util import dict_append<EOL>for n in sysinfo_flags:<EOL><INDENT>i = get_info(n)<EOL>if not i:<EOL><INDENT>outmess('<STR_LIT>''<STR_LIT>' % (repr(n)))<EOL><DEDENT>dict_append(ext_args,**i)<EOL><DEDENT><DEDENT>ext = Extension(**ext_args)<EOL>sys.argv = [sys.argv[<NUM_LIT:0>]] + setup_flags<EOL>sys.argv.extend(['<STR_LIT>',<EOL>'<STR_LIT>', build_dir,<EOL>'<STR_LIT>', build_dir,<EOL>'<STR_LIT>', '<STR_LIT:.>'])<EOL>if fc_flags:<EOL><INDENT>sys.argv.extend(['<STR_LIT>']+fc_flags)<EOL><DEDENT>if flib_flags:<EOL><INDENT>sys.argv.extend(['<STR_LIT>']+flib_flags)<EOL><DEDENT>setup(ext_modules = [ext])<EOL>if remove_build_dir and os.path.exists(build_dir):<EOL><INDENT>import shutil<EOL>outmess('<STR_LIT>'%(build_dir))<EOL>shutil.rmtree(build_dir)<EOL><DEDENT>


<EOL>result = <NUM_LIT:0><EOL>f = open(file, '<STR_LIT:r>')<EOL>line = f.readline()<EOL>n = <NUM_LIT:15> <EOL>if _has_f_header(line):<EOL><INDENT>n = <NUM_LIT:0><EOL><DEDENT>elif _has_f90_header(line):<EOL><INDENT>n = <NUM_LIT:0><EOL>result = <NUM_LIT:1><EOL><DEDENT>while n><NUM_LIT:0> and line:<EOL><INDENT>if line[<NUM_LIT:0>]!='<STR_LIT:!>' and line.strip():<EOL><INDENT>n -= <NUM_LIT:1><EOL>if (line[<NUM_LIT:0>]!='<STR_LIT:\t>' and _free_f90_start(line[:<NUM_LIT:5>])) or line[-<NUM_LIT:2>:-<NUM_LIT:1>]=='<STR_LIT:&>':<EOL><INDENT>result = <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>line = f.readline()<EOL><DEDENT>f.close()<EOL>return result<EOL>

Check if file is in free format Fortran.


global gotnextfile, filepositiontext, currentfilename, sourcecodeform, strictf77,beginpattern, quiet, verbose, dolowercase, include_paths<EOL>if not istop:<EOL><INDENT>saveglobals=gotnextfile, filepositiontext, currentfilename, sourcecodeform, strictf77,beginpattern, quiet, verbose, dolowercase<EOL><DEDENT>if ffile==[]: return<EOL>localdolowercase = dolowercase<EOL>cont=<NUM_LIT:0><EOL>finalline='<STR_LIT>'<EOL>ll='<STR_LIT>'<EOL>commentline=re.compile(r'<STR_LIT>')<EOL>includeline=re.compile(r'<STR_LIT>', re.I)<EOL>cont1=re.compile(r'<STR_LIT>')<EOL>cont2=re.compile(r'<STR_LIT>')<EOL>mline_mark = re.compile(r"<STR_LIT>")<EOL>if istop: dowithline('<STR_LIT>', -<NUM_LIT:1>)<EOL>ll, l1='<STR_LIT>', '<STR_LIT>'<EOL>spacedigits=['<STR_LIT:U+0020>'] + [str(_m) for _m in range(<NUM_LIT:10>)]<EOL>filepositiontext='<STR_LIT>'<EOL>fin=fileinput.FileInput(ffile)<EOL>while True:<EOL><INDENT>l=fin.readline()<EOL>if not l: break<EOL>if fin.isfirstline():<EOL><INDENT>filepositiontext='<STR_LIT>'<EOL>currentfilename=fin.filename()<EOL>gotnextfile=<NUM_LIT:1><EOL>l1=l<EOL>strictf77=<NUM_LIT:0><EOL>sourcecodeform='<STR_LIT>'<EOL>ext = os.path.splitext(currentfilename)[<NUM_LIT:1>]<EOL>if is_f_file(currentfilename) andnot (_has_f90_header(l) or _has_fix_header(l)):<EOL><INDENT>strictf77=<NUM_LIT:1><EOL><DEDENT>elif is_free_format(currentfilename) and not _has_fix_header(l):<EOL><INDENT>sourcecodeform='<STR_LIT>'<EOL><DEDENT>if strictf77: beginpattern=beginpattern77<EOL>else: beginpattern=beginpattern90<EOL>outmess('<STR_LIT>'%(repr(currentfilename), sourcecodeform,<EOL>strictf77 and '<STR_LIT>' or '<STR_LIT>'))<EOL><DEDENT>l=l.expandtabs().replace('<STR_LIT>', '<STR_LIT:U+0020>')<EOL>while not l=='<STR_LIT>':                       <EOL><INDENT>if l[-<NUM_LIT:1>] not in "<STR_LIT>": break<EOL>l=l[:-<NUM_LIT:1>]<EOL><DEDENT>if not strictf77:<EOL><INDENT>r=commentline.match(l)<EOL>if r:<EOL><INDENT>l=r.group('<STR_LIT>')+'<STR_LIT:U+0020>' <EOL>rl=r.group('<STR_LIT>')<EOL>if rl[:<NUM_LIT:4>].lower()=='<STR_LIT>': <EOL><INDENT>l = l + <NUM_LIT:4>*'<STR_LIT:U+0020>'<EOL>r=commentline.match(rl[<NUM_LIT:4>:])<EOL>if r: l=l+r.group('<STR_LIT>')<EOL>else: l = l + rl[<NUM_LIT:4>:]<EOL><DEDENT><DEDENT><DEDENT>if l.strip()=='<STR_LIT>': <EOL><INDENT>cont=<NUM_LIT:0><EOL>continue<EOL><DEDENT>if sourcecodeform=='<STR_LIT>':<EOL><INDENT>if l[<NUM_LIT:0>] in ['<STR_LIT:*>', '<STR_LIT:c>', '<STR_LIT:!>', '<STR_LIT:C>', '<STR_LIT:#>']:<EOL><INDENT>if l[<NUM_LIT:1>:<NUM_LIT:5>].lower()=='<STR_LIT>': <EOL><INDENT>l='<STR_LIT:U+0020>'+l[<NUM_LIT:5>:]<EOL><DEDENT>else: <EOL><INDENT>cont=<NUM_LIT:0><EOL>continue<EOL><DEDENT><DEDENT>elif strictf77:<EOL><INDENT>if len(l)><NUM_LIT>: l=l[:<NUM_LIT>]<EOL><DEDENT>if not (l[<NUM_LIT:0>] in spacedigits):<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % repr(l))<EOL><DEDENT>if (not cont or strictf77) and (len(l)><NUM_LIT:5> and not l[<NUM_LIT:5>]=='<STR_LIT:U+0020>'):<EOL><INDENT>ll=ll+l[<NUM_LIT:6>:]<EOL>finalline='<STR_LIT>'<EOL>origfinalline='<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if not strictf77:<EOL><INDENT>r=cont1.match(l)<EOL>if r: l=r.group('<STR_LIT>') <EOL>if cont:<EOL><INDENT>ll=ll+cont2.match(l).group('<STR_LIT>')<EOL>finalline='<STR_LIT>'<EOL>origfinalline='<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>l='<STR_LIT:U+0020>'+l[<NUM_LIT:5>:] <EOL>if localdolowercase: finalline=ll.lower()<EOL>else: finalline=ll<EOL>origfinalline=ll<EOL>ll=l<EOL><DEDENT>cont=(r is not None)<EOL><DEDENT>else:<EOL><INDENT>l='<STR_LIT:U+0020>'+l[<NUM_LIT:5>:] <EOL>if localdolowercase: finalline=ll.lower()<EOL>else: finalline=ll<EOL>origfinalline =ll<EOL>ll=l<EOL><DEDENT><DEDENT><DEDENT>elif sourcecodeform=='<STR_LIT>':<EOL><INDENT>if not cont and ext=='<STR_LIT>' and mline_mark.match(l):<EOL><INDENT>l = l + '<STR_LIT:\n>'<EOL>while True:<EOL><INDENT>lc = fin.readline()<EOL>if not lc:<EOL><INDENT>errmess('<STR_LIT>')<EOL>break<EOL><DEDENT>l = l + lc<EOL>if mline_mark.match(lc):<EOL><INDENT>break<EOL><DEDENT><DEDENT>l = l.rstrip()<EOL><DEDENT>r=cont1.match(l)<EOL>if r: l=r.group('<STR_LIT>') <EOL>if cont:<EOL><INDENT>ll=ll+cont2.match(l).group('<STR_LIT>')<EOL>finalline='<STR_LIT>'<EOL>origfinalline='<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if localdolowercase: finalline=ll.lower()<EOL>else: finalline=ll<EOL>origfinalline =ll<EOL>ll=l<EOL><DEDENT>cont=(r is not None)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"%repr(sourcecodeform))<EOL><DEDENT>filepositiontext='<STR_LIT>' % (fin.filelineno()-<NUM_LIT:1>, currentfilename, l1)<EOL>m=includeline.match(origfinalline)<EOL>if m:<EOL><INDENT>fn=m.group('<STR_LIT:name>')<EOL>if os.path.isfile(fn):<EOL><INDENT>readfortrancode(fn, dowithline=dowithline, istop=<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>include_dirs = [os.path.dirname(currentfilename)] + include_paths<EOL>foundfile = <NUM_LIT:0><EOL>for inc_dir in include_dirs:<EOL><INDENT>fn1 = os.path.join(inc_dir, fn)<EOL>if os.path.isfile(fn1):<EOL><INDENT>foundfile = <NUM_LIT:1><EOL>readfortrancode(fn1, dowithline=dowithline, istop=<NUM_LIT:0>)<EOL>break<EOL><DEDENT><DEDENT>if not foundfile:<EOL><INDENT>outmess('<STR_LIT>'%(repr(fn), os.pathsep.join(include_dirs)))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>dowithline(finalline)<EOL><DEDENT>l1=ll<EOL><DEDENT>if localdolowercase:<EOL><INDENT>finalline=ll.lower()<EOL><DEDENT>else: finalline=ll<EOL>origfinalline = ll<EOL>filepositiontext='<STR_LIT>' % (fin.filelineno()-<NUM_LIT:1>, currentfilename, l1)<EOL>m=includeline.match(origfinalline)<EOL>if m:<EOL><INDENT>fn=m.group('<STR_LIT:name>')<EOL>if os.path.isfile(fn):<EOL><INDENT>readfortrancode(fn, dowithline=dowithline, istop=<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>include_dirs = [os.path.dirname(currentfilename)] + include_paths<EOL>foundfile = <NUM_LIT:0><EOL>for inc_dir in include_dirs:<EOL><INDENT>fn1 = os.path.join(inc_dir, fn)<EOL>if os.path.isfile(fn1):<EOL><INDENT>foundfile = <NUM_LIT:1><EOL>readfortrancode(fn1, dowithline=dowithline, istop=<NUM_LIT:0>)<EOL>break<EOL><DEDENT><DEDENT>if not foundfile:<EOL><INDENT>outmess('<STR_LIT>'%(repr(fn), os.pathsep.join(include_dirs)))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>dowithline(finalline)<EOL><DEDENT>filepositiontext='<STR_LIT>'<EOL>fin.close()<EOL>if istop: dowithline('<STR_LIT>', <NUM_LIT:1>)<EOL>else:<EOL><INDENT>gotnextfile, filepositiontext, currentfilename, sourcecodeform, strictf77,beginpattern, quiet, verbose, dolowercase=saveglobals<EOL><DEDENT>

Read fortran codes from files and
 1) Get rid of comments, line continuations, and empty lines; lower cases.
 2) Call dowithline(line) on every line.
 3) Recursively call itself when statement \"include '<filename>'\" is met.


global beginpattern, groupcounter, groupname, groupcache, grouplist, gotnextfile,filepositiontext, currentfilename, neededmodule, expectbegin, skipblocksuntil,skipemptyends, previous_context<EOL>if '<STR_LIT:;>' in line and not (f2pyenhancementspattern[<NUM_LIT:0>].match(line) or<EOL>multilinepattern[<NUM_LIT:0>].match(line)):<EOL><INDENT>for l in line.split('<STR_LIT:;>'):<EOL><INDENT>assert reset==<NUM_LIT:0>, repr(reset) <EOL>crackline(l, reset)<EOL><DEDENT>return<EOL><DEDENT>if reset<<NUM_LIT:0>:<EOL><INDENT>groupcounter=<NUM_LIT:0><EOL>groupname={groupcounter:'<STR_LIT>'}<EOL>groupcache={groupcounter:{}}<EOL>grouplist={groupcounter:[]}<EOL>groupcache[groupcounter]['<STR_LIT:body>']=[]<EOL>groupcache[groupcounter]['<STR_LIT>']={}<EOL>groupcache[groupcounter]['<STR_LIT>']='<STR_LIT>'<EOL>groupcache[groupcounter]['<STR_LIT:name>']='<STR_LIT>'<EOL>neededmodule=-<NUM_LIT:1><EOL>skipblocksuntil=-<NUM_LIT:1><EOL>return<EOL><DEDENT>if reset><NUM_LIT:0>:<EOL><INDENT>fl=<NUM_LIT:0><EOL>if f77modulename and neededmodule==groupcounter: fl=<NUM_LIT:2><EOL>while groupcounter>fl:<EOL><INDENT>outmess('<STR_LIT>'%(repr(groupcounter), repr(groupname)))<EOL>outmess('<STR_LIT>')<EOL>grouplist[groupcounter-<NUM_LIT:1>].append(groupcache[groupcounter])<EOL>grouplist[groupcounter-<NUM_LIT:1>][-<NUM_LIT:1>]['<STR_LIT:body>']=grouplist[groupcounter]<EOL>del grouplist[groupcounter]<EOL>groupcounter=groupcounter-<NUM_LIT:1><EOL><DEDENT>if f77modulename and neededmodule==groupcounter:<EOL><INDENT>grouplist[groupcounter-<NUM_LIT:1>].append(groupcache[groupcounter])<EOL>grouplist[groupcounter-<NUM_LIT:1>][-<NUM_LIT:1>]['<STR_LIT:body>']=grouplist[groupcounter]<EOL>del grouplist[groupcounter]<EOL>groupcounter=groupcounter-<NUM_LIT:1> <EOL>grouplist[groupcounter-<NUM_LIT:1>].append(groupcache[groupcounter])<EOL>grouplist[groupcounter-<NUM_LIT:1>][-<NUM_LIT:1>]['<STR_LIT:body>']=grouplist[groupcounter]<EOL>del grouplist[groupcounter]<EOL>groupcounter=groupcounter-<NUM_LIT:1> <EOL>neededmodule=-<NUM_LIT:1><EOL><DEDENT>return<EOL><DEDENT>if line=='<STR_LIT>': return<EOL>flag=<NUM_LIT:0><EOL>for pat in [dimensionpattern, externalpattern, intentpattern, optionalpattern,<EOL>requiredpattern,<EOL>parameterpattern, datapattern, publicpattern, privatepattern,<EOL>intrisicpattern,<EOL>endifpattern, endpattern,<EOL>formatpattern,<EOL>beginpattern, functionpattern, subroutinepattern,<EOL>implicitpattern, typespattern, commonpattern,<EOL>callpattern, usepattern, containspattern,<EOL>entrypattern,<EOL>f2pyenhancementspattern,<EOL>multilinepattern<EOL>]:<EOL><INDENT>m = pat[<NUM_LIT:0>].match(line)<EOL>if m:<EOL><INDENT>break<EOL><DEDENT>flag=flag+<NUM_LIT:1><EOL><DEDENT>if not m:<EOL><INDENT>re_1 = crackline_re_1<EOL>if <NUM_LIT:0><=skipblocksuntil<=groupcounter:return<EOL>if '<STR_LIT>' in groupcache[groupcounter]:<EOL><INDENT>for name in groupcache[groupcounter]['<STR_LIT>']:<EOL><INDENT>if name in invbadnames:<EOL><INDENT>name=invbadnames[name]<EOL><DEDENT>if '<STR_LIT>' in groupcache[groupcounter] and name in groupcache[groupcounter]['<STR_LIT>']:<EOL><INDENT>continue<EOL><DEDENT>m1=re.match(r'<STR_LIT>'%name, markouterparen(line), re.I)<EOL>if m1:<EOL><INDENT>m2 = re_1.match(m1.group('<STR_LIT>'))<EOL>a = _simplifyargs(m1.group('<STR_LIT:args>'))<EOL>if m2:<EOL><INDENT>line='<STR_LIT>'%(name, a, m2.group('<STR_LIT:result>'))<EOL><DEDENT>else: line='<STR_LIT>'%(name, a)<EOL>m = callfunpattern[<NUM_LIT:0>].match(line)<EOL>if not m:<EOL><INDENT>outmess('<STR_LIT>'%repr(line))<EOL>return<EOL><DEDENT>analyzeline(m, '<STR_LIT>', line)<EOL>return<EOL><DEDENT><DEDENT><DEDENT>if verbose><NUM_LIT:1> or (verbose==<NUM_LIT:1> and currentfilename.lower().endswith('<STR_LIT>')):<EOL><INDENT>previous_context = None<EOL>outmess('<STR_LIT>'%(groupcounter))<EOL><DEDENT>return<EOL><DEDENT>elif pat[<NUM_LIT:1>]=='<STR_LIT:end>':<EOL><INDENT>if <NUM_LIT:0><=skipblocksuntil<groupcounter:<EOL><INDENT>groupcounter=groupcounter-<NUM_LIT:1><EOL>if skipblocksuntil<=groupcounter: return<EOL><DEDENT>if groupcounter<=<NUM_LIT:0>:<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>'% (groupcounter))<EOL><DEDENT>m1 = beginpattern[<NUM_LIT:0>].match((line))<EOL>if (m1) and (not m1.group('<STR_LIT>')==groupname[groupcounter]):<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>' %(repr(m1.group('<STR_LIT>')), repr(groupname[groupcounter]),<EOL>filepositiontext)<EOL>)<EOL><DEDENT>if skipblocksuntil==groupcounter:<EOL><INDENT>skipblocksuntil=-<NUM_LIT:1><EOL><DEDENT>grouplist[groupcounter-<NUM_LIT:1>].append(groupcache[groupcounter])<EOL>grouplist[groupcounter-<NUM_LIT:1>][-<NUM_LIT:1>]['<STR_LIT:body>']=grouplist[groupcounter]<EOL>del grouplist[groupcounter]<EOL>groupcounter=groupcounter-<NUM_LIT:1><EOL>if not skipemptyends:<EOL><INDENT>expectbegin=<NUM_LIT:1><EOL><DEDENT><DEDENT>elif pat[<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>if <NUM_LIT:0><=skipblocksuntil<=groupcounter:<EOL><INDENT>groupcounter=groupcounter+<NUM_LIT:1><EOL>return<EOL><DEDENT>gotnextfile=<NUM_LIT:0><EOL>analyzeline(m, pat[<NUM_LIT:1>], line)<EOL>expectbegin=<NUM_LIT:0><EOL><DEDENT>elif pat[<NUM_LIT:1>]=='<STR_LIT>':<EOL><INDENT>pass<EOL><DEDENT>elif pat[<NUM_LIT:1>]=='<STR_LIT>':<EOL><INDENT>if ignorecontains: return<EOL>if <NUM_LIT:0><=skipblocksuntil<=groupcounter: return<EOL>skipblocksuntil=groupcounter<EOL><DEDENT>else:<EOL><INDENT>if <NUM_LIT:0><=skipblocksuntil<=groupcounter:return<EOL>analyzeline(m, pat[<NUM_LIT:1>], line)<EOL><DEDENT>

reset=-1  --- initialize
reset=0   --- crack the line
reset=1   --- final check if mismatch of blocks occured

Cracked data is saved in grouplist[0].


global usermodules, onlyfunctions<EOL>if isinstance(block, list):<EOL><INDENT>gret=[]<EOL>uret=[]<EOL>for g in block:<EOL><INDENT>setmesstext(g)<EOL>g=postcrack(g, tab=tab+'<STR_LIT:\t>')<EOL>if '<STR_LIT:name>' in g and '<STR_LIT>' in g['<STR_LIT:name>']: <EOL><INDENT>uret.append(g)<EOL><DEDENT>else:<EOL><INDENT>gret.append(g)<EOL><DEDENT><DEDENT>return uret+gret<EOL><DEDENT>setmesstext(block)<EOL>if not isinstance(block, dict) and '<STR_LIT>' not in block:<EOL><INDENT>raise Exception('<STR_LIT>' +str(block))<EOL><DEDENT>if '<STR_LIT:name>' in block and not block['<STR_LIT:name>']=='<STR_LIT>':<EOL><INDENT>outmess('<STR_LIT>'%(tab, block['<STR_LIT:name>']), <NUM_LIT:0>)<EOL><DEDENT>blocktype=block['<STR_LIT>']<EOL>block=analyzeargs(block)<EOL>block=analyzecommon(block)<EOL>block['<STR_LIT>']=analyzevars(block)<EOL>block['<STR_LIT>']=sortvarnames(block['<STR_LIT>'])<EOL>if '<STR_LIT:args>' in block and block['<STR_LIT:args>']:<EOL><INDENT>args=block['<STR_LIT:args>']<EOL><DEDENT>block['<STR_LIT:body>']=analyzebody(block, args, tab=tab)<EOL>userisdefined=[]<EOL><INDENT>fromuser = []<EOL><DEDENT>if '<STR_LIT>' in block:<EOL><INDENT>useblock=block['<STR_LIT>']<EOL>for k in list(useblock.keys()):<EOL><INDENT>if '<STR_LIT>' in k:<EOL><INDENT>userisdefined.append(k)<EOL><INDENT>if '<STR_LIT>' in useblock[k]:<EOL><INDENT>for n in useblock[k]['<STR_LIT>'].itervalues():<EOL><INDENT>if n not in fromuser: fromuser.append(n)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else: useblock={}<EOL>name='<STR_LIT>'<EOL>if '<STR_LIT:name>' in block:<EOL><INDENT>name=block['<STR_LIT:name>']<EOL><DEDENT>if '<STR_LIT>' in block and block['<STR_LIT>']:<EOL><INDENT>interfaced=[]<EOL>if '<STR_LIT>' in block:<EOL><INDENT>interfaced=block['<STR_LIT>']<EOL><DEDENT>mvars=copy.copy(block['<STR_LIT>'])<EOL>if name:<EOL><INDENT>mname=name+'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>mname='<STR_LIT>'<EOL><DEDENT>if mname in userisdefined:<EOL><INDENT>i=<NUM_LIT:1><EOL>while '<STR_LIT>'%(mname, i) in userisdefined: i=i+<NUM_LIT:1><EOL>mname='<STR_LIT>'%(mname, i)<EOL><DEDENT>interface={'<STR_LIT>':'<STR_LIT>','<STR_LIT:body>':[],'<STR_LIT>':{},'<STR_LIT:name>':name+'<STR_LIT>'}<EOL>for e in block['<STR_LIT>']:<EOL><INDENT>if e in fromuser:<EOL><INDENT>outmess('<STR_LIT>'%(`e`))<EOL>continue<EOL>

TODO:
      function return values
      determine expression types if in argument list


setmesstext(block)<EOL>ret='<STR_LIT>'<EOL>nout=[]<EOL>for a in args:<EOL><INDENT>if a in block['<STR_LIT>']:<EOL><INDENT>nout.append(a)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in block:<EOL><INDENT>for a in block['<STR_LIT>']:<EOL><INDENT>if a in vars:<EOL><INDENT>if a not in nout:<EOL><INDENT>nout.append(a)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>errmess('<STR_LIT>'%a)<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in block:<EOL><INDENT>nout.extend(block['<STR_LIT>'])<EOL><DEDENT>if not as_interface:<EOL><INDENT>for a in list(vars.keys()):<EOL><INDENT>if a not in nout:<EOL><INDENT>nout.append(a)<EOL><DEDENT><DEDENT><DEDENT>for a in nout:<EOL><INDENT>if '<STR_LIT>' in vars[a]:<EOL><INDENT>for d in vars[a]['<STR_LIT>']:<EOL><INDENT>if d in vars and '<STR_LIT>' in vars[d] and a in vars[d]['<STR_LIT>']:<EOL><INDENT>errmess('<STR_LIT>'%(a, d))<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in block and a in block['<STR_LIT>']:<EOL><INDENT>if isintent_callback(vars[a]):<EOL><INDENT>ret='<STR_LIT>'%(ret, tab, a)<EOL><DEDENT>ret='<STR_LIT>'%(ret, tab, a)<EOL>if isoptional(vars[a]):<EOL><INDENT>ret='<STR_LIT>'%(ret, tab, a)<EOL><DEDENT>if a in vars and '<STR_LIT>' not in vars[a]:<EOL><INDENT>continue<EOL><DEDENT>cont=<NUM_LIT:1><EOL>for b in block['<STR_LIT:body>']:<EOL><INDENT>if a==b['<STR_LIT:name>'] and b['<STR_LIT>']=='<STR_LIT>':<EOL><INDENT>cont=<NUM_LIT:0>;break<EOL><DEDENT><DEDENT>if cont:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if a not in vars:<EOL><INDENT>show(vars)<EOL>outmess('<STR_LIT>'%a)<EOL>continue<EOL><DEDENT>if a==block['<STR_LIT:name>'] and not block['<STR_LIT>']=='<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>if '<STR_LIT>' not in vars[a]:<EOL><INDENT>if '<STR_LIT>' in vars[a] and '<STR_LIT>' in vars[a]['<STR_LIT>']:<EOL><INDENT>if a in args:<EOL><INDENT>ret='<STR_LIT>'%(ret, tab, a)<EOL><DEDENT>continue<EOL><DEDENT>show(vars[a])<EOL>outmess('<STR_LIT>'%a)<EOL>continue<EOL><DEDENT>vardef=vars[a]['<STR_LIT>']<EOL>if vardef=='<STR_LIT:type>' and '<STR_LIT>' in vars[a]:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, vars[a]['<STR_LIT>'])<EOL><DEDENT>selector={}<EOL>if '<STR_LIT>' in vars[a]:<EOL><INDENT>selector=vars[a]['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in vars[a]:<EOL><INDENT>selector=vars[a]['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT:*>' in selector:<EOL><INDENT>if selector['<STR_LIT:*>'] in ['<STR_LIT:*>', '<STR_LIT::>']:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, selector['<STR_LIT:*>'])<EOL><DEDENT>else:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, selector['<STR_LIT:*>'])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if '<STR_LIT>' in selector:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, selector['<STR_LIT>'])<EOL>if '<STR_LIT>' in selector:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, selector['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>vardef='<STR_LIT>'%(vardef)<EOL><DEDENT><DEDENT>elif '<STR_LIT>' in selector:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, selector['<STR_LIT>'])<EOL><DEDENT><DEDENT>c='<STR_LIT:U+0020>'<EOL>if '<STR_LIT>' in vars[a]:<EOL><INDENT>attr=[]<EOL>for l in vars[a]['<STR_LIT>']:<EOL><INDENT>if l not in ['<STR_LIT>']:<EOL><INDENT>attr.append(l)<EOL><DEDENT><DEDENT>if attr:<EOL><INDENT>vardef='<STR_LIT>'%(vardef, '<STR_LIT:U+002C>'.join(attr))<EOL>c='<STR_LIT:U+002C>'<EOL><DEDENT><DEDENT>if '<STR_LIT>' in vars[a]:<EOL><INDENT>if not isintent_c(vars[a]):<EOL><INDENT>vars[a]['<STR_LIT>'].reverse()<EOL>


global f2py_version, options<EOL>outmess('<STR_LIT>'%(m['<STR_LIT:name>']))<EOL>ret = {}<EOL>mod_rules=defmod_rules[:]<EOL>vrd=modsign2map(m)<EOL>rd=dictappend({'<STR_LIT>':f2py_version}, vrd)<EOL>funcwrappers = []<EOL>funcwrappers2 = [] <EOL>for n in m['<STR_LIT>']:<EOL><INDENT>nb=None<EOL>for bi in m['<STR_LIT:body>']:<EOL><INDENT>if not bi['<STR_LIT>']=='<STR_LIT>':<EOL><INDENT>errmess('<STR_LIT>')<EOL>continue<EOL><DEDENT>for b in bi['<STR_LIT:body>']:<EOL><INDENT>if b['<STR_LIT:name>']==n: nb=b;break<EOL><DEDENT><DEDENT>if not nb:<EOL><INDENT>errmess('<STR_LIT>'%(n))<EOL>continue<EOL><DEDENT>nb_list = [nb]<EOL>if '<STR_LIT>' in nb:<EOL><INDENT>for k, a in nb['<STR_LIT>'].items():<EOL><INDENT>nb1 = copy.deepcopy(nb)<EOL>del nb1['<STR_LIT>']<EOL>nb1['<STR_LIT:name>'] = k<EOL>nb1['<STR_LIT:args>'] = a<EOL>nb_list.append(nb1)<EOL><DEDENT><DEDENT>for nb in nb_list:<EOL><INDENT>api, wrap=buildapi(nb)<EOL>if wrap:<EOL><INDENT>if ismoduleroutine(nb):<EOL><INDENT>funcwrappers2.append(wrap)<EOL><DEDENT>else:<EOL><INDENT>funcwrappers.append(wrap)<EOL><DEDENT><DEDENT>ar=applyrules(api, vrd)<EOL>rd=dictappend(rd, ar)<EOL><DEDENT><DEDENT>cr, wrap = common_rules.buildhooks(m)<EOL>if wrap:<EOL><INDENT>funcwrappers.append(wrap)<EOL><DEDENT>ar=applyrules(cr, vrd)<EOL>rd=dictappend(rd, ar)<EOL>mr, wrap = f90mod_rules.buildhooks(m)<EOL>if wrap:<EOL><INDENT>funcwrappers2.append(wrap)<EOL><DEDENT>ar=applyrules(mr, vrd)<EOL>rd=dictappend(rd, ar)<EOL>for u in um:<EOL><INDENT>ar=use_rules.buildusevars(u, m['<STR_LIT>'][u['<STR_LIT:name>']])<EOL>rd=dictappend(rd, ar)<EOL><DEDENT>needs=cfuncs.get_needs()<EOL>code={}<EOL>for n in needs.keys():<EOL><INDENT>code[n]=[]<EOL>for k in needs[n]:<EOL><INDENT>c='<STR_LIT>'<EOL>if k in cfuncs.includes0:<EOL><INDENT>c=cfuncs.includes0[k]<EOL><DEDENT>elif k in cfuncs.includes:<EOL><INDENT>c=cfuncs.includes[k]<EOL><DEDENT>elif k in cfuncs.userincludes:<EOL><INDENT>c=cfuncs.userincludes[k]<EOL><DEDENT>elif k in cfuncs.typedefs:<EOL><INDENT>c=cfuncs.typedefs[k]<EOL><DEDENT>elif k in cfuncs.typedefs_generated:<EOL><INDENT>c=cfuncs.typedefs_generated[k]<EOL><DEDENT>elif k in cfuncs.cppmacros:<EOL><INDENT>c=cfuncs.cppmacros[k]<EOL><DEDENT>elif k in cfuncs.cfuncs:<EOL><INDENT>c=cfuncs.cfuncs[k]<EOL><DEDENT>elif k in cfuncs.callbacks:<EOL><INDENT>c=cfuncs.callbacks[k]<EOL><DEDENT>elif k in cfuncs.f90modhooks:<EOL><INDENT>c=cfuncs.f90modhooks[k]<EOL><DEDENT>elif k in cfuncs.commonhooks:<EOL><INDENT>c=cfuncs.commonhooks[k]<EOL><DEDENT>else:<EOL><INDENT>errmess('<STR_LIT>'%(repr(k)));continue<EOL><DEDENT>code[n].append(c)<EOL><DEDENT><DEDENT>mod_rules.append(code)<EOL>for r in mod_rules:<EOL><INDENT>if ('<STR_LIT>' in r and r['<STR_LIT>'](m)) or ('<STR_LIT>' not in r):<EOL><INDENT>ar=applyrules(r, vrd, m)<EOL>rd=dictappend(rd, ar)<EOL><DEDENT><DEDENT>ar=applyrules(module_rules, rd)<EOL>fn = os.path.join(options['<STR_LIT>'], vrd['<STR_LIT>'])<EOL>ret['<STR_LIT>'] = fn<EOL>f=open(fn, '<STR_LIT:w>')<EOL>f.write(ar['<STR_LIT>'].replace('<STR_LIT:\t>', <NUM_LIT:2>*'<STR_LIT:U+0020>'))<EOL>f.close()<EOL>outmess('<STR_LIT>'%(m['<STR_LIT:name>'], fn))<EOL>if options['<STR_LIT>']:<EOL><INDENT>fn = os.path.join(options['<STR_LIT>'], vrd['<STR_LIT>']+'<STR_LIT>')<EOL>f=open(fn, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT:\n>'.join(ar['<STR_LIT>']))<EOL>f.close()<EOL>outmess('<STR_LIT>'%(options['<STR_LIT>'], vrd['<STR_LIT>']))<EOL><DEDENT>if options['<STR_LIT>']:<EOL><INDENT>fn = os.path.join(options['<STR_LIT>'], vrd['<STR_LIT>']+'<STR_LIT>')<EOL>ret['<STR_LIT>'] = fn<EOL>f=open(fn, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>'%(f2py_version))<EOL>if '<STR_LIT>' not in options:<EOL><INDENT>f.write('<STR_LIT>')<EOL><DEDENT>f.write('<STR_LIT:\n>'.join(ar['<STR_LIT>']))<EOL>if '<STR_LIT>' not in options:<EOL><INDENT>f.write('<STR_LIT>')<EOL><DEDENT>f.close()<EOL>outmess('<STR_LIT>'%(options['<STR_LIT>'], vrd['<STR_LIT>']))<EOL><DEDENT>if funcwrappers:<EOL><INDENT>wn = os.path.join(options['<STR_LIT>'], vrd['<STR_LIT>'])<EOL>ret['<STR_LIT>'] = wn<EOL>f=open(wn, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>'%(f2py_version))<EOL>f.write('<STR_LIT>')<EOL>lines = []<EOL>for l in ('<STR_LIT>'.join(funcwrappers)+'<STR_LIT:\n>').split('<STR_LIT:\n>'):<EOL><INDENT>if l and l[<NUM_LIT:0>]=='<STR_LIT:U+0020>':<EOL><INDENT>while len(l)>=<NUM_LIT>:<EOL><INDENT>lines.append(l[:<NUM_LIT>]+'<STR_LIT>')<EOL>l = l[<NUM_LIT>:]<EOL><DEDENT>lines.append(l+'<STR_LIT:\n>')<EOL><DEDENT>else: lines.append(l+'<STR_LIT:\n>')<EOL><DEDENT>lines = '<STR_LIT>'.join(lines).replace('<STR_LIT>', '<STR_LIT:\n>')<EOL>f.write(lines)<EOL>f.close()<EOL>outmess('<STR_LIT>'%(wn))<EOL><DEDENT>if funcwrappers2:<EOL><INDENT>wn = os.path.join(options['<STR_LIT>'], '<STR_LIT>'%(vrd['<STR_LIT>']))<EOL>ret['<STR_LIT>'] = wn<EOL>f=open(wn, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>'%(f2py_version))<EOL>f.write('<STR_LIT>')<EOL>lines = []<EOL>for l in ('<STR_LIT>'.join(funcwrappers2)+'<STR_LIT:\n>').split('<STR_LIT:\n>'):<EOL><INDENT>if len(l)><NUM_LIT> and l[<NUM_LIT:0>]=='<STR_LIT:U+0020>':<EOL><INDENT>lines.append(l[:<NUM_LIT>]+'<STR_LIT>')<EOL>l = l[<NUM_LIT>:]<EOL>while len(l)><NUM_LIT>:<EOL><INDENT>lines.append(l[:<NUM_LIT>]+'<STR_LIT>')<EOL>l = l[<NUM_LIT>:]<EOL><DEDENT>lines.append(l+'<STR_LIT:\n>')<EOL><DEDENT>else: lines.append(l+'<STR_LIT:\n>')<EOL><DEDENT>lines = '<STR_LIT>'.join(lines).replace('<STR_LIT>', '<STR_LIT:\n>')<EOL>f.write(lines)<EOL>f.close()<EOL>outmess('<STR_LIT>'%(wn))<EOL><DEDENT>return ret<EOL>


ctype='<STR_LIT>'<EOL>if isfunction(var):<EOL><INDENT>if '<STR_LIT:result>' in var:<EOL><INDENT>a=var['<STR_LIT:result>']<EOL><DEDENT>else:<EOL><INDENT>a=var['<STR_LIT:name>']<EOL><DEDENT>if a in var['<STR_LIT>']:<EOL><INDENT>return getctype(var['<STR_LIT>'][a])<EOL><DEDENT>else:<EOL><INDENT>errmess('<STR_LIT>'%a)<EOL><DEDENT><DEDENT>elif issubroutine(var):<EOL><INDENT>return ctype<EOL><DEDENT>elif '<STR_LIT>' in var and var['<STR_LIT>'].lower() in f2cmap_all:<EOL><INDENT>typespec = var['<STR_LIT>'].lower()<EOL>f2cmap=f2cmap_all[typespec]<EOL>ctype=f2cmap['<STR_LIT>'] <EOL>if '<STR_LIT>' in var:<EOL><INDENT>if '<STR_LIT:*>' in var['<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>ctype=f2cmap[var['<STR_LIT>']['<STR_LIT:*>']]<EOL><DEDENT>except KeyError:<EOL><INDENT>errmess('<STR_LIT>'%(var['<STR_LIT>'], '<STR_LIT:*>', var['<STR_LIT>']['<STR_LIT:*>']))<EOL><DEDENT><DEDENT>elif '<STR_LIT>' in var['<STR_LIT>']:<EOL><INDENT>if typespec+'<STR_LIT>' in f2cmap_all:<EOL><INDENT>f2cmap=f2cmap_all[typespec+'<STR_LIT>']<EOL><DEDENT>try:<EOL><INDENT>ctype=f2cmap[var['<STR_LIT>']['<STR_LIT>']]<EOL><DEDENT>except KeyError:<EOL><INDENT>if typespec in f2cmap_all:<EOL><INDENT>f2cmap=f2cmap_all[typespec]<EOL><DEDENT>try:<EOL><INDENT>ctype=f2cmap[str(var['<STR_LIT>']['<STR_LIT>'])]<EOL><DEDENT>except KeyError:<EOL><INDENT>errmess('<STR_LIT>'%(typespec, var['<STR_LIT>']['<STR_LIT>'], ctype,<EOL>typespec, var['<STR_LIT>']['<STR_LIT>'], os.getcwd()))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if not isexternal(var):<EOL><INDENT>errmess('<STR_LIT>'%var)<EOL><DEDENT><DEDENT>return ctype<EOL>


global lcb_map, cb_map<EOL>out_a = a<EOL>if isintent_out(var):<EOL><INDENT>for k in var['<STR_LIT>']:<EOL><INDENT>if k[:<NUM_LIT:4>]=='<STR_LIT>':<EOL><INDENT>out_a = k[<NUM_LIT:4>:]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>ret={'<STR_LIT>':a,'<STR_LIT>':out_a}<EOL>ret['<STR_LIT>']=getctype(var)<EOL>intent_flags = []<EOL>for f, s in isintent_dict.items():<EOL><INDENT>if f(var): intent_flags.append('<STR_LIT>'%s)<EOL><DEDENT>if intent_flags:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT:|>'.join(intent_flags)<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if isarray(var): ret['<STR_LIT>']='<STR_LIT:N>'<EOL>elif ret['<STR_LIT>'] in c2buildvalue_map:<EOL><INDENT>ret['<STR_LIT>']=c2buildvalue_map[ret['<STR_LIT>']]<EOL><DEDENT>else: ret['<STR_LIT>']='<STR_LIT:O>'<EOL>ret['<STR_LIT>'], ret['<STR_LIT>']=getinit(a, var)<EOL>if hasinitvalue(var) and iscomplex(var) and not isarray(var):<EOL><INDENT>ret['<STR_LIT>'], ret['<STR_LIT>'] = markoutercomma(ret['<STR_LIT>'][<NUM_LIT:1>:-<NUM_LIT:1>]).split('<STR_LIT>')<EOL><DEDENT>if isexternal(var):<EOL><INDENT>ret['<STR_LIT>']=a<EOL>if a in lcb_map:<EOL><INDENT>ret['<STR_LIT>']=lcb_map[a]<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL>ret['<STR_LIT>']=lcb2_map[lcb_map[a]]['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>']=a<EOL>errmess('<STR_LIT>'%(a, list(lcb_map.keys())))<EOL><DEDENT><DEDENT>if isstring(var):<EOL><INDENT>ret['<STR_LIT>']=getstrlength(var)<EOL><DEDENT>if isarray(var):<EOL><INDENT>ret=dictappend(ret, getarrdims(a, var))<EOL>dim=copy.copy(var['<STR_LIT>'])<EOL><DEDENT>if ret['<STR_LIT>'] in c2capi_map:<EOL><INDENT>ret['<STR_LIT>']=c2capi_map[ret['<STR_LIT>']]<EOL><DEDENT>if debugcapi(var):<EOL><INDENT>il=[isintent_in, '<STR_LIT:input>', isintent_out, '<STR_LIT>',<EOL>isintent_inout, '<STR_LIT>', isrequired, '<STR_LIT>',<EOL>isoptional, '<STR_LIT>', isintent_hide, '<STR_LIT>',<EOL>iscomplex, '<STR_LIT>',<EOL>l_and(isscalar, l_not(iscomplex)), '<STR_LIT>',<EOL>isstring, '<STR_LIT:string>', isarray, '<STR_LIT>',<EOL>iscomplexarray, '<STR_LIT>', isstringarray, '<STR_LIT>',<EOL>iscomplexfunction, '<STR_LIT>',<EOL>l_and(isfunction, l_not(iscomplexfunction)), '<STR_LIT>',<EOL>isexternal, '<STR_LIT>',<EOL>isintent_callback, '<STR_LIT>',<EOL>isintent_aux, '<STR_LIT>',<EOL>]<EOL>rl=[]<EOL>for i in range(<NUM_LIT:0>, len(il), <NUM_LIT:2>):<EOL><INDENT>if il[i](var): rl.append(il[i+<NUM_LIT:1>])<EOL><DEDENT>if isstring(var):<EOL><INDENT>rl.append('<STR_LIT>'%(a, ret['<STR_LIT>']))<EOL><DEDENT>if isarray(var):<EOL><INDENT>if not isintent_c(var):<EOL><INDENT>var['<STR_LIT>'].reverse()<EOL>

varname,ctype,atype
init,init.r,init.i,pytype
vardebuginfo,vardebugshowvalue,varshowvalue
varrfromat
intent


global lcb_map<EOL>name = rout['<STR_LIT:name>']<EOL>fname = getfortranname(rout)<EOL>ret={'<STR_LIT:name>': name,<EOL>'<STR_LIT>': name.replace('<STR_LIT:_>', '<STR_LIT>'),<EOL>'<STR_LIT>': name.lower(),<EOL>'<STR_LIT>': name.upper(),<EOL>'<STR_LIT>': gentitle(name),<EOL>'<STR_LIT>': gentitle('<STR_LIT>'%name),<EOL>'<STR_LIT>': fname,<EOL>'<STR_LIT>': fname.upper(),<EOL>'<STR_LIT>': getcallstatement(rout) or '<STR_LIT>',<EOL>'<STR_LIT>': getusercode(rout) or '<STR_LIT>',<EOL>'<STR_LIT>': getusercode1(rout) or '<STR_LIT>',<EOL>}<EOL>if '<STR_LIT:_>' in fname:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if '<STR_LIT:_>' in name:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>lcb_map={}<EOL>if '<STR_LIT>' in rout:<EOL><INDENT>for u in rout['<STR_LIT>'].keys():<EOL><INDENT>if u in cb_rules.cb_map:<EOL><INDENT>for un in cb_rules.cb_map[u]:<EOL><INDENT>ln=un[<NUM_LIT:0>]<EOL>if '<STR_LIT>' in rout['<STR_LIT>'][u]:<EOL><INDENT>for k in rout['<STR_LIT>'][u]['<STR_LIT>'].keys():<EOL><INDENT>if rout['<STR_LIT>'][u]['<STR_LIT>'][k]==un[<NUM_LIT:0>]: ln=k;break<EOL><DEDENT><DEDENT>lcb_map[ln]=un[<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif '<STR_LIT>' in rout and rout['<STR_LIT>']:<EOL><INDENT>errmess('<STR_LIT>'%(ret['<STR_LIT:name>'], repr(rout['<STR_LIT>'])))<EOL><DEDENT>ret['<STR_LIT>'] = getcallprotoargument(rout, lcb_map) or '<STR_LIT>'<EOL>if isfunction(rout):<EOL><INDENT>if '<STR_LIT:result>' in rout:<EOL><INDENT>a=rout['<STR_LIT:result>']<EOL><DEDENT>else:<EOL><INDENT>a=rout['<STR_LIT:name>']<EOL><DEDENT>ret['<STR_LIT>']=a<EOL>ret['<STR_LIT>'], ret['<STR_LIT>']=getpydocsign(a, rout)<EOL>ret['<STR_LIT>']=getctype(rout['<STR_LIT>'][a])<EOL>if hasresultnote(rout):<EOL><INDENT>ret['<STR_LIT>']=rout['<STR_LIT>'][a]['<STR_LIT>']<EOL>rout['<STR_LIT>'][a]['<STR_LIT>']=['<STR_LIT>']<EOL><DEDENT>if ret['<STR_LIT>'] in c2buildvalue_map:<EOL><INDENT>ret['<STR_LIT>']=c2buildvalue_map[ret['<STR_LIT>']]<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>']='<STR_LIT:O>'<EOL>errmess('<STR_LIT>'%(repr(ret['<STR_LIT>'])))<EOL><DEDENT>if debugcapi(rout):<EOL><INDENT>if ret['<STR_LIT>'] in cformat_map:<EOL><INDENT>ret['<STR_LIT>']='<STR_LIT>'%(a, cformat_map[ret['<STR_LIT>']])<EOL><DEDENT>if isstringfunction(rout):<EOL><INDENT>ret['<STR_LIT>']='<STR_LIT>'%(a, a)<EOL><DEDENT><DEDENT>if isstringfunction(rout):<EOL><INDENT>ret['<STR_LIT>']=getstrlength(rout['<STR_LIT>'][a])<EOL>if ret['<STR_LIT>']=='<STR_LIT>':<EOL><INDENT>errmess('<STR_LIT>'%(repr(rout['<STR_LIT:name>'])))<EOL>ret['<STR_LIT>']='<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>if hasnote(rout):<EOL><INDENT>ret['<STR_LIT>']=rout['<STR_LIT>']<EOL>rout['<STR_LIT>']=['<STR_LIT>']<EOL><DEDENT>return ret<EOL>


if ismodule(m):<EOL><INDENT>ret={'<STR_LIT>':m['<STR_LIT:name>'],<EOL>'<STR_LIT>':m['<STR_LIT:name>'].upper(),<EOL>'<STR_LIT>':m['<STR_LIT:name>'].replace('<STR_LIT:_>', '<STR_LIT>')}<EOL><DEDENT>else:<EOL><INDENT>ret={'<STR_LIT>':m['<STR_LIT:name>'],<EOL>'<STR_LIT>':m['<STR_LIT:name>'].upper(),<EOL>'<STR_LIT>':m['<STR_LIT:name>'].replace('<STR_LIT:_>', '<STR_LIT>')}<EOL><DEDENT>ret['<STR_LIT>'] = getrestdoc(m) or []<EOL>if hasnote(m):<EOL><INDENT>ret['<STR_LIT>']=m['<STR_LIT>']<EOL><DEDENT>ret['<STR_LIT>'] = getusercode(m) or '<STR_LIT>'<EOL>ret['<STR_LIT>'] = getusercode1(m) or '<STR_LIT>'<EOL>if m['<STR_LIT:body>']:<EOL><INDENT>ret['<STR_LIT>'] = getusercode(m['<STR_LIT:body>'][<NUM_LIT:0>]) or '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>ret['<STR_LIT>'] = getpymethoddef(m) or '<STR_LIT>'<EOL>if '<STR_LIT>' in m:<EOL><INDENT>ret['<STR_LIT>'] = m['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in m:<EOL><INDENT>ret['<STR_LIT>'] = m['<STR_LIT>']<EOL><DEDENT>return ret<EOL>


ret={'<STR_LIT:name>':'<STR_LIT>'%(rout['<STR_LIT:name>'], um),<EOL>'<STR_LIT>':'<STR_LIT>'}<EOL>if isintent_callback(rout):<EOL><INDENT>if '<STR_LIT:_>' in rout['<STR_LIT:name>']:<EOL><INDENT>F_FUNC='<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>F_FUNC='<STR_LIT>'<EOL><DEDENT>ret['<STR_LIT>'] = '<STR_LIT>'% (F_FUNC,<EOL>rout['<STR_LIT:name>'].lower(),<EOL>rout['<STR_LIT:name>'].upper(),<EOL>)<EOL>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>ret['<STR_LIT>'] = ret['<STR_LIT:name>']<EOL>ret['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>ret['<STR_LIT>']=rout['<STR_LIT:name>']<EOL>ret['<STR_LIT>']=gentitle(ret['<STR_LIT:name>'])<EOL>ret['<STR_LIT>']=gentitle('<STR_LIT>'%ret['<STR_LIT:name>'])<EOL>ret['<STR_LIT>']=getctype(rout)<EOL>ret['<STR_LIT>']='<STR_LIT>'<EOL>if ret['<STR_LIT>']=='<STR_LIT:string>': ret['<STR_LIT>']='<STR_LIT>'<EOL>else:<EOL><INDENT>ret['<STR_LIT>']=ret['<STR_LIT>']<EOL><DEDENT>if ret['<STR_LIT>']!='<STR_LIT>':<EOL><INDENT>if iscomplexfunction(rout):<EOL><INDENT>ret['<STR_LIT>'] = """<STR_LIT>"""<EOL><DEDENT><DEDENT>ef F2PY_CB_RETURNCOMPLEX<EOL>pe<EOL>e<EOL>if<EOL>else:<EOL><INDENT>if hasnote(rout):<EOL><INDENT>ret['<STR_LIT>']=rout['<STR_LIT>']<EOL>rout['<STR_LIT>']=['<STR_LIT>']<EOL><DEDENT><DEDENT>nofargs=<NUM_LIT:0><EOL>nofoptargs=<NUM_LIT:0><EOL>if '<STR_LIT:args>' in rout and '<STR_LIT>' in rout:<EOL><INDENT>for a in rout['<STR_LIT:args>']:<EOL><INDENT>var=rout['<STR_LIT>'][a]<EOL>if l_or(isintent_in, isintent_inout)(var):<EOL><INDENT>nofargs=nofargs+<NUM_LIT:1><EOL>if isoptional(var):<EOL><INDENT>nofoptargs=nofoptargs+<NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>ret['<STR_LIT>']=repr(nofargs)<EOL>ret['<STR_LIT>']=repr(nofoptargs)<EOL>if hasnote(rout) and isfunction(rout) and '<STR_LIT:result>' in rout:<EOL><INDENT>ret['<STR_LIT>']=rout['<STR_LIT>']<EOL>rout['<STR_LIT>']=['<STR_LIT>']<EOL><DEDENT>return ret<EOL>


def compile(source,<EOL>modulename = '<STR_LIT>',<EOL>extra_args = '<STR_LIT>',<EOL>verbose = <NUM_LIT:1>,<EOL>source_fn = None<EOL>):

from numpy.distutils.exec_command import exec_command<EOL>import tempfile<EOL>if source_fn is None:<EOL><INDENT>f = tempfile.NamedTemporaryFile(suffix='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>f = open(source_fn, '<STR_LIT:w>')<EOL><DEDENT>try:<EOL><INDENT>f.write(source)<EOL>f.flush()<EOL>args = '<STR_LIT>'%(modulename, f.name, extra_args)<EOL>c = '<STR_LIT>' %(sys.executable, args)<EOL>s, o = exec_command(c)<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL><DEDENT>return s<EOL>

Build extension module from processing source with f2py.
    Read the source of this function for more information.


return double<EOL>

Cast the type t to either double or cdouble.


a, wrap = _makearray(a)<EOL>b = asarray(b)<EOL>an = a.ndim<EOL>if axes is not None:<EOL><INDENT>allaxes = list(range(<NUM_LIT:0>, an))<EOL>for k in axes:<EOL><INDENT>allaxes.remove(k)<EOL>allaxes.insert(an, k)<EOL><DEDENT>a = a.transpose(allaxes)<EOL><DEDENT>oldshape = a.shape[-(an-b.ndim):]<EOL>prod = <NUM_LIT:1><EOL>for k in oldshape:<EOL><INDENT>prod *= k<EOL><DEDENT>a = a.reshape(-<NUM_LIT:1>, prod)<EOL>b = b.ravel()<EOL>res = wrap(solve(a, b))<EOL>res.shape = oldshape<EOL>return res<EOL>

Solve the tensor equation ``a x = b`` for x.

It is assumed that all indices of `x` are summed over in the product,
together with the rightmost indices of `a`, as is done in, for example,
``tensordot(a, x, axes=len(b.shape))``.

Parameters
----------
a : array_like
    Coefficient tensor, of shape ``b.shape + Q``. `Q`, a tuple, equals
    the shape of that sub-tensor of `a` consisting of the appropriate
    number of its rightmost indices, and must be such that
   ``prod(Q) == prod(b.shape)`` (in which sense `a` is said to be
   'square').
b : array_like
    Right-hand tensor, which can be of any shape.
axes : tuple of ints, optional
    Axes in `a` to reorder to the right, before inversion.
    If None (default), no reordering is done.

Returns
-------
x : ndarray, shape Q

Raises
------
LinAlgError
    If `a` is singular or not 'square' (in the above sense).

See Also
--------
tensordot, tensorinv, einsum

Examples
--------
>>> a = np.eye(2*3*4)
>>> a.shape = (2*3, 4, 2, 3, 4)
>>> b = np.random.randn(2*3, 4)
>>> x = np.linalg.tensorsolve(a, b)
>>> x.shape
(2, 3, 4)
>>> np.allclose(np.tensordot(a, x, axes=3), b)
True


a, _ = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>b, wrap = _makearray(b)<EOL>t, result_t = _commonType(a, b)<EOL>if b.ndim == a.ndim - <NUM_LIT:1>:<EOL><INDENT>if a.shape[-<NUM_LIT:1>] == <NUM_LIT:0> and b.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>a = a.reshape(a.shape[:-<NUM_LIT:1>])<EOL>bc = broadcast(a, b)<EOL>return wrap(empty(bc.shape, dtype=result_t))<EOL><DEDENT>gufunc = _umath_linalg.solve1<EOL><DEDENT>else:<EOL><INDENT>if b.size == <NUM_LIT:0>:<EOL><INDENT>if (a.shape[-<NUM_LIT:1>] == <NUM_LIT:0> and b.shape[-<NUM_LIT:2>] == <NUM_LIT:0>) or b.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>a = a[:,:<NUM_LIT:1>].reshape(a.shape[:-<NUM_LIT:1>] + (<NUM_LIT:1>,))<EOL>bc = broadcast(a, b)<EOL>return wrap(empty(bc.shape, dtype=result_t))<EOL><DEDENT><DEDENT>gufunc = _umath_linalg.solve<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>extobj = get_linalg_error_extobj(_raise_linalgerror_singular)<EOL>r = gufunc(a, b, signature=signature, extobj=extobj)<EOL>return wrap(r.astype(result_t))<EOL>

Solve a linear matrix equation, or system of linear scalar equations.

Computes the "exact" solution, `x`, of the well-determined, i.e., full
rank, linear matrix equation `ax = b`.

Parameters
----------
a : (..., M, M) array_like
    Coefficient matrix.
b : {(..., M,), (..., M, K)}, array_like
    Ordinate or "dependent variable" values.

Returns
-------
x : {(..., M,), (..., M, K)} ndarray
    Solution to the system a x = b.  Returned shape is identical to `b`.

Raises
------
LinAlgError
    If `a` is singular or not square.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

The solutions are computed using LAPACK routine _gesv

`a` must be square and of full-rank, i.e., all rows (or, equivalently,
columns) must be linearly independent; if either is not true, use
`lstsq` for the least-squares best "solution" of the
system/equation.

References
----------
.. [1] G. Strang, *Linear Algebra and Its Applications*, 2nd Ed., Orlando,
       FL, Academic Press, Inc., 1980, pg. 22.

Examples
--------
Solve the system of equations ``3 * x0 + x1 = 9`` and ``x0 + 2 * x1 = 8``:

>>> a = np.array([[3,1], [1,2]])
>>> b = np.array([9,8])
>>> x = np.linalg.solve(a, b)
>>> x
array([ 2.,  3.])

Check that the solution is correct:

>>> np.allclose(np.dot(a, x), b)
True


a = asarray(a)<EOL>oldshape = a.shape<EOL>prod = <NUM_LIT:1><EOL>if ind > <NUM_LIT:0>:<EOL><INDENT>invshape = oldshape[ind:] + oldshape[:ind]<EOL>for k in oldshape[ind:]:<EOL><INDENT>prod *= k<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>a = a.reshape(prod, -<NUM_LIT:1>)<EOL>ia = inv(a)<EOL>return ia.reshape(*invshape)<EOL>

Compute the 'inverse' of an N-dimensional array.

The result is an inverse for `a` relative to the tensordot operation
``tensordot(a, b, ind)``, i. e., up to floating-point accuracy,
``tensordot(tensorinv(a), a, ind)`` is the "identity" tensor for the
tensordot operation.

Parameters
----------
a : array_like
    Tensor to 'invert'. Its shape must be 'square', i. e.,
    ``prod(a.shape[:ind]) == prod(a.shape[ind:])``.
ind : int, optional
    Number of first indices that are involved in the inverse sum.
    Must be a positive integer, default is 2.

Returns
-------
b : ndarray
    `a`'s tensordot inverse, shape ``a.shape[ind:] + a.shape[:ind]``.

Raises
------
LinAlgError
    If `a` is singular or not 'square' (in the above sense).

See Also
--------
tensordot, tensorsolve

Examples
--------
>>> a = np.eye(4*6)
>>> a.shape = (4, 6, 8, 3)
>>> ainv = np.linalg.tensorinv(a, ind=2)
>>> ainv.shape
(8, 3, 4, 6)
>>> b = np.random.randn(4, 6)
>>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))
True

>>> a = np.eye(4*6)
>>> a.shape = (24, 8, 3)
>>> ainv = np.linalg.tensorinv(a, ind=1)
>>> ainv.shape
(8, 3, 24)
>>> b = np.random.randn(24)
>>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))
True


a, wrap = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>if a.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>return wrap(empty_like(a, dtype=result_t))<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>extobj = get_linalg_error_extobj(_raise_linalgerror_singular)<EOL>ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)<EOL>return wrap(ainv.astype(result_t))<EOL>

Compute the (multiplicative) inverse of a matrix.

Given a square matrix `a`, return the matrix `ainv` satisfying
``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``.

Parameters
----------
a : (..., M, M) array_like
    Matrix to be inverted.

Returns
-------
ainv : (..., M, M) ndarray or matrix
    (Multiplicative) inverse of the matrix `a`.

Raises
------
LinAlgError
    If `a` is not square or inversion fails.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

Examples
--------
>>> from numpy.linalg import inv
>>> a = np.array([[1., 2.], [3., 4.]])
>>> ainv = inv(a)
>>> np.allclose(np.dot(a, ainv), np.eye(2))
True
>>> np.allclose(np.dot(ainv, a), np.eye(2))
True

If a is a matrix object, then the return value is a matrix as well:

>>> ainv = inv(np.matrix(a))
>>> ainv
matrix([[-2. ,  1. ],
        [ 1.5, -0.5]])

Inverses of several matrices can be computed at once:

>>> a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
>>> inv(a)
array([[[-2. ,  1. ],
        [ 1.5, -0.5]],
       [[-5. ,  2. ],
        [ 3. , -1. ]]])


extobj = get_linalg_error_extobj(_raise_linalgerror_nonposdef)<EOL>gufunc = _umath_linalg.cholesky_lo<EOL>a, wrap = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>return wrap(gufunc(a, signature=signature, extobj=extobj).astype(result_t))<EOL>

Cholesky decomposition.

Return the Cholesky decomposition, `L * L.H`, of the square matrix `a`,
where `L` is lower-triangular and .H is the conjugate transpose operator
(which is the ordinary transpose if `a` is real-valued).  `a` must be
Hermitian (symmetric if real-valued) and positive-definite.  Only `L` is
actually returned.

Parameters
----------
a : (..., M, M) array_like
    Hermitian (symmetric if all elements are real), positive-definite
    input matrix.

Returns
-------
L : (..., M, M) array_like
    Upper or lower-triangular Cholesky factor of `a`.  Returns a
    matrix object if `a` is a matrix object.

Raises
------
LinAlgError
   If the decomposition fails, for example, if `a` is not
   positive-definite.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

The Cholesky decomposition is often used as a fast way of solving

.. math:: A \\mathbf{x} = \\mathbf{b}

(when `A` is both Hermitian/symmetric and positive-definite).

First, we solve for :math:`\\mathbf{y}` in

.. math:: L \\mathbf{y} = \\mathbf{b},

and then for :math:`\\mathbf{x}` in

.. math:: L.H \\mathbf{x} = \\mathbf{y}.

Examples
--------
>>> A = np.array([[1,-2j],[2j,5]])
>>> A
array([[ 1.+0.j,  0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> L = np.linalg.cholesky(A)
>>> L
array([[ 1.+0.j,  0.+0.j],
       [ 0.+2.j,  1.+0.j]])
>>> np.dot(L, L.T.conj()) # verify that L * L.H = A
array([[ 1.+0.j,  0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> A = [[1,-2j],[2j,5]] # what happens if A is only array_like?
>>> np.linalg.cholesky(A) # an ndarray object is returned
array([[ 1.+0.j,  0.+0.j],
       [ 0.+2.j,  1.+0.j]])
>>> # But a matrix object is returned if A is a matrix object
>>> LA.cholesky(np.matrix(A))
matrix([[ 1.+0.j,  0.+0.j],
        [ 0.+2.j,  1.+0.j]])