def test_tan():
    value = 0.5
    x = Variable('x', value)
    a = tan(value)
    b = arctan(value)
    c = tanh(value)
    assert a == pytest.approx(np.tan(value))
    assert b == pytest.approx(np.arctan(value))
    assert c == pytest.approx(np.tanh(value))
    g = tan(x)
    h = arctan(x)
    i = tanh(x)
    assert g.val == pytest.approx(np.tan(value))
    assert h.val == pytest.approx(np.arctan(value))
    assert i.val == pytest.approx(np.tanh(value))
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)
Ejemplo n.º 5
0
 def f(x):
     return cos(x) * tan(x) + exp(x)
Ejemplo n.º 6
0
def f0(x):
    return x**3 - 4 * x + cos(exp(-sin(tan(log(x)))))
Ejemplo n.º 7
0
def f10(v):
    return sin(v)**2 + tan(v)**2
Ejemplo n.º 8
0
def f5(x, y, z):
    return [exp(-(sin(x) - cos(y))**2), sin(-log(x)**2 + tan(z))]