def pad_test_value(): var_names = ['x','y'] func = ['_x + _y + sin(_x)', 'exp(_x+_y) - _x - sqrt(_y)'] PAD = Parallelized_AD(fun=func, var=var_names) PAD.get_value([1, 2]) out = PAD.value assert out[0] == 1 + 2 + np.sin(1) assert out[1] == np.exp(3) - 1 - np.sqrt(2)
def pad_test_forward_reverse(): ''' Here's a quick check to ensure our equality condition is working (and our forward and reverse modes!). If everything is in order, forward mode and reverse mode should be equal. ''' func = ['_x + sin(_y)*_z', '_x + sin(_y)*exp(_z)'] PAD = Parallelized_AD(fun = func, var = ['x', 'y', 'z']) a = PAD.get_Jacobian([1,2,3]) b = PAD.get_value([1,2,3]) PAD2 = Parallelized_AD(fun = func, var = ['x', 'y', 'z']) a2 = PAD2.get_Jacobian([1,2,3], forward=True) b2 = PAD2.get_value([1,2,3]) for i in range(2): for j in range(3): assert a[i][j] == a2[i][j] for i in range(2): assert b[i] == b2[i]