コード例 #1
0
def test_log(trig_cls, trig_var):
    f1 = AD.log(trig_cls)
    f2 = AD.log(trig_var)

    assert f1.func_val == np.log(np.pi / 4)
    assert f1.partial_dict['x1'] == 1 / (np.pi / 4)
    assert f2 == np.log(np.pi / 4)
コード例 #2
0
def test_misc_funcs():
    ar_f = AD.from_array([1, 4], 'f')

    assert AD.sqrt(ar_f)[1].func_val == 2
    assert AD.sqrt(ar_f)[1].partial_dict['f_1'] == 0.25

    assert AD.log(ar_f)[0].func_val == 0
    assert AD.log(ar_f)[1].partial_dict['f_1'] == 0.25

    assert np.round(AD.sinh(ar_f)[0].func_val,
                    7) == np.round(1.1752011936438014, 7)
    assert np.round(AD.sinh(ar_f)[1].partial_dict['f_1'],
                    7) == np.round(27.308232836016487, 7)

    assert np.round(AD.cosh(ar_f)[0].func_val,
                    7) == np.round(1.5430806348152437, 7)
    assert np.round(AD.cosh(ar_f)[1].partial_dict['f_1'],
                    7) == np.round(27.289917197127753, 7)
    assert np.round(AD.cosh(1), 7) == np.round(1.5430806348152437, 7)

    assert np.round(AD.tanh(ar_f)[0].func_val,
                    7) == np.round(0.7615941559557649, 7)
    assert np.round(AD.tanh(ar_f)[1].partial_dict['f_1'],
                    7) == np.round(0.001340950683025897, 7)
コード例 #3
0
def test_improper_logbase():
    x = AD(3)
    with pytest.raises(Exception):
        AD.log(x, base = AD(4))