def test_exp():
    value = 67
    x = Variable('x', value)
    f = exp(x)
    a = exp(value)
    assert a == pytest.approx(np.exp(value))
    assert f._val == pytest.approx(np.exp(value), rel=1e-5)
    assert f._der['v1'] == f._val
def test_array_input():
    arr = [Variable('x', 0.5), Variable('x', 0.5)]
    t1 = sin(arr)
    t2 = arcsin(arr)
    t3 = cos(arr)
    t4 = arccos(arr)
    t5 = tan(arr)
    t6 = arctan(arr)
    t7 = exp(arr)
    t8 = log(arr)
    t9 = sinh(arr)
    t10 = cosh(arr)
    t11 = tanh(arr)
    t12 = sqrt(arr)
    t13 = sigmoid(arr)
    assert t1[0].val == pytest.approx(np.sin(0.5))
    assert t2[1].val == pytest.approx(np.arcsin(0.5))
    assert t3[0].val == pytest.approx(np.cos(0.5))
    assert t4[1].val == pytest.approx(np.arccos(0.5))
    assert t5[0].val == pytest.approx(np.tan(0.5))
    assert t6[1].val == pytest.approx(np.arctan(0.5))
    assert t8[0].val == pytest.approx(np.log(0.5))
    assert t9[1].val == pytest.approx(np.sinh(0.5))
    assert t10[0].val == pytest.approx(np.cosh(0.5))
    assert t11[1].val == pytest.approx(np.tanh(0.5))
    assert t12[0].val == pytest.approx(np.sqrt(0.5))
    assert t13[1].val == pytest.approx(1 / (1 + np.exp(-0.5)))
def test_string_input():
    with pytest.raises(TypeError):
        f = sin('test')
    with pytest.raises(TypeError):
        f = cos('test')
    with pytest.raises(TypeError):
        f = tan('test')
    with pytest.raises(TypeError):
        f = sinh('test')
    with pytest.raises(TypeError):
        f = cosh('test')
    with pytest.raises(TypeError):
        f = tanh('test')
    with pytest.raises(TypeError):
        f = arcsin('test')
    with pytest.raises(TypeError):
        f = arccos('test')
    with pytest.raises(TypeError):
        f = arctan('test')
    with pytest.raises(TypeError):
        f = sqrt('test')
    with pytest.raises(TypeError):
        f = sigmoid('test')
    with pytest.raises(TypeError):
        f = log('test')
    with pytest.raises(TypeError):
        f = exp('test')
def test_composition_val():
    value = np.pi / 6
    x = Variable('x', value)
    c = cos(x)
    s = sin(x)
    t = tan(x)
    e = exp(x)
    f = c * t + e
    g = c + s
    assert isinstance(f, Trace)
    assert f._val == np.cos(value) * np.tan(value) + np.exp(value)
Exemplo n.º 5
0
 def f(x):
     return cos(x) * tan(x) + exp(x)
Exemplo n.º 6
0
 def f(v):
     return [v[0] + v[1], v[1] - v[2], cos(v[2]), exp(v[3]) * sin(v[2])]
Exemplo n.º 7
0
 def f(v):
     return v[0] + exp(v[1]) + 6 * v[2]**2
Exemplo n.º 8
0
def f0(x):
    return x**3 - 4 * x + cos(exp(-sin(tan(log(x)))))
Exemplo n.º 9
0
def f5(x, y, z):
    return [exp(-(sin(x) - cos(y))**2), sin(-log(x)**2 + tan(z))]
Exemplo n.º 10
0
def f1(x, y):
    return x * y + exp(x * y)
def test_exp_base2():
    x = Variable('x', 5)
    base = 2
    f = exp(x, base=base)
    assert f._val == pytest.approx(32)
    assert f._der['v1'] == (base**x._val) * np.log(base)