Example #1
0
    def test_composite_clone_float32(self):
        w = int8()
        x = float16()
        y = float32()
        cz = Composite([x, y], [tanh(x + cast(y, "float16"))])
        c = Composite(
            [w, x, y],
            [
                cz(x, y)
                - cz(x, y) ** 2
                + cast(x, "int16")
                + cast(x, "float32")
                + cast(w, "float16")
                - constant(np.float16(1.0))
            ],
        )
        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)

        v = uint8()
        w = float16()
        x = float16()
        y = float16()
        z = float16()

        c = Composite([v, w, x, y, z], [switch(v, mul(w, x, y), z)])

        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)
Example #2
0
    def test_composite_clone_float32(self):
        def has_f16(comp):
            if any(v.type == float16 for v in comp.fgraph.variables):
                return True
            return False

        w = int8()
        x = float16()
        y = float32()
        cz = Composite([x, y], [tanh(x + cast(y, "float16"))])
        c = Composite(
            [w, x, y],
            [
                cz(x, y) - cz(x, y)**2 + cast(x, "int16") +
                cast(x, "float32") + cast(w, "float16") -
                constant(np.float16(1.0))
            ],
        )
        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)

        v = uint8()
        w = float16()
        x = float16()
        y = float16()
        z = float16()

        c = Composite([v, w, x, y, z], [switch(v, mul(w, x, y), z)])

        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)
Example #3
0
 def test_straightforward(self):
     x, y, z = inputs()
     e = mul(add(x, y), div_proxy(x, y))
     C = Composite([x, y], [e])
     c = C.make_node(x, y)
     # print c.c_code(['x', 'y'], ['z'], dict(id = 0))
     g = FunctionGraph([x, y], [c.out])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 1.5
Example #4
0
 def test_straightforward(self):
     x, y, z = inputs()
     e = mul(add(x, y), div_proxy(x, y))
     C = Composite([x, y], [e])
     c = C.make_node(x, y)
     # print c.c_code(['x', 'y'], ['z'], dict(id = 0))
     g = FunctionGraph([x, y], [c.out])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 1.5
Example #5
0
 def test_with_constants(self):
     x, y, z = inputs()
     e = mul(add(70.0, y), div_proxy(x, y))
     C = Composite([x, y], [e])
     c = C.make_node(x, y)
     assert "70.0" in c.op.c_code(c, 'dummy', ['x', 'y'], ['z'], dict(id=0))
     # print c.c_code(['x', 'y'], ['z'], dict(id = 0))
     g = FunctionGraph([x, y], [c.out])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 36.0
Example #6
0
 def test_with_constants(self):
     x, y, z = inputs()
     e = mul(add(70.0, y), div_proxy(x, y))
     C = Composite([x, y], [e])
     c = C.make_node(x, y)
     assert "70.0" in c.op.c_code(c, 'dummy', ['x', 'y'], ['z'], dict(id = 0))
     # print c.c_code(['x', 'y'], ['z'], dict(id = 0))
     g = FunctionGraph([x, y], [c.out])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 36.0
Example #7
0
 def test_with_constants(self):
     x, y, z = floats("xyz")
     e = mul(add(70.0, y), true_div(x, y))
     C = Composite([x, y], [e])
     c = C.make_node(x, y)
     assert "70.0" in c.op.c_code(c, "dummy", ["x", "y"], ["z"], dict(id=0))
     # print c.c_code(['x', 'y'], ['z'], dict(id = 0))
     g = FunctionGraph([x, y], [c.out])
     fn = DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 36.0
Example #8
0
    def test_composite_clone_float32(self):
        w = int8()
        x = float16()
        y = float32()
        cz = Composite([x, y], [tanh(x + cast(y, 'float16'))])
        c = Composite([w, x, y], [cz(x, y) - cz(x, y)**2 +
                                  cast(x, 'int16') + cast(x, 'float32') +
                                  cast(w, 'float16') -
                                  constant(np.float16(1.0))])
        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)

        v = uint8()
        w = float16()
        x = float16()
        y = float16()
        z = float16()

        c = Composite([v, w, x, y, z], [switch(v, mul(w, x, y), z)])

        assert has_f16(c)
        nc = c.clone_float32()
        assert not has_f16(nc)
Example #9
0
 def test_straightforward(self):
     x, y, z = inputs()
     e = mul(add(x, y), div_proxy(x, y))
     g = FunctionGraph([x, y], [e])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 1.5
Example #10
0
 def test_straightforward(self):
     x, y, z = inputs()
     e = mul(add(x, y), div_proxy(x, y))
     g = FunctionGraph([x, y], [e])
     fn = gof.DualLinker().accept(g).make_function()
     assert fn(1.0, 2.0) == 1.5
Example #11
0
def test_mul_add_div_proxy():
    x, y, z = floats("xyz")
    e = mul(add(x, y), div_proxy(x, y))
    g = FunctionGraph([x, y], [e])
    fn = gof.DualLinker().accept(g).make_function()
    assert fn(1.0, 2.0) == 1.5