On Wed, Mar 10, 2010 at 11:14 PM, Priit Laes <plaes...@gmail.com> wrote:
> Ühel kenal päeval, K, 2010-03-10 kell 15:08, kirjutas Brian Granger: > > Hi, > > > > I have improved the Piecewise class and implemented B-splines. Here > > is the branch on github: > > > > http://github.com/ellisonbg/sympy/tree/bg-piecewise > > +def bspline_basis(d, knots, n, x, close=True): > + """The n-th B-spline at x of degree d with knots. > + > + B-Splines are piecewise polynomials of degree d [1]. There are > defined on > > Maybe "They are ..." ? > > Yep. > + a set of knots, which is a sequence of integers or floats. > > ... > > + It is quite time consuming to contruct and evaluate B-splines. If you > construct ---------------------------^^^ > + need to evaluate a B-splines many times, it is best to lambdify them > + first: > > ... > > + if d==0: > spaces maybe: d == 0 > + result = Piecewise( > + (S.One, Interval(knots[n], knots[n+1], False, True)), > + (0, True) > + ) > + elif d>0: > d > 0 seems a bit clearer than d>0. Unfortunately we do not have code > style manual :S > > OK. > ... > > +def bspline_basis_set(d, knots, x): > + """Return the len(knots)-d-1 B-splines at x of degree d with knots. > skip "the" --->^^^ > + > + This function returns a list of Piecewise polynomials that are the > + len(knots)-d-1 B-splines of degree d for the given knots. This > function > + calls bspline_basis(d, knots, n, x) for different values of n. > > Hmm.. function called bspline_basis_set that returns a list ;) > Although, list is a bit more flexible to deal with than set... > > By "Basis Set" I don't mean set as in python built in set. Rather, in physics we refer to a basis set. Ironically, this type of "set" is typically ordered, so it is more like a list - which is why I choose that. I think this name is OK. > ... > > + splines = [] > + n_splines = len(knots)-d-1 > + for i in range(n_splines): > + b = bspline_basis(d,knots, i, x) > + splines.append(b) > + return splines > > I would write this simply as: > > + n_splines = len(knots)-d-1 > + return [bspline_basis(d, knots, i, x) for i in range(n_splines)] > > Ok, I like this. > or even reduce it to single line ;) > > + return [bspline_basis(d, knots, i, x) for i in range(len(knots) - d - > 1)] > > I like having the explicit calculation of n_splines as it helps people who are reading the code to see how the number of splines is calculated. Thanks! Brian -- > Päikest, > Priit ;) > > > > -- > You received this message because you are subscribed to the Google Groups > "sympy-patches" group. > To post to this group, send email to sympy-patc...@googlegroups.com. > To unsubscribe from this group, send email to > sympy-patches+unsubscr...@googlegroups.com<sympy-patches%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/sympy-patches?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patc...@googlegroups.com. To unsubscribe from this group, send email to sympy-patches+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en.