def test_more_operators(): a = Variable(val=4, name='a') # Power t1 = Diff().auto_diff(function=power_scalar, eval_point=[a]) assert (t1.val == 26) assert (t1.der['a'] == 8) # Square root t2 = Diff().auto_diff(function=sqrt_scalar, eval_point=[a]) assert (t2.val == 13) assert (t2.der['a'] == 1 / 3) # Power function t3 = Diff().auto_diff(function=power_function, eval_point=[a]) assert (t3.val == 16) assert (t3.der['a'] == bm.log(2) * 16) assert (t3.der['a'] == np.log(2) * 16) # Power function general t4 = Diff().auto_diff(function=power_function_general, eval_point=[a]) assert (t4.val == 256) assert (t4.der['a'] == 256 * (bm.log(4) + 1)) assert (t4.der['a'] == 256 * (np.log(4) + 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 log_exp_function(x, y): return bm.log(x) + bm.exp(y)
def log_exp(x, y): return bm.log(x * x) + x * bm.exp(y)