def test_tan4(): # AD object with .val=[1,2] x1 = AD(val=[1, 2], index=0, magnitude=2) # AD object with .val=[2,3] x2 = AD(val=[2, 3], index=1, magnitude=2) y = ef.tan(x1 + x2) assert y.val == pytest.approx(np.tan([3, 5])) assert y.der[0] == pytest.approx((1 / np.cos([3, 5]))**2 * 1) assert y.der[1] == pytest.approx((1 / np.cos([3, 5]))**2 * 1)
def test_tan1(): # default AD object with .val=[0.0] x = AD() y = ef.tan(x) assert y.val == pytest.approx(np.tan(0)) assert y.der == pytest.approx((1 / np.cos(0))**2 * 1)
def test_tan2(): # AD object with .val=[1,2] x = AD(val=[1, 2], index=0, magnitude=1) y = ef.tan(x) assert y.val == pytest.approx(np.tan([1, 2])) assert y.der[0] == pytest.approx((1 / np.cos([1, 2]))**2 * 1)
def test_tan0(): x = 1 assert ef.tan(x) == pytest.approx(np.tan(x))