コード例 #1
0
ファイル: test_grad.py プロジェクト: okkomakkonen/dmath
def test_grad():
    def f(x, y):
        return sin(x) * cos(y)

    def f_prime(x, y):
        return (cos(x) * cos(y), -sin(x) * sin(y))

    assert grad(f)(2, 3) == f_prime(2, 3)
コード例 #2
0
ファイル: test_grad.py プロジェクト: okkomakkonen/dmath
def test_pol():
    def f(x):
        return x**2 + 3 * x + 6

    def f_prime(x):
        return 2 * x + 3

    assert grad(f)(3) == f_prime(3)
コード例 #3
0
ファイル: test_grad.py プロジェクト: okkomakkonen/dmath
def test_trig():
    def g(x):
        return sin(x**2)

    def g_prime(x):
        return 2 * x * cos(x**2)

    assert grad(g)(6) == g_prime(6)
コード例 #4
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_asin():

    for x in range(-1, 1):
        assert dmath.asin(x) == math.asin(x)
        assert grad(dmath.asin)(x) == approx(1 / math.sqrt(1 - x**2))
コード例 #5
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_cos():

    for x in range(-10, 10):
        assert dmath.cos(x) == math.cos(x)
        assert grad(dmath.cos)(x) == -math.sin(x)
コード例 #6
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_log():

    for x in range(1, 10):
        assert dmath.log(x) == math.log(x)
        assert grad(dmath.log)(x) == 1 / x
コード例 #7
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_exp():

    for x in range(-10, 10):
        assert dmath.exp(x) == math.exp(x) == grad(dmath.exp)(x)
コード例 #8
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_erfc():

    for x in range(-10, 10):
        assert dmath.erfc(x) == math.erfc(x)
        assert grad(
            dmath.erfc)(x) == -2 / math.sqrt(math.pi) * math.exp(-(x**2))
コード例 #9
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_cosh():

    for x in range(-10, 10):
        assert dmath.cosh(x) == math.cosh(x)
        assert grad(dmath.cosh)(x) == math.sinh(x)
コード例 #10
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_log1p():

    for x in range(0, 0.1):
        assert dmath.log1p(x) == math.log1p(x)
        assert grad(dmath.log1p)(x) == 1 / x
コード例 #11
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_sqrt():

    for x in range(0, 10):
        assert dmath.sqrt(x) == math.sqrt(x)
        assert grad(dmath.sqrt)(x) == approx(1 / (2 * math.sqrt(x)))
コード例 #12
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_atanh():

    for x in range(-1, 1):
        assert dmath.atanh(x) == math.atanh(x)
        assert grad(dmath.atanh)(x) == approx(1 / (1 - x**2))
コード例 #13
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_acosh():

    for x in range(1, 10):
        assert dmath.acosh(x) == math.acosh(x)
        assert grad(dmath.acosh)(x) == approx(1 / math.sqrt(x**2 - 1))
コード例 #14
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_asinh():

    for x in range(-10, 10):
        assert dmath.asinh(x) == math.asinh(x)
        assert grad(dmath.asinh)(x) == approx(1 / math.sqrt(x**2 + 1))
コード例 #15
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_acos():

    for x in range(-1, 1):
        assert dmath.acos(x) == math.acos(x)
        assert grad(dmath.acos)(x) == approx(-1 / math.sqrt(1 - x**2))
コード例 #16
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_atan():

    for x in range(-10, 10):
        assert dmath.atan(x) == math.atan(x)
        assert grad(dmath.atan)(x) == approx(1 / (1 + x**2))
コード例 #17
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_log2():

    for x in range(0, 10):
        assert dmath.log2(x) == math.log2(x)
        assert grad(dmath.log2)(x) == approx(1 / (math.log(2) * x))
コード例 #18
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_tanh():

    for x in range(-10, 10):
        assert dmath.tanh(x) == math.tanh(x)
        assert grad(dmath.tanh)(x) == approx(1 / math.cosh(x)**2)
コード例 #19
0
ファイル: test_functions.py プロジェクト: okkomakkonen/dmath
def test_expm1():

    for x in range(0, 0.1):
        assert dmath.expm1(x) == math.expm1(x)
        assert grad(dmath.expm1)(x) == math.expm1(x) + 1.0