def test_misused_or(): x = hl.Var('x') y = hl.Var('y') f = hl.Func('f') try: f[x, y] = hl.print_when(x == 0 or y == 0, 0, "x=", x, "y=", y) f.realize(10, 10) except ValueError as e: assert 'cannot be converted to a bool' in str(e) else: assert False, 'Did not see expected exception!'
def test_print_when(): x = hl.Var('x') f = hl.Func('f') f[x] = hl.print_when(x == 3, hl.cast(hl.UInt(8), x * x), 'is result at', x) buf = hl.Buffer(hl.UInt(8), [10]) output = StringIO() with _redirect_stdout(output): f.realize(buf) expected = '9 is result at 3\n' actual = output.getvalue() assert expected == actual, "Expected: %s, Actual: %s" % (expected, actual)
def test_print_when(): x = hl.Var('x') f = hl.Func('f') f[x] = hl.print_when(x == 3, hl.cast(hl.UInt(8), x*x), 'is result at', x) buf = hl.Buffer(hl.UInt(8), 10) output = StringIO() with _redirect_stdout(output): f.realize(buf) expected = '9 is result at 3\n' actual = output.getvalue() assert expected == actual, "Expected: %s, Actual: %s" % (expected, actual) return