예제 #1
0
    def f2(x, y, z):
        def g1(_z, _y):
            return _y

        def g2(_z, _y):
            return _z

        def g3(_z, _y):
            return 0

        a = switch(x < 0, g1, g3)
        b = switch(x > 0, g2, g3)
        return a(DEAD, y) + b(z, DEAD)
예제 #2
0
    def f1(x, y, z):
        def g1():
            return y

        def g2():
            return z

        def g3():
            return 0

        a = switch(x < 0, g1, g3)
        b = switch(x > 0, g2, g3)
        return a() + b()
예제 #3
0
def test_switch2(c, x, y):
    fn = switch(
        c,
        partial(scalar_sub, x),
        partial(scalar_add, x)
    )
    return fn(y)
예제 #4
0
    def f2(x, y):
        def g(a, c):
            return a + c

        def h(a, c):
            return a + c

        return switch(y < 0, g, h)(x + 1, x + 3)
예제 #5
0
    def f2(x, y, z):
        def true_branch(_y, _z):
            return _y

        def false_branch(_y, _z):
            return _z

        return switch(x < 0, true_branch, false_branch)(y, z)
예제 #6
0
    def before(x, y):
        def f1(x, y):
            return x, y

        def f2(x, y):
            return y, x

        return switch(x < 0, f1, f2)(x, y)[0]
예제 #7
0
    def f1(x, y):
        def g(a, b, c):
            return a

        def h(a, b, c):
            return c

        return switch(y < 0, g, h)(x + 1, x + 2, x + 3)
예제 #8
0
    def after(x, y):
        def f1(x, y):
            return x

        def f2(x, y):
            return y

        return switch(x < 0, f1, f2)(x, y)
예제 #9
0
파일: test_llift.py 프로젝트: tomzhang/myia
        def i(_x):
            def g():
                return _x

            def h():
                return -_x

            return switch(_x > 0, g, h)
예제 #10
0
        def after_helper(x, y, z):
            def tb(y, z):
                return scalar_mul(y, z)

            def fb(y, z):
                return scalar_add(y, z)

            return switch(x < 0, tb, fb)(y, z)
예제 #11
0
    def before(x, y):
        key = embed(x)

        def f1(x, y):
            return env_setitem(newenv, key, x * y)

        def f2(x, y):
            return env_setitem(newenv, key, x + y)

        return env_getitem(switch(x < 0, f1, f2)(x, y), key, 0)
예제 #12
0
 def before(x, y):
     return env_getitem(switch(x < 0, newenv, newenv), embed(y), 5)
예제 #13
0
 def after(x, y):
     return switch(x < 0, x[0], y[0])
예제 #14
0
 def before(x, y):
     return switch(x < 0, x, y)[0]
예제 #15
0
 def after(x, y):
     return switch(x < 0, x + y, y + x)
예제 #16
0
 def before(x, y):
     cond = x < 0
     a = switch(cond, x, y)
     b = switch(cond, y, x)
     return a + b
예제 #17
0
 def before(x, y):
     a = y * y
     return switch(x < 0, a, a)
예제 #18
0
 def after(a, b, c, d):
     x = a < 0
     return switch(x, a, d)
예제 #19
0
 def hof(fn):
     return switch(y < 0, g, fn)(x + 1, x + 2, x + 3)
예제 #20
0
파일: test_llift.py 프로젝트: tomzhang/myia
 def i():
     return switch(x > 0, g, h)
예제 #21
0
 def after(x, y):
     key = embed(y)
     return switch(x < 0, env_getitem(newenv, key, 5),
                   env_getitem(newenv, key, 5))
예제 #22
0
 def before(a, b, c, d):
     x = a < 0
     y = b < 0
     return switch(x, switch(y, a, b), switch(y, c, d))
예제 #23
0
 def before(x, y):
     return switch(True, x, y)
예제 #24
0
def test_prim_switch():
    assert switch(True, 1, 2) == 1
    assert switch(False, 1, 2) == 2
예제 #25
0
def test_switch(c, x):
    return switch(c, scalar_usub, scalar_uadd)(x)
예제 #26
0
 def before(x, y):
     return switch(False, x, y)