コード例 #1
0
def test_difficult_derivative_case():
    x1 = CMG(1.0)

    #     ## the following is a test case for: sin(tan(x)) + 2^(cos(x)) + sin(x)^tan(x)^exp(x) - (cos(x))^2, seeded at x = 1. Try it in autograd, it works.
    test_func1 = CMfunc.sin(CMfunc.tan(x1)) + 2**(CMfunc.cos(x1)) + CMfunc.sin(
        x1)**CMfunc.tan(x1)**CMfunc.exp(x1) - CMfunc.cos(x1)**2
    print("test_func1 val, der: {}, {}".format(test_func1.val,
                                               test_func1.grad))
    assert (np.round(test_func1.val,
                     8), np.round(test_func1.grad,
                                  8)) == (np.round(2.7246781638986564, 8),
                                          np.round(-1.0139897786023675, 8))
    print("Difficult derivative test passed.")
コード例 #2
0
def test_CMfunc_constant():
    assert CMfunc.sin(2) == np.sin(2)
    assert CMfunc.cos(5) == np.cos(5)
    assert CMfunc.tan(9) == np.tan(9)
    assert CMfunc.arcsin(.5) == np.arcsin(.5)
    assert CMfunc.arccos(.4) == np.arccos(.4)
    assert CMfunc.arctan(.1) == np.arctan(.1)
    assert CMfunc.exp(3) == np.exp(3)
    assert CMfunc.log(
        74088, 42) == np.log(74088) / np.log(42)  #using alternative base

    print('passed constants test')
コード例 #3
0
def test_sin():
    x = CMG(2)
    f = CMfunc.sin(x)
    assert f.val == np.sin(2)
    assert np.array_equal(f.grad, np.array([np.cos(2)]))