def test_tan_s(s): def value(x): return math.tan(x) output = ad.tan(s) assert output.value == pytest.approx(value(s)) assert output.derivatives == {}
def test_tan_sm(m): def value(x): return math.tan(x) output = ad.tan(m) for i in range(len(m)): assert output.value[i] == pytest.approx(value(m[i])) assert output.derivatives == {}
def test_tan_d(b): def value(x): return math.tan(x) def der(x): return 1 / (math.cos(x)**2) output = ad.tan(b) assert output.value == pytest.approx(value(b.value)) coef = der(b.value) assert output.derivatives == pytest.approx({ 'x': coef * 1.2, 'y': coef * 9.5, 'z': coef * 5 })
def test_tan_dm(dm): def value(x): return math.tan(x) def der(x): return 1 / (math.cos(x)**2) output = ad.tan(dm) for i in range(len(dm.value)): assert output.value[i] == pytest.approx(value(dm.value[i])) coef = der(dm.value[i]) assert output.derivatives['x'][i] == pytest.approx( coef * dm.derivatives['x'][i]) assert output.derivatives['y'][i] == pytest.approx( coef * dm.derivatives['y'][i]) assert output.derivatives['z'][i] == pytest.approx( coef * dm.derivatives['z'][i])
def test_tan_no_change(b): b_d = b.derivatives output = ad.tan(b) assert b_d == b.derivatives