def test_non_alphabetical_22(): x = Variable(val=3, name='z') y = Variable(val=5, name='a') t1 = Diff().jacobian([f1,f2], [x,y]) assert(t1.shape == (2,2)) assert(t1[0][0] == 30) assert(t1[0][1] == 9) assert(t1[1][0] == 5) assert(t1[1][1] == bm.cos(5))
def test_jacobian_22(): x = Variable(val=3, name='x') y = Variable(val=5, name='y') t1 = Diff().jacobian([f1,f2], [x,y]) assert(t1.shape == (2,2)) assert(t1[0][0] == 30) assert(t1[0][1] == 9) assert(t1[1][0] == 5) assert(t1[1][1] == bm.cos(5))
def test_jacobian_32(): x = Variable(val=3, name='c') y = Variable(val=5, name='a') z = Variable(val=5, name='t') t1 = Diff().jacobian([f1,f2,f3], [x,y]) assert(t1.shape == (3,2)) assert(t1[0][0] == 30) assert(t1[0][1] == 9) assert(t1[1][0] == 5) assert(t1[1][1] == bm.cos(5)) assert(t1[2][0] == 5) assert(t1[2][1] == 4)
def test_jacobian_23(): x = Variable(val=3, name='x') y = Variable(val=5, name='y') z = Variable(val=2, name='z') t1 = Diff().jacobian([f1,f2], [x,y,z]) assert(t1.shape == (2,3)) assert(t1[0][0] == 30) assert(t1[0][1] == 9) assert(t1[0][2] == 1) assert(t1[1][0] == 5) assert(t1[1][1] == bm.cos(5)) assert(t1[0][2] == 1)
def test_sanity_checks(): assert (bm.log(4.1) == np.log(4.1)) assert (bm.exp(-10.1) == np.exp(-10.1)) assert (bm.sqrt(112.3) == np.sqrt(112.3)) assert (bm.sin(4.1) == np.sin(4.1)) assert (bm.cos(2.2) == np.cos(2.2)) assert (bm.tan(2) == np.tan(2.0)) assert (bm.arcsin(0) == np.arcsin(0)) assert (bm.arccos(0.2) == np.arccos(0.2)) assert (bm.arctan(2) == np.arctan(2)) assert (bm.sinh(2) == np.sinh(2)) assert (bm.cosh(2) == np.cosh(2)) assert (bm.tanh(2) == np.tanh(2)) assert (bm.logk(2, np.exp(1)) == np.log(2))
def sin_cos(x, y): return bm.sin(x) + bm.cos(y)
def sin_cos(x, y): return y * bm.sin(x * x * x) + x * bm.cos(y)