Exemple #1
0
def test1__mul__():
    x = dual.Dual(2)
    f = x * 9
    assert f.val == 18
    assert f.der == 9
Exemple #2
0
def test2__mul__():
    x = dual.Dual(1)
    f = x * x
    assert f.val == 1
    assert f.der == 2
Exemple #3
0
def test__neg__():
    x = dual.Dual(3)
    f = -x
    assert f.val == -3
    assert f.der == -1
Exemple #4
0
def test__rsub__():
    x = dual.Dual(1)
    f = 4 - 4 * x
    assert f.val == 0
    assert f.der == -4
Exemple #5
0
def test1__sub__():
    x = dual.Dual(2)
    f = 6 * x - 9
    assert f.val == 3
    assert f.der == 6
Exemple #6
0
def test2__sub__():
    x = dual.Dual(3)
    f = 6 * x - 4 * x
    assert f.val == 6
    assert f.der == 2
Exemple #7
0
def test2__add__():
    x = dual.Dual(2)
    f = 6 * x + 4 * x
    assert f.val == 20
    assert f.der == 10
Exemple #8
0
def test__rtruediv__():
    x = dual.Dual(2)
    f = 1 / x
    assert f.val == 0.5
    assert f.der == -0.25
Exemple #9
0
def test__rpow__():
    x = dual.Dual(2)
    f = 2**x
    assert f.val == 4.0
    assert f.der == np.log(2) * 2**2
Exemple #10
0
def test1__add__():
    x = dual.Dual(3)
    f = 6 * x + 9
    assert f.val == 27
    assert f.der == 6
Exemple #11
0
def test__pos__():
    x = dual.Dual(-3)
    f = +x
    assert f.val == -3
    assert f.der == 1
Exemple #12
0
def test2__pow__():
    x = dual.Dual(2)
    f = x**2
    assert f.val == 4
    assert f.der == 4
Exemple #13
0
def test1__pow__():
    x = dual.Dual(2)
    f = x**x
    assert f.val == 4.0
    assert f.der == 2 * (2 + 2 * np.log(2))
Exemple #14
0
def test__rmul__():
    x = dual.Dual(3)
    f = 4 * x
    assert f.val == 12
    assert f.der == 4
Exemple #15
0
def test__radd__():
    x = dual.Dual(2)
    f = 4 + 4 * x
    assert f.val == 12
    assert f.der == 4
Exemple #16
0
def test1__truediv__():
    x = dual.Dual(2)
    f = x / 10
    assert f.val == 0.2
    assert f.der == 0.1
Exemple #17
0
def test2__truediv__():
    x = dual.Dual(1)
    f = (2 * x**2) / (4 * x)
    assert f.val == 0.5
    assert f.der == 0.5