Skip to content
Snippets Groups Projects
Commit 8e5e6d47 authored by Michele Maris's avatar Michele Maris
Browse files

u

parent b601953e
Branches
Tags
No related merge requests found
...@@ -47,6 +47,29 @@ def evaluate_spline(x, y, b, c, d, x_eval): ...@@ -47,6 +47,29 @@ def evaluate_spline(x, y, b, c, d, x_eval):
break break
return y_eval return y_eval
@njit
def evaluate_spline_singlex(x, y, b, c, d, x_eval):
if xi <= x_eval[0] :
return y[0]
if x[-1] <= x_eval :
return y[-1]
#
i=len(x)//2
while True :
if x_eval < x[i] :
i=i//2
if i==0 :
return y[0]
elif x[i+1]<x_eval :
i=(i+len(x)-1)//2
if i==len(x)-1 :
return y[-1]
else :
#if x[i] <= x_eval <= x[i+1]:
dx = x_eval - x[i]
return y[i] + b[i]*dx + c[i]*dx**2 + d[i]*dx**3
return
@njit @njit
def evaluate_spline_derivative(x, b, c, d, x_eval): def evaluate_spline_derivative(x, b, c, d, x_eval):
n = len(x) - 1 n = len(x) - 1
...@@ -125,6 +148,9 @@ class NumbaNaturalCubicSpline: ...@@ -125,6 +148,9 @@ class NumbaNaturalCubicSpline:
self.y = np.asarray(y) self.y = np.asarray(y)
self.b, self.c, self.d = _compute_coeffs(self.x, self.y) self.b, self.c, self.d = _compute_coeffs(self.x, self.y)
def get_vectors(self) :
return [self.x,self.y,self.b,self.c,self.d]
def __call__(self, x_eval): def __call__(self, x_eval):
x_eval = np.asarray(x_eval) x_eval = np.asarray(x_eval)
return _evaluate(self.x, self.y, self.b, self.c, self.d, x_eval) return _evaluate(self.x, self.y, self.b, self.c, self.d, x_eval)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment