Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: stats, interpolate: Fix some minor docstring issues. #18000

Merged
merged 1 commit into from Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 35 additions & 30 deletions scipy/interpolate/_bsplines.py
Expand Up @@ -236,7 +236,7 @@ def __init__(self, t, c, k, extrapolate=True, axis=0):
raise ValueError("Knot vector must be one-dimensional.")
if n < self.k + 1:
raise ValueError("Need at least %d knots for degree %d" %
(2*k + 2, k))
(2*k + 2, k))
if (np.diff(self.t) < 0).any():
raise ValueError("Knots must be in a non-decreasing order.")
if len(np.unique(self.t[k:n+1])) < 2:
Expand Down Expand Up @@ -510,7 +510,7 @@ def __call__(self, x, nu=0, extrapolate=None):

def _evaluate(self, xp, nu, extrapolate, out):
_bspl.evaluate_spline(self.t, self.c.reshape(self.c.shape[0], -1),
self.k, xp, nu, extrapolate, out)
self.k, xp, nu, extrapolate, out)

def _ensure_c_contiguous(self):
"""
Expand Down Expand Up @@ -549,7 +549,7 @@ def derivative(self, nu=1):
c = np.r_[c, np.zeros((ct,) + c.shape[1:])]
tck = _fitpack_impl.splder((self.t, c, self.k), nu)
return self.construct_fast(*tck, extrapolate=self.extrapolate,
axis=self.axis)
axis=self.axis)

def antiderivative(self, nu=1):
"""Return a B-spline representing the antiderivative.
Expand Down Expand Up @@ -876,6 +876,7 @@ def _process_deriv_spec(deriv):
ords, vals = [], []
return np.atleast_1d(ords, vals)


def _woodbury_algorithm(A, ur, ll, b, k):
'''
Solve a cyclic banded linear system with upper right
Expand All @@ -885,7 +886,7 @@ def _woodbury_algorithm(A, ur, ll, b, k):
Parameters
----------
A : 2-D array, shape(k, n)
Matrix of diagonals of original matrix(see
Matrix of diagonals of original matrix (see
``solve_banded`` documentation).
ur : 2-D array, shape(bs, bs)
Upper right block matrix.
Expand Down Expand Up @@ -944,11 +945,11 @@ def _woodbury_algorithm(A, ur, ll, b, k):
U = np.zeros((n - 1, k_mod))
VT = np.zeros((k_mod, n - 1)) # V transpose

# upper right block
# upper right block
U[:bs, :bs] = ur
VT[np.arange(bs), np.arange(bs) - bs] = 1

# lower left block
# lower left block
U[-bs:, -bs:] = ll
VT[np.arange(bs) - bs, np.arange(bs)] = 1

Expand All @@ -961,6 +962,7 @@ def _woodbury_algorithm(A, ur, ll, b, k):

return c


def _periodic_knots(x, k):
'''
returns vector of nodes on circle
Expand All @@ -969,7 +971,7 @@ def _periodic_knots(x, k):
n = len(xc)
if k % 2 == 0:
dx = np.diff(xc)
xc[1: -1] -= dx[:-1] / 2
xc[1: -1] -= dx[:-1] / 2
dx = np.diff(xc)
t = np.zeros(n + 2 * k)
t[k: -k] = xc
Expand Down Expand Up @@ -1043,6 +1045,7 @@ def _make_interp_per_full_matr(x, y, t, k):
c = solve(matr, b)
return c


