Example #1
0
def pad_test_add_var():
    func = ['_x + _y + sin(_x)', 'exp(_x+_y) - _x - sqrt(_y)']
    PAD = Parallelized_AD(fun=func)
    PAD.add_var('x')
    PAD.add_var('y')
    PAD.add_function('_z**2')
    PAD.add_var('z')
    out = PAD.get_Jacobian([1, 2, 3])
    assert out[0][0] == 1 + np.cos(1)
    assert out[0][1] == 1
    assert out[0][2] == 0
    assert out[1][0] == np.exp(3) - 1
    assert out[1][1] == np.exp(3) - 1 / (2*np.sqrt(2))
    assert out[1][2] == 0
    assert out[2][0] == 0
    assert out[2][1] == 0
    assert out[2][2] == 6
Example #2
0
def pad_test_add_function():
    var_names = ['x','y']
    PAD = Parallelized_AD(var=var_names)
    PAD.add_function('_x + _y + sin(_x)')
    PAD.add_function('exp(_x+_y) - _x - sqrt(_y)')
    PAD.add_function('_x+1+_y ')
    out = PAD.get_Jacobian([1, 2])
    assert out[0][0] == 1 + np.cos(1)
    assert out[0][1] == 1
    assert out[1][0] == np.exp(3) - 1
    assert out[1][1] == np.exp(3) - 1 / (2*np.sqrt(2))
    assert out[2][0] == 1
    assert out[2][1] == 1