Spline Utilities [private methods]
Here are the functions of the module splinekit.spline_utilities. The description of these low-level building blocks is provided for completeness only. These functions are not meant to be called directly.
The splinekit.spline_utilities module provides the building blocks
and low-level methods associated to the efficient and stable computation of
polynomial B-splines of arbitrary degree.
- splinekit.spline_utilities._sgn_frac(x: Fraction) int
Signum function \({\mathrm{sgn}}.\)
Returns as an integer the signum of the rational argument \(x.\)
- Parameters:
x (Fraction) – Rational argument.
- Returns:
The signum of \(x.\)
- Return type:
int
- splinekit.spline_utilities._sgn(x: float) float
Signum function \({\mathrm{sgn}}.\)
Returns the signum of the argument \(x.\)
- Parameters:
x (float) – Argument.
- Returns:
The signum of \(x.\)
- Return type:
float
- splinekit.spline_utilities._pse_frac(x: Fraction, n: int) Fraction
Polynomial simple element \(\varsigma^{n}.\)
Returns the rational value of a polynomial simple element of integer degree \(n\) evaluated at the rational argument \(x.\)
- Parameters:
x (Fraction) – Rational argument.
n (int) – Degree of the polynomial simple element.
- Returns:
The rational value of the polynomial simple element at \(x.\)
- Return type:
Fraction
- splinekit.spline_utilities._pse(x: float, n: int) float
Polynomial simple element \(\varsigma^{n}.\)
See also
splinekit.bsplines.polynomial_simple_elementPolynomial simple element.
- splinekit.spline_utilities._db_frac(x: Fraction, n: int, d: int) Fraction
Differentiated B-spline \({\mathrm{D}}^{d}\beta^{n}.\)
Returns the rational value of the \(d\)-th derivative of a polynomial B-spline \(\beta^{n}\) of nonnegative degree \(n\) evaluated at the rational argument \(x,\) with \(d\) nonnegative. This function is computed as
\[\frac{{\mathrm{d}}^{d}\beta^{n}(x)}{{\mathrm{d}}x^{d}}= \sum_{k=0}^{n+1}\,\left(-1\right)^{k}\,{n+1\choose k}\,\varsigma^{n-d} (x+\frac{n+1}{2}-k),\]with \(\varsigma\) a polynomial simple element.
- Parameters:
x (Fraction) – Rational argument.
n (int) – Nonnegative degree of the polynomial B-spline.
d (int) – Nonnegative order of differentiation.
- Returns:
The rational value of the \(d\)-th derivative of a B-spline at rational \(x.\)
- Return type:
Fraction
- splinekit.spline_utilities._db(x: float, n: int, d: int) float
Differentiated B-spline \({\mathrm{D}}^{d}\beta^{n}.\)
Returns the value of the \(d\)-th derivative of a polynomial B-spline of nonnegative degree \(n\) evaluated at \(x,\) with \(d\) nonnegative.
- Parameters:
x (float) – Argument.
n (int) – Nonnegative degree of the polynomial B-spline.
d (int) – Nonnegative order of differentiation.
- Returns:
The value of the \(d\)-th derivative of a B-spline at \(x.\)
- Return type:
float
- splinekit.spline_utilities._b(n: int) ndarray[tuple[int], dtype[float64]]
B-spline discrete sequence \({\mathrm{b}}^{n}.\)
Returns a
numpyone-dimensional array of the nonvanishing values \(\beta^{n}(k)\) of a polynomial B-spline \(\beta^{n}\) of nonnegative degree \(n\) sampled at the integers \(k\in[-\left\lfloor n/2\right\rfloor\ldots \left\lfloor n/2\right\rfloor].\)- Parameters:
n (int) – Nonnegative degree of the polynomial B-spline.
- Returns:
The samples of the B-spline.
- Return type:
np.ndarray[tuple[int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._pole(n: int) ndarray[tuple[int], dtype[float64]]
Poles of the reciprocal of the z-transform of a B-spline \(\beta^{n}.\)
See also
splinekit.bsplines.polePoles of polynomial B-splines.
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._knots(n: int) ndarray[tuple[int], dtype[float64]]
Knots of the B-spline \(\beta^{n}.\)
Returns a
numpyone-dimensional array of the knots of a polynomial B-spline of nonnegative degree \(n.\)- Parameters:
n (int) – Nonnegative degree of the polynomial B-spline.
- Returns:
The knots of the B-spline.
- Return type:
np.ndarray[tuple[int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._w_frac(n: int) List[List[Fraction]]
Spline evaluation matrix \({\mathbf{W}}^{n}.\)
Returns the B-spline rational evaluation matrix \({\mathbf{W}}^{n}\in{\mathbb{Q}}^{\left(n+1\right)\times \left(n+1\right)}\) of a polynomial B-spline \(\beta^{n}\) of positive degree \(n,\) as defined by the rational component at its \((r+1)\)-th row and \((c+1)\)-th column
\[w_{r+1,c+1}^{n}=w^{n}[r][c]=\frac{1}{c!}\, \left(\left.\frac{{\mathrm{d}}^{c}\beta^{n}(x)}{{\mathrm{d}}x^{c}} \right|_{x=\frac{n-1}{2}-r}+\frac{1}{2}\, {\mathbf{[\![}}c=n\,{\mathbf{]\!]}}\,\left(-1\right)^{n-r}\, {n+1\choose r+1}\right),\]where the notation \({\mathbf{[\![}}\cdot\,{\mathbf{]\!]}}\) is that of the Iverson bracket. The B-spline derivatives are computed as in _db_frac.
- Parameters:
n (int) – Positive degree of the polynomial B-spline.
- Returns:
The B-spline rational evaluation matrix.
- Return type:
list of list of Fraction
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._w(n: int) ndarray[tuple[int, int], dtype[float64]]
Spline evaluation matrix \({\mathbf{W}}^{n}.\)
Returns the B-spline evaluation matrix \({\mathbf{W}}^{n}\in{\mathbb{R}}^{\left(n+1\right)\times \left(n+1\right)}\) of a polynomial B-spline of positive degree \(n.\)
- Parameters:
n (int) – Positive degree of the polynomial B-spline.
- Returns:
The B-spline evaluation matrix.
- Return type:
np.ndarray[tuple[int, int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._inv_w(n: int) ndarray[tuple[int, int], dtype[float64]]
Spline evaluation matrix inverse \(\left({\mathbf{W}}^{n}\right)^{-1}.\)
Returns the inverse \(\left({\mathbf{W}}^{n}\right)^{-1} \in{\mathbb{R}}^{\left(n+1\right)\times\left(n+1\right)}\) of the B-spline evaluation matrix of positive degree \(n.\)
- Parameters:
n (int) – Positive degree of the polynomial B-spline.
- Returns:
The inverse of the B-spline evaluation matrix.
- Return type:
np.ndarray[tuple[int, int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._wint(n: int) ndarray[tuple[int, int], dtype[float64]]
Integrated-B-spline evaluation matrix \({\mathbf{W}}_{{\mathrm{int}}}^{n}.\)
Returns the integrated-B-spline evaluation matrix \({\mathbf{W}}_{{\mathrm{int}}}^{n} \in{\mathbb{R}}^{\left(n+1\right)\times\left(n+2\right)}\) of an integrated polynomial B-spline of nonnegative degree \(n,\) as defined by the component at its \((r+1)\)-th row and \((c+1)\)-th column
\[\begin{split}\left[{\mathbf{W}}^{n}_{{\mathrm{int}}}\right]_{r+1,c+1}= w_{{\mathrm{int}}}^{n}[r][c]=\left\{\begin{array}{ll}\sum_{q=0}^{n}\, \frac{1}{q+1}\sum_{p=r+1}^{n}\,w^{n}[p][q],&c=0\\ \frac{1}{c}\,w^{n}[r][c-1],&c\in[1\ldots n+1],\end{array}\right.\end{split}\]where \(w^{n}\) is a component of the B-spline evaluation matrix.
- Parameters:
n (int) – Nonnegative degree of the polynomial B-spline.
- Returns:
The integrated-B-spline evaluation matrix.
- Return type:
np.ndarray[tuple[int, int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._wd(n: int) ndarray[tuple[int, int], dtype[float64]]
Differentiated-B-spline evaluation matrix \({\mathbf{W}}_{{\mathrm{d}}}^{n}.\)
Returns the differentiated-B-spline evaluation matrix \({\mathbf{W}}_{{\mathrm{d}}}^{n} \in{\mathbb{R}}^{\left(n+1\right)\times n}\) of a differentiated polynomial B-spline of degree \(n>1,\) as defined by the component at its \((r+1)\)-th row and \((c+1)\)-th column
\[\left[{\mathbf{W}}^{n}_{{\mathrm{d}}}\right]_{r+1,c+1}= w_{{\mathrm{d}}}^{n}[r][c]=\left(c+1\right)\,w^{n}[r][c+1],\]where \(w^{n}\) is a component of the B-spline evaluation matrix.
- Parameters:
n (int) – Positive degree of the polynomial B-spline.
- Returns:
The differentiated-B-pline evaluation matrix.
- Return type:
np.ndarray[tuple[int, int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._iota(n: int) ndarray[tuple[int], dtype[float64]]
Returns the vector \({\mathbf{i}}^{n}\) of the pole coefficients used in the computation of inverse B-spline sequences. For a polynomial B-spline of degree \(n>1,\) this vector is given by
\[{\mathbf{i}}^{n}=\left(\frac{1} {\beta^{n}(\left\lfloor\frac{n}{2}\right\rfloor)\, \left(\left[{\mathbf{z}}^{n}\right]_{c+1}- \frac{1}{\left[{\mathbf{z}}^{n}\right]_{c+1}}\right)\, \prod_{p\in[0\ldots\left\lfloor\frac{n}{2}\right\rfloor-1]\setminus \{c\}}\,\left(\left[{\mathbf{z}}^{n}\right]_{c+1}- \left[{\mathbf{z}}^{n}\right]_{p+1}+ \frac{1}{\left[{\mathbf{z}}^{n}\right]_{c+1}}- \frac{1}{\left[{\mathbf{z}}^{n}\right]_{p+1}}\right)}\right) _{c=0}^{\left\lfloor\frac{n}{2}\right\rfloor-1},\]where \({\mathbf{z}}^{n}\) is the vector of poles. Equivalently, it is also given by the first column of the inverse of the matrix \({\mathbf{Z}}^{n},\) as in
\[{\mathbf{i}}^{n}=\left[\left({\mathbf{Z}}^{n}\right)^{-1}\right] _{\cdot,1}.\]There, the component at the \((r+1)\)-th row and \((c+1)\)-th column of \({\mathbf{Z}}^{n}\in{\mathbf{R}}^ {\left\lfloor n/2\right\rfloor\times\left\lfloor n/2\right\rfloor}\) is given by
\[z_{r+1,c+1}^{n}=z^{n}[r][c]=\sum_{q=-\left\lfloor n/2\right\rfloor}^ {\left\lfloor n/2\right\rfloor}\, \left(\left[{\mathbf{z}}^{n}\right]_{c+1}\right)^{\left|r-q\right|}\, \beta^{n}(q).\]- Parameters:
n (int) – Degree of the polynomial B-spline, with \(n > 1\).
- Returns:
The vector \({\mathbf{i}}^{n}.\)
- Return type:
np.ndarray[tuple[int], np.dtype[np.float64]]
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._v_frac(n: int) List[List[Fraction]]
Returns the rational lookup table \({\mathbf{V}}^{n} \in{\mathbb{Q}}^{n\times\left(\left\lfloor n/2\right\rfloor+1\right)}\) that contains the polynomial coefficients of a B-spline-weighted sum of discrete monomials. For B-splines \(\beta^{n}\) of positive degree \(n,\) it is given by the component at its \((r+1)\)-th row and \((c+1)\)-th column
\[\begin{split}\left[{\mathbf{V}}^{n}\right]_{r+1,c+1}= v^{n}[r][c]=\left\{\begin{array}{ll}1,&c=0\\{r+1\choose 2\,c}\, \sum_{k=0}^{n-1}\,\left(\frac{n-1}{2}-k\right)^{2\,c}\, \beta^{n}(\frac{n-1}{2}-k),&c>0.\end{array}\right.\end{split}\]- Parameters:
n (int) – Positive degree of the polynomial B-spline.
- Returns:
The lookup table \({\mathbf{V}}^{n}.\)
- Return type:
list of list of Fraction
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._alpha_frac(n: int, m: int) List[Fraction]
Returns the lookup table \({\mathbf{A}}^{n}\) that contains the spline coefficients of a monomial-reproducing spline. For a B-spline \(\beta^{n}\) of nonnegative degree \(n\) and a monomial of nonnegative degree \(m\) not greater than \(n,\) its component at \(p\in[0\ldots m]\) is defined by the recursion
\[\begin{split}\alpha^{n}[m][p]=\left\{\begin{array}{ll} -\sum_{q=1}^{\left\lfloor\left(m-p\right)/2\right\rfloor} \,v^{n}[m-1][q]\,\alpha^{n}[m-2\,q][p],&0\leq p<m-1\\0,&p=m-1\\1,&p=m, \end{array}\right.\end{split}\]with \(v^{n}[m-1][q]\) the component at row \(m\) and column \((q+1)\) of the the lookup table \({\mathbf{V}}^{n}\) in _v_frac.
- Parameters:
n (int) – Nonnegative degree of the polynomial B-spline.
m (int) – Nonnegative degree of the monomial.
- Returns:
The lookup table \({\mathbf{A}}^{n}.\)
- Return type:
list of list of Fraction
Notes
The results of this method are cached. If the returned results are mutated, the cache gets modified and the next call will return corrupted values.
- splinekit.spline_utilities._divmod(x: float, m: int) Tuple[int, float]
Quotient and remainder from dividend and divisor.
A function similar to the built-in
divmodfunction, with the added guarantee that the remainder part of result lies in the closed-open interval \([0,m),\) while the built-in version only guarantees the closed interval \([0,m].\) The tipping point where \(m\) is included or not mimicks theModfunction of the Wolfram framework.- Parameters:
x (float) – Dividend whose quotient and remainder are sought.
m (int) – Nonzero divisor.
- Returns:
A tuple
(q, r)such thatx == m * q + rup to numerical inaccuracies, with the guarantee thatr < m.- Return type:
tuple (int, float)
Examples
- Load the libraries.
>>> import splinekit.spline_utilities as sku >>> import math
- Here is an argument at which this function agrees with the built-in one.
>>> sku._divmod(-math.ulp(1.0), 1) == divmod(-math.ulp(1.0), 1) True
- Here is an argument at which this function disagrees with the built-in one.
>>> sku._divmod(-math.ulp(0.1), 1) == divmod(-math.ulp(0.1), 1) False