def test_diff_pow1(self): for eg in self.examples: p = SparsePowers(eg) for var in xrange(len(eg)): coeff, q = p.diff(var) coeff1, q1 = p.diff_pow(var, 1) self.assertEquals(coeff1, coeff) self.assertEquals(q1, q)
def test_diff(self): for eg in self.examples: p = SparsePowers(eg) for var in xrange(len(eg)): coeff, q = p.diff(var) self.assertEquals(coeff, eg[var]) msg = ('d(%d)[%s]'%(var, repr(eg)))+' -> '+repr(q) for j in xrange(len(eg)): if j==var: if eg[j]==0: self.assertEquals(coeff, 0.0, msg) else: self.assertEquals(q[j], eg[j]-1, msg) self.assertEquals(coeff, eg[j], msg) else: if eg[var] != 0: self.assertEquals(q[j], eg[j], msg)
def test_diff_pow(self): for eg in self.examples: p = SparsePowers(eg) for var in xrange(len(eg)): coeff0, q0 = p.diff_pow(var, 0) self.assertEquals(coeff0, 1.0) self.assertEquals(q0, p) coeff, q = p.diff(var) coeff1, q1 = p.diff_pow(var, 1) self.assertEquals(coeff1, coeff) self.assertEquals(q1, q) for pow in xrange(5): coeff, q = p.diff_pow(var, pow) cop = p.copy() c = 1.0 for i in xrange(pow): co, cop = cop.diff(var) c *= co self.assertEquals(cop, q) err = abs(coeff - c) self.assert_(err < 1.0e-12, err)
def test_diff_powers(self): m = SparsePowers() c, d = m.diff(0) self.assertEquals(repr(d), 'SparsePowers(1, {})')
def test_diff_coeff(self): m = SparsePowers() c, d = m.diff(0) self.assertEquals(c, 0)