def test_arctan(less1_cls, less1_var):
    f1 = AD.arctan(less1_cls)
    f2 = AD.arctan(less1_var)

    assert f1.func_val == np.arctan(0.25)
    assert f1.partial_dict['x1'] == 1 / (1 + 0.25**2)
    assert f2 == np.arctan(0.25)
Esempio n. 2
0
def test_invtrig():
    x = np.array([0.25, 0.5])
    inv_ar = AD.from_array(x, 'p')

    assert [
        np.round(AD.arcsin(inv_ar)[0].func_val, 7),
        np.round(AD.arcsin(inv_ar)[1].func_val, 7)
    ] == [np.round(0.25268025514207865, 7),
          np.round(0.5235987755982989, 7)]
    assert np.round(AD.arcsin(inv_ar)[0].partial_dict['p_0'],
                    7) == np.round(1.0327955589886444, 7)

    assert [
        np.round(AD.arccos(inv_ar)[0].func_val, 7),
        np.round(AD.arccos(inv_ar)[1].func_val, 7)
    ] == [np.round(1.318116071652818, 7),
          np.round(1.0471975511965979, 7)]
    assert np.round(AD.arccos(inv_ar)[0].partial_dict['p_0'],
                    7) == np.round(-1.0327955589886444, 7)

    assert np.round(AD.arctan(inv_ar)[1].func_val,
                    7) == np.round(0.4636476090008061, 7)
    assert AD.arctan(inv_ar)[1].partial_dict['p_1'] == 0.8