コード例 #1
0
def test23_exp(m):
    x = ek.linspace(m.Float, 0, 1, 10)
    ek.enable_grad(x)
    y = ek.exp(x * x)
    ek.backward(y)
    exp_x = ek.exp(ek.sqr(ek.detach(x)))
    assert ek.allclose(y, exp_x)
    assert ek.allclose(ek.grad(x), 2 * ek.detach(x) * exp_x)
コード例 #2
0
def test13_cont_func(variant_packet_rgb):
    # Test continuous 1D distribution integral against analytic result
    from mitsuba.core import ContinuousDistribution, Float

    x = ek.linspace(Float, -2, 2, 513)
    y = ek.exp(-ek.sqr(x))

    d = ContinuousDistribution([-2, 2], y)
    assert ek.allclose(d.integral(), ek.sqrt(ek.pi) * ek.erf(2.0))
    assert ek.allclose(d.eval_pdf([1]), [ek.exp(-1)])
    assert ek.allclose(d.sample([0, 0.5, 1]), [-2, 0, 2])
コード例 #3
0
ファイル: utils_render.py プロジェクト: Mine-525/mitsuba2
def check_zero_scatter(sampler, si, bs, channel, active):
    """Check a ray whether go through medium without scattering or not"""

    sigma_t = index_spectrum(bs.sigma_t, channel)

    # Ray passes through medium w/o scattering?
    is_zero_scatter = (sampler.next_1d(active) >
                       Float(1) - ek.exp(-sigma_t * si.t)) & active

    return is_zero_scatter
コード例 #4
0
def exp_(a0):
    if not a0.IsFloat:
        raise Exception("exp(): requires floating point operands!")
    ar, sr = _check1(a0)
    if not a0.IsSpecial:
        for i in range(sr):
            ar[i] = _ek.exp(a0[i])
    elif a0.IsComplex:
        s, c = _ek.sincos(a0.imag)
        exp_r = _ek.exp(a0.real)
        ar.real = exp_r * c
        ar.imag = exp_r * s
    elif a0.IsQuaternion:
        qi = a0.imag
        ri = _ek.norm(qi)
        exp_w = _ek.exp(a0.real)
        s, c = _ek.sincos(ri)
        ar.imag = qi * (s * exp_w / ri)
        ar.real = c * exp_w
    else:
        raise Exception("exp(): unsupported array type!")
    return ar
コード例 #5
0
def pow_(a0, a1):
    if not a0.IsFloat:
        raise Exception("pow(): requires floating point operands!")
    if not a0.IsSpecial:
        if isinstance(a1, int) or isinstance(a1, float):
            ar, sr = _check1(a0)
            for i in range(sr):
                ar[i] = _ek.pow(a0[i], a1)
        else:
            ar, sr = _check2(a0, a1)
            for i in range(sr):
                ar[i] = _ek.pow(a0[i], a1[i])
    else:
        return _ek.exp(_ek.log(a0) * a1)
    return ar
コード例 #6
0
ファイル: test_complex.py プロジェクト: wjakob/enoki
def test10_math_explog():
    for i in range(-5, 5):
        for j in range(-5, 5):
            if i != 0 or j != 0:
                a = ek.log(C(i, j))
                b = C(cmath.log(complex(i, j)))
                assert ek.allclose(a, b)

                a = ek.log2(C(i, j))
                b = C(cmath.log(complex(i, j)) / cmath.log(2))
                assert ek.allclose(a, b)

            a = ek.exp(C(i, j))
            b = C(cmath.exp(complex(i, j)))
            assert ek.allclose(a, b)

            a = ek.exp2(C(i, j))
            b = C(cmath.exp(complex(i, j) * cmath.log(2)))
            assert ek.allclose(a, b)

            a = ek.pow(C(2, 3), C(i, j))
            b = C(complex(2, 3)**complex(i, j))
            assert ek.allclose(a, b)
コード例 #7
0
def rlgamma(a, x):
    'Regularized lower incomplete gamma function based on CEPHES'

    eps = 1e-15
    big = 4.503599627370496e15
    biginv = 2.22044604925031308085e-16

    if a < 0 or x < 0:
        raise "out of range"

    if x == 0:
        return 0

    ax = (a * ek.log(x)) - x - ek.lgamma(a)

    if ax < -709.78271289338399:
        return 1.0 if a < x else 0.0

    if x <= 1 or x <= a:
        r2 = a
        c2 = 1
        ans2 = 1

        while True:
            r2 = r2 + 1
            c2 = c2 * x / r2
            ans2 += c2

            if c2 / ans2 <= eps:
                break

        return ek.exp(ax) * ans2 / a

    c = 0
    y = 1 - a
    z = x + y + 1
    p3 = 1
    q3 = x
    p2 = x + 1
    q2 = z * x
    ans = p2 / q2

    while True:
        c += 1
        y += 1
        z += 2
        yc = y * c
        p = (p2 * z) - (p3 * yc)
        q = (q2 * z) - (q3 * yc)

        if q != 0:
            nextans = p / q
            error = ek.abs((ans - nextans) / nextans)
            ans = nextans
        else:
            error = 1

        p3 = p2
        p2 = p
        q3 = q2
        q2 = q

        # normalize fraction when the numerator becomes large
        if ek.abs(p) > big:
            p3 *= biginv
            p2 *= biginv
            q3 *= biginv
            q2 *= biginv

        if error <= eps:
            break;

    return 1 - ek.exp(ax) * ans
コード例 #8
0
ファイル: utils_render.py プロジェクト: Mine-525/mitsuba2
def reduced_albedo_to_effective_albedo(reduced_albedo):
    return -ek.log(1.0 - reduced_albedo * (1.0 - ek.exp(-8.0))) / 8.0
コード例 #9
0
def test06_exp():
    assert ek.allclose(ek.exp(Q(1, 2, 3, 4)),
                       Q(-8.24003, -16.4801, -24.7201, -45.0598))