コード例 #1
0
def test_cot_s(s):
    def value(x):
        return 1 / math.tan(x)

    output = ad.cot(s)
    assert output.value == pytest.approx(value(s))
    assert output.derivatives == {}
コード例 #2
0
def test_cot_sm(m):
    def value(x):
        return 1 / math.tan(x)

    output = ad.cot(m)
    for i in range(len(m)):
        assert output.value[i] == pytest.approx(value(m[i]))
    assert output.derivatives == {}
コード例 #3
0
def test_cot_d(b):
    def value(x):
        return 1 / math.tan(x)

    def der(x):
        return -1 / (math.sin(x)**2)

    output = ad.cot(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
    })
コード例 #4
0
def test_cot_dm(dm):
    def value(x):
        return 1 / math.tan(x)

    def der(x):
        return -1 / (math.sin(x)**2)

    output = ad.cot(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])
コード例 #5
0
def test_cot_no_change(b):
    b_d = b.derivatives
    output = ad.cot(b)
    assert b_d == b.derivatives