def test_multi_dim_4(): x = AD(1, 1, 'x') y = AD(2, 2, 'y') z = AD([y.cos() + x.cos(), y.tan() + x.tanh()]) z.sort(['x', 'y']) np.testing.assert_allclose(z.val, np.array([0.12415547, -1.42344571]).reshape(2, 1), atol=1e-5) np.testing.assert_allclose(z.der, np.array([[-0.84147098, -1.81859485], [0.41997434, 11.54879841]]), atol=1e-5) assert z.name == ['x', 'y']
def test_tan_inf(): x = AD(np.pi / 2, 1, 'x') with pytest.raises(ValueError): x.tan()
def test_tan(): x = AD(0.5, 1, 'x') z = x.tan() assert z.val == [np.tan(0.5)] assert z.der == [1 / (np.cos(0.5))**2]