def test_simple(gen):
    (x, y) = (hl.Var(), hl.Var())
    target = hl.get_jit_target_from_environment()
    b_in = hl.Buffer(hl.UInt(8), [2, 2])
    b_in.fill(123)
    f_in = hl.Func('f')
    f_in[(x, y)] = (x + y)
    f = gen(target, b_in, f_in, 3.5)
    _realize_and_check(f)
    f = gen(target, buffer_input=b_in, func_input=f_in, float_arg=3.5)
    _realize_and_check(f)
    f = gen(target, float_arg=3.5, buffer_input=b_in, func_input=f_in)
    _realize_and_check(f)
    k = 42
    f = gen(target, b_in, f_in, 3.5, offset=k)
    _realize_and_check(f, k)
    f = gen(target, offset=k, buffer_input=b_in, func_input=f_in, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, offset=k, func_input=f_in, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, func_input=f_in, offset=k, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, float_arg=3.5, func_input=f_in, offset=k)
    _realize_and_check(f, k)
    try:
        f = gen(target, b_in, f_in, float_arg=3.5)
    except RuntimeError as e:
        assert ('Cannot use both positional and keyword arguments for inputs.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, 3.5, 4)
    except RuntimeError as e:
        assert ('Expected exactly 3 positional args for inputs, but saw 4.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in)
    except RuntimeError as e:
        assert ('Expected exactly 3 positional args for inputs, but saw 2.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, hl.f32(3.141592), 'happy', k)
    except RuntimeError as e:
        assert ('Unable to cast Python instance' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, float_arg='bogus')
    except RuntimeError as e:
        assert ('Unable to cast Python instance' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, 3.5, float_arg=4.5)
    except RuntimeError as e:
        assert ('Cannot use both positional and keyword arguments for inputs.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, buffer_input=b_in, float_arg=3.5, offset=k, funk_input=f_in)
    except RuntimeError as e:
        assert ('Expected exactly 3 keyword args for inputs, but saw 2.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, buffer_input=b_in, float_arg=3.5, offset=k, func_input=f_in, nonexistent_generator_param='wat')
    except RuntimeError as e:
        assert ('has no GeneratorParam named: nonexistent_generator_param' in str(e))
    else:
        assert False, 'Did not see expected exception!'
def test_simple(gen):
    (x, y) = (hl.Var(), hl.Var())
    target = hl.get_jit_target_from_environment()
    b_in = hl.Buffer(hl.UInt(8), [2, 2])
    b_in.fill(123)
    f_in = hl.Func('f')
    f_in[(x, y)] = (x + y)
    f = gen(target, b_in, f_in, 3.5)
    _realize_and_check(f)
    f = gen(target, buffer_input=b_in, func_input=f_in, float_arg=3.5)
    _realize_and_check(f)
    f = gen(target, float_arg=3.5, buffer_input=b_in, func_input=f_in)
    _realize_and_check(f)
    k = 42
    f = gen(target, b_in, f_in, 3.5, offset=k)
    _realize_and_check(f, k)
    f = gen(target, offset=k, buffer_input=b_in, func_input=f_in, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, offset=k, func_input=f_in, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, func_input=f_in, offset=k, float_arg=3.5)
    _realize_and_check(f, k)
    f = gen(target, buffer_input=b_in, float_arg=3.5, func_input=f_in, offset=k)
    _realize_and_check(f, k)
    try:
        f = gen(target, b_in, f_in, float_arg=3.5)
    except RuntimeError as e:
        assert ('Cannot use both positional and keyword arguments for inputs.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, 3.5, 4)
    except RuntimeError as e:
        assert ('Expected exactly 3 positional args for inputs, but saw 4.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in)
    except RuntimeError as e:
        assert ('Expected exactly 3 positional args for inputs, but saw 2.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, hl.f32(3.141592), 'happy', k)
    except RuntimeError as e:
        assert ('Unable to cast Python instance' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, float_arg='bogus')
    except RuntimeError as e:
        assert ('Unable to cast Python instance' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, b_in, f_in, 3.5, float_arg=4.5)
    except RuntimeError as e:
        assert ('Cannot use both positional and keyword arguments for inputs.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, buffer_input=b_in, float_arg=3.5, offset=k, funk_input=f_in)
    except RuntimeError as e:
        assert ('Expected exactly 3 keyword args for inputs, but saw 2.' in str(e))
    else:
        assert False, 'Did not see expected exception!'
    try:
        f = gen(target, buffer_input=b_in, float_arg=3.5, offset=k, func_input=f_in, nonexistent_generator_param='wat')
    except RuntimeError as e:
        assert ('has no GeneratorParam named: nonexistent_generator_param' in str(e))
    else:
        assert False, 'Did not see expected exception!'