Skip to content

Commit

Permalink
add docstring for the main xspline class
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengp0 committed Jul 25, 2023
1 parent 3aa1a66 commit 2d54c16
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions src/xspline/xspl.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
from typing import Optional

from numpy.typing import NDArray

from xspline.bspl import clear_bspl_cache, get_bspl_funs
from xspline.poly import get_poly_fun
from xspline.xfunction import BasisXFunction
from xspline.typing import NDArray


class XSpline(BasisXFunction):
"""Main class for xspline functions.
Parameters
----------
knots
Knots of the spline.
degree
Degree of the spline.
ldegree
Left extrapolation polynomial degree.
rdegree
Right extrapolation polynomial degree.
coefs
The coefficients for linear combining the spline basis.
"""

def __init__(self,
knots: tuple[float, ...],
degree: int,
ldegree: Optional[int] = None,
rdegree: Optional[int] = None,
coefs: Optional[NDArray] = None) -> None:
def __init__(
self,
knots: tuple[float, ...],
degree: int,
ldegree: Optional[int] = None,
rdegree: Optional[int] = None,
coefs: Optional[NDArray] = None,
) -> None:
# validate inputs
knots, degree = tuple(sorted(map(float, knots))), int(degree)
if len(set(knots)) < 2:
Expand All @@ -37,8 +54,26 @@ def __init__(self,
self.ldegree, self.rdegree = ldegree, rdegree
super().__init__(funs, coefs=coefs)

def get_design_mat(self, x: NDArray,
order: int = 0, check_args: bool = True) -> NDArray:
def get_design_mat(
self, x: NDArray, order: int = 0, check_args: bool = True
) -> NDArray:
"""Create design matrix from spline basis functions.
Parameters
----------
x
Data points.
order
Order of differentiation/integration.
check_args
If ``True``, it will automatically check and parse the arguments.
Returns
-------
describe
Design matrix from spline basis functions.
"""
design_mat = super().get_design_mat(x, order, check_args)
clear_bspl_cache()
return design_mat

0 comments on commit 2d54c16

Please sign in to comment.