def _make_periodic_spline(x, y, t, k, axis):
'''
Compute the (coefficients of) interpolating B-spline with periodic
Expand Down Expand Up @@ -1131,6 +1134,7 @@ def _make_periodic_spline(x, y, t, k, axis):
c = np.ascontiguousarray(c.reshape((n + k - 1,) + y.shape[1:]))
return BSpline.construct_fast(t, c, k, extrapolate='periodic', axis=axis)


def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
check_finite=True):
"""Compute the (coefficients of) interpolating B-spline.
Expand Down Expand Up @@ -1180,6 +1184,14 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
-------
b : a BSpline object of the degree ``k`` and with knots ``t``.

See Also
--------
BSpline : base class representing the B-spline objects
CubicSpline : a cubic spline in the polynomial basis
make_lsq_spline : a similar factory function for spline fitting
UnivariateSpline : a wrapper over FITPACK spline fitting routines
splrep : a wrapper over FITPACK spline fitting routines

Examples
--------

Expand Down Expand Up @@ -1253,14 +1265,6 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
>>> ax.scatter3D(x, *y, color='red')
>>> plt.show()

See Also
--------
BSpline : base class representing the B-spline objects
CubicSpline : a cubic spline in the polynomial basis
make_lsq_spline : a similar factory function for spline fitting
UnivariateSpline : a wrapper over FITPACK spline fitting routines
splrep : a wrapper over FITPACK spline fitting routines

"""
# convert string aliases for the boundary conditions
if bc_type is None or bc_type == 'not-a-knot' or bc_type == 'periodic':
Expand Down Expand Up @@ -1317,7 +1321,8 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,

if bc_type == 'periodic' and t is not None:
raise NotImplementedError("For periodic case t is constructed "
"automatically and can not be passed manually")
"automatically and can not be passed "
"manually")

# come up with a sensible knot vector, if needed
if t is None:
Expand All @@ -1329,8 +1334,8 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
# 2nd and 2nd-to-last points, a la not-a-knot
t = (x[1:] + x[:-1]) / 2.
t = np.r_[(x[0],)*(k+1),
t[1:-1],
(x[-1],)*(k+1)]
t[1:-1],
(x[-1],)*(k+1)]
else:
t = _not_a_knot(x, k)
else:
Expand Down Expand Up @@ -1381,7 +1386,7 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
_bspl._handle_lhs_derivatives(t, k, x[0], ab, kl, ku, deriv_l_ords)
if nright > 0:
_bspl._handle_lhs_derivatives(t, k, x[-1], ab, kl, ku, deriv_r_ords,
offset=nt-nright)
offset=nt-nright)

# set up the RHS: values to interpolate (+ derivative values, if any)
extradim = prod(y.shape[1:])
Expand All @@ -1397,7 +1402,7 @@ def make_interp_spline(x, y, k=3, t=None, bc_type=None, axis=0,
ab, rhs = map(np.asarray_chkfinite, (ab, rhs))
gbsv, = get_lapack_funcs(('gbsv',), (ab, rhs))
lu, piv, c, info = gbsv(kl, ku, ab, rhs,
overwrite_ab=True, overwrite_b=True)
overwrite_ab=True, overwrite_b=True)

if info > 0:
raise LinAlgError("Collocation matrix is singular.")
Expand Down Expand Up @@ -1451,6 +1456,13 @@ def make_lsq_spline(x, y, t, k=3, w=None, axis=0, check_finite=True):
-------
b : a BSpline object of the degree ``k`` with knots ``t``.

See Also
--------
BSpline : base class representing the B-spline objects
make_interp_spline : a similar factory function for interpolating splines
LSQUnivariateSpline : a FITPACK-based spline fitting routine
splrep : a FITPACK-based fitting routine

Notes
-----
The number of data points must be larger than the spline degree ``k``.
Expand Down Expand Up @@ -1507,13 +1519,6 @@ def make_lsq_spline(x, y, t, k=3, w=None, axis=0, check_finite=True):
Notice the need to replace a ``nan`` by a numerical value (precise value
does not matter as long as the corresponding weight is zero.)

See Also
--------
BSpline : base class representing the B-spline objects
make_interp_spline : a similar factory function for interpolating splines
LSQUnivariateSpline : a FITPACK-based spline fitting routine
splrep : a FITPACK-based fitting routine

"""
x = _as_float_array(x, check_finite)
y = _as_float_array(y, check_finite)
Expand Down Expand Up @@ -1555,9 +1560,9 @@ def make_lsq_spline(x, y, t, k=3, w=None, axis=0, check_finite=True):
ab = np.zeros((k+1, n), dtype=np.float_, order='F')
rhs = np.zeros((n, extradim), dtype=y.dtype, order='F')
_bspl._norm_eq_lsq(x, t, k,
y.reshape(-1, extradim),
w,
ab, rhs)
y.reshape(-1, extradim),
w,
ab, rhs)
rhs = rhs.reshape((n,) + y.shape[1:])

# have observation matrix & rhs, can solve the LSQ problem
Expand Down
11 changes: 5 additions & 6 deletions scipy/interpolate/_cubic.py
Expand Up @@ -227,7 +227,6 @@ class PchipInterpolator(CubicHermiteSpline):
.. [2] see, e.g., C. Moler, Numerical Computing with Matlab, 2004.
:doi:`10.1137/1.9780898717952`


"""

def __init__(self, x, y, axis=0, extrapolate=None):
Expand Down Expand Up @@ -328,14 +327,14 @@ def pchip_interpolate(xi, yi, x, der=0, axis=0):
axis : int, optional
Axis in the yi array corresponding to the x-coordinate values.

See Also
--------
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.

Returns
-------
y : scalar or array_like
The result, of length R or length M or M by R,
The result, of length R or length M or M by R.

See Also
--------
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.

Examples
--------
Expand Down
19 changes: 9 additions & 10 deletions scipy/interpolate/_fitpack_impl.py
Expand Up @@ -625,17 +625,17 @@ def splint(a, b, tck, full_output=0):
An array containing the integrals of the normalized B-splines
defined on the set of knots.

Notes
-----
splint silently assumes that the spline function is zero outside the data
interval (a, b).

See Also
--------
splprep, splrep, sproot, spalde, splev
bisplrep, bisplev
UnivariateSpline, BivariateSpline

Notes
-----
splint silently assumes that the spline function is zero outside the data
interval (a, b).

References
----------
.. [1] P.W. Gaffney, The calculation of indefinite integrals of b-splines",
Expand Down Expand Up @@ -689,7 +689,6 @@ def sproot(tck, mest=10):
bisplrep, bisplev
UnivariateSpline, BivariateSpline


References
----------
.. [1] C. de Boor, "On calculating with b-splines", J. Approximation
Expand Down Expand Up @@ -1166,15 +1165,15 @@ def splder(tck, n=1):
Spline of order k2=k-n representing the derivative
of the input spline.

See Also
--------
splantider, splev, spalde

Notes
-----

.. versionadded:: 0.13.0

See Also
--------
splantider, splev, spalde

Examples
--------
This can be used for finding maxima of a curve:
Expand Down
41 changes: 20 additions & 21 deletions scipy/interpolate/_fitpack_py.py
Expand Up @@ -328,17 +328,17 @@ def splev(x, tck, der=0, ext=0):
the points in `x`. If `tck` was returned from `splprep`, then this
is a list of arrays representing the curve in an N-D space.

Notes
-----
Manipulating the tck-tuples directly is not recommended. In new code,
prefer using `BSpline` objects.

See Also
--------
splprep, splrep, sproot, spalde, splint
bisplrep, bisplev
BSpline

Notes
-----
Manipulating the tck-tuples directly is not recommended. In new code,
prefer using `BSpline` objects.

References
----------
.. [1] C. de Boor, "On calculating with b-splines", J. Approximation
Expand Down Expand Up @@ -395,6 +395,12 @@ def splint(a, b, tck, full_output=0):
defined on the set of knots.
(Only returned if `full_output` is non-zero)

See Also
--------
splprep, splrep, sproot, spalde, splev
bisplrep, bisplev
BSpline

Notes
-----
`splint` silently assumes that the spline function is zero outside the data
Expand All @@ -403,12 +409,6 @@ def splint(a, b, tck, full_output=0):
Manipulating the tck-tuples directly is not recommended. In new code,
prefer using the `BSpline` objects.

See Also
--------
splprep, splrep, sproot, spalde, splev
bisplrep, bisplev
BSpline

References
----------
.. [1] P.W. Gaffney, The calculation of indefinite integrals of b-splines",
Expand Down Expand Up @@ -459,17 +459,16 @@ def sproot(tck, mest=10):
zeros : ndarray
An array giving the roots of the spline.

Notes
-----
Manipulating the tck-tuples directly is not recommended. In new code,
prefer using the `BSpline` objects.

See Also
--------
splprep, splrep, splint, spalde, splev
bisplrep, bisplev
BSpline

Notes
-----
Manipulating the tck-tuples directly is not recommended. In new code,
prefer using the `BSpline` objects.

References
----------
Expand Down Expand Up @@ -684,16 +683,16 @@ def splder(tck, n=1):
A tuple is returned iff the input argument `tck` is a tuple, otherwise
a BSpline object is constructed and returned.

Notes
-----

.. versionadded:: 0.13.0

See Also
--------
splantider, splev, spalde
BSpline

Notes
-----

.. versionadded:: 0.13.0

Examples
--------
This can be used for finding maxima of a curve:
Expand Down