def test_matrix(self): knots = np.hstack((np.zeros(3), np.linspace(0,1,self.nrKnots-4), np.ones(3))) xi=(knots[1:-3]+knots[2:-2]+knots[3:-1])/3 nMatrix=np.zeros((len(xi),len(xi))) for i in xrange(len(xi)): fun = spline.basisFunction(i,knots) nMatrix[:,i]=fun(xi,3) revMatrix = nMatrix[::-1,::-1] for i in xrange(nMatrix.size): self.assertAlmostEqual(revMatrix.flat[i],nMatrix.flat[i])
def test_SumsUpToOne(self): # the sum of the basis functions should add up to one s = zeros([10,2]) u = linspace(0,1,10) for i in range(10): for j in range(12): b = sp.basisFunction(u,j) s[i] = s[i] + b(u[i]) b = abs(s[:,:] - 1.0) < finfo(double).eps #machine epsilon # print b,s,sum(b) assert(sum(b)==20)
def test_addsToOne(self): knots = np.hstack((np.zeros(3), np.linspace(0,1,self.nrKnots-4), np.ones(3))) Ns = [] for i in xrange(len(knots)-4): Ns.append(spline.basisFunction(i,knots)) x = np.random.random(1000) y = np.zeros(len(x)) for n in Ns: y += n(x) for val in y: self.assertAlmostEqual(val,1.)
def test_samefromblossomasfromrecursion(self): cp = array([[0.,0.1], [0.3,0.6], [0.7,0.8],[1.0,0.2]]); s = sp.Spline(cp); N = [sp.basisFunction(s.getKnots()[2:-2], j) for j in range(len(cp))] same = True; for i in linspace(0,1,400): s1 = s(i); s2 = 0; for j in range(len(cp)): s2 += cp[j]*N[j](i); # print s1 # print s2 self.assertAlmostEqual(s1.all(),s2.all());