def test_arcsec_s(sinv): def value(x): return math.acos(1 / x) output = ad.arcsec(sinv) assert output.value == pytest.approx(value(sinv)) assert output.derivatives == {}
def test_arcsec_sm(minv): def value(x): return math.acos(1 / x) output = ad.arcsec(minv) for i in range(len(minv)): assert output.value[i] == pytest.approx(value(minv[i])) assert output.derivatives == {}
def test_arcsec_d(binv): def value(x): return math.acos(1 / x) def der(x): return 1 / (abs(x) * math.sqrt(x**2 - 1)) output = ad.arcsec(binv) assert output.value == pytest.approx(value(binv.value)) coef = der(binv.value) assert output.derivatives == pytest.approx({ 'x': coef * 1.2, 'y': coef * 9.5, 'z': coef * 5 })
def test_arcsec_dm(dminv): def value(x): return math.acos(1 / x) def der(x): return 1 / (abs(x) * math.sqrt(x**2 - 1)) output = ad.arcsec(dminv) for i in range(len(dminv.value)): assert output.value[i] == pytest.approx(value(dminv.value[i])) coef = der(dminv.value[i]) assert output.derivatives['x'][i] == pytest.approx( coef * dminv.derivatives['x'][i]) assert output.derivatives['y'][i] == pytest.approx( coef * dminv.derivatives['y'][i]) assert output.derivatives['z'][i] == pytest.approx( coef * dminv.derivatives['z'][i])
def test_arcsec_no_change(binv): b_d = binv.derivatives output = ad.arcsec(binv) assert b_d == binv.derivatives