def test_grad_builtin_untracked_var_set_to_tracked_var(self, compiler_bin): prog = inspect.cleandoc(""" x:track_grad = 10; y = x; grad(y); """) assert run_typechecker(compiler_bin, prog).find("ERROR") != -1
def test_grad_builtin(self, compiler_bin): prog = inspect.cleandoc(""" x:track_grad = 5.; backward(x); grad(x); """) assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_backward_builtin_intermediate_var(self, compiler_bin): prog = inspect.cleandoc(""" x:track_grad = 5.; y = 2. * x; z = y + 5.; backward(z); """) assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_grad_builtin_bad_target_expr_with_func(self, compiler_bin): prog = inspect.cleandoc(""" def f() { a:track_grad = 10; a; } grad(f()); """) assert run_typechecker(compiler_bin, prog).find("ERROR") != -1
def test_grad_builtin_ret_type(self, compiler_bin): prog = inspect.cleandoc(""" def f(a: float) { a; } x:track_grad = 5.; backward(x); f(grad(x)); """) assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_rand_type(self, compiler_bin): prog = inspect.cleandoc(""" def f(a: Matrix) {a[0,0];} f(fill(2, 2, 1.0)); """) assert run_typechecker(compiler_bin, prog).startswith('SUCCESS')
def test_track_grad_bad_target(self, compiler_bin, target): prog = inspect.cleandoc(f'{target}:track_grad;') assert run_typechecker(compiler_bin, prog).find("ERROR") != -1
def test_backward_builtin_outside_of_backprop(self, compiler_bin): prog = inspect.cleandoc(f""" x:track_grad = sum(Vector[1., 2.]); backward(x); """) assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_backward_builtin_arbitrary_expr(self, compiler_bin): prog = inspect.cleandoc(""" x:track_grad = 5.; backward(2. * x + 5.); """) assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_track_grad_tag(self, compiler_bin): prog = inspect.cleandoc('x:track_grad = 5.;') assert run_typechecker(compiler_bin, prog).startswith("SUCCESS")
def test_grad_builtin_bad_target_expr_with_var(self, compiler_bin): prog = inspect.cleandoc(""" x:track_grad = 10; grad(x * 2); """) assert run_typechecker(compiler_bin, prog).find("ERROR") != -1
def test_grad_builtin_bad_target_expr(self, compiler_bin): prog = inspect.cleandoc('grad(4 + 6);') assert run_typechecker(compiler_bin, prog).find("ERROR") != -1
def test_backward_builtin_stmt_target(self, compiler_bin, target): prog = inspect.cleandoc(f'backward({target});') assert run_typechecker(compiler_bin, prog).find("ERROR") != -1