def test_cos(): value = 0.5 x = Variable('x', value) a = cos(value) b = arccos(value) c = cosh(value) assert a == pytest.approx(np.cos(value)) assert b == pytest.approx(np.arccos(value)) assert c == pytest.approx(np.cosh(value)) g = cos(x) h = arccos(x) i = cosh(x) assert g.val == pytest.approx(np.cos(value)) assert h.val == pytest.approx(np.arccos(value)) assert i.val == pytest.approx(np.cosh(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_plot_derivative_trig(): def f(x): return sin(x) xs, ys = tools.plot_derivative(f, 0, 5, n_pts=5) txs = np.linspace(0, 5, 5) tys = [cos(x) for x in txs] assert (xs == txs).all() assert ys == tys
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)
def f(x): return cos(x) * tan(x) + exp(x)
def f(v): return [v[0] + v[1], v[1] - v[2], cos(v[2]), exp(v[3]) * sin(v[2])]
def f0(x): return x**3 - 4 * x + cos(exp(-sin(tan(log(x)))))
def f5(x, y, z): return [exp(-(sin(x) - cos(y))**2), sin(-log(x)**2 + tan(z))]
def trig(w, x, y, z): return sin(x) + cos(z) * y + sin(w)