Exemplo n.º 1
0
 def test_missing_var_in_func(self, compiler_bin):
     prog = inspect.cleandoc("""
         def f() {
             y + 2;
         }
     """)
     assert run(compiler_bin, prog).startswith("TYPE ERROR")
Exemplo n.º 2
0
    def test_sum_return(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f (a: float) {a;}

            m = Matrix[[1., 2.], [3., 4.]];
            f(sum(m));
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 3
0
    def test_num_rows_num_cols_return(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f (a: int) {a;}

            m = Matrix[[1., 2.], [3., 4.]];
            f(numcols(m) + numrows(m));
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 4
0
    def test_sum_return(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f (a: float) {a;}

            v = Vector[1., 2., 3., 4.];
            f(sum(v));
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 5
0
 def test_incompatible_elem_accessor(self, compiler_bin):
     prog = inspect.cleandoc("""
         def f(a) {
             a[1, 1];
         }
         f(Vector[5]);
     """)
     assert run(compiler_bin, prog).find("ERROR") != -1
 def test_vector_mul(self, compiler_bin):
     prog = inspect.cleandoc("""
         x:track_grad = Vector[3., 6., 9.];
         backward(x * 2);
         grad(x);
     """)
     assert run(compiler_bin,
                prog).startswith("SUCCESS: Vector[2., 2., 2.]")
 def test_matrix_stress_test_dims(self, compiler_bin):
     prog = inspect.cleandoc("""
         Matrix[[1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]] @ Matrix[[1., 2.], [3., 4.], [5., 6.],
             [7., 8.], [9., 10.], [11., 12.], [13., 14.], [15., 16.], [17., 18.], [19., 20.]];
     """)
     assert "".join(
         run(compiler_bin,
             prog).split()).startswith(f'SUCCESS:Matrix[[715.,770.]]')
 def test_no_semicolons_func(self, compiler_bin):
     prog = inspect.cleandoc("""
         def func (a: int, b: int) {
           a + b
           2 * a
         }
     """)
     assert run(compiler_bin, prog).startswith("PARSE ERROR")
Exemplo n.º 9
0
 def test_single_arg_inference_no_constraints(self, compiler_bin, target):
     prog = inspect.cleandoc(f"""
         def f(a) {{
             a;
         }}
         f({target});
     """)
     assert run(compiler_bin, prog).startswith(f'SUCCESS: {target}')
 def test_binop_vector_by_copy(self, compiler_bin):
     prog = inspect.cleandoc("""
         x = Vector[1., 2., 3.];
         y = Vector[1., 2., 3.];
         x * y;
         sum(x) + sum(y);
     """)
     assert run(compiler_bin, prog).startswith(f'SUCCESS: 12.')
Exemplo n.º 11
0
 def test_incompatible_binop(self, compiler_bin):
     prog = inspect.cleandoc("""
         def f(a, b) {
             a + b;
         }
         f(1, Vector[1.]);
     """)
     assert run(compiler_bin, prog).find("ERROR") != -1
 def test_multiline_comments(self, compiler_bin):
     prog = inspect.cleandoc("""
         (* There's a comment here with some invalid syntax! 3.x
             and it even goes onto another line! *)
         x = 3;
         x + 3;
     """)
     assert run(compiler_bin, prog).startswith("SUCCESS")
 def test_trailing_semicolon_on_func(self, compiler_bin):
     prog = inspect.cleandoc("""
         def func (a: int, b: int) {
           a + b;
           2 * a;
         };
     """)
     assert run(compiler_bin, prog).startswith("PARSE ERROR")
 def test_no_types_func(self, compiler_bin):
     prog = inspect.cleandoc("""
         def func (a, b) {
           a + b;
           2 * a;
         }
     """)
     assert run(compiler_bin, prog).startswith("PARSE ERROR")
Exemplo n.º 15
0
    def test_num_rows_num_cols_return(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f (a: int) {a;}

            v = Vector[1., 2., 3., 4.];
            f(numcols(v) + numrows(v));
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 16
0
 def test_func_signature_rebinding(self, compiler_bin):
     prog = inspect.cleandoc("""
         def f(a) {
             a;
         }
         f(1);
         f(1.0);
     """)
     assert run(compiler_bin, prog).find("ERROR") != -1
    def test_builtin_shadowing_override(self, compiler_bin):
        prog = inspect.cleandoc("""
            def numrows(t: Vector) {
                t[0,];
            }

            numrows(Vector[1., 2., 3., 4.]) + 2;
        """)
        assert run(compiler_bin, prog).startswith("PARSE ERROR")
Exemplo n.º 18
0
    def test_func_wrong_types(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: int) {
                a + b;
            }

            f(1, Vector[10.]);
        """)
        assert run(compiler_bin, prog).startswith("TYPE ERROR")
Exemplo n.º 19
0
    def test_no_arg_func_with_call(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f() {
                5;
            }

            f() + 10;
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 20
0
 def test_single_arg_inference_with_binop_constraints(
         self, compiler_bin, t1, t2, res):
     prog = inspect.cleandoc(f"""
         def f(a) {{
             a + {t2};
         }}
         f({t1});
     """)
     assert run(compiler_bin, prog).startswith(f'SUCCESS: {res}')
    def test_func_app_with_arg_exprs(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: float) {
                a + b;
            }

            f(3 + 2, Vector[10][0,]);
        """)
        assert run(compiler_bin, prog).startswith('SUCCESS: 15')
    def test_func_app_with_args(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: int) {
                a + b;
            }

            f(5, 10);
        """)
        assert run(compiler_bin, prog).startswith('SUCCESS: 15')
    def test_no_args_func_app(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f() {
                10;
            }

            f();
        """)
        assert run(compiler_bin, prog).startswith('SUCCESS: 10')
Exemplo n.º 24
0
    def test_multiple_arg_func_with_call(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: Vector, c: Vector, d: float) {
                a + b[,0] + c[0,] + d;
            }

            f(5 + 5, Vector[10., 20.], Vector[10., 20.], 1.0) + 10;
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 25
0
    def test_single_arg_func_with_call(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int) {
                a;
            }

            f(8) + 10;
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")
Exemplo n.º 26
0
 def test_single_arg_inference_with_elem_accessor_constraints(
         self, compiler_bin):
     prog = inspect.cleandoc("""
         def f(a) {
             a[0,0];
         }
         f(Matrix[[10.]]);
     """)
     assert run(compiler_bin, prog).startswith('SUCCESS: 10.')
Exemplo n.º 27
0
    def test_func_wrong_num_types(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: float) {
                a + b;
            }

            f(2.5, 1);
        """)
        assert run(compiler_bin, prog).startswith("TYPE ERROR")
    def test_func_app_in_expr(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: int, b: int) {
                a + b;
            }

            f(5, 10) + 5;
        """)
        assert run(compiler_bin, prog).startswith('SUCCESS: 20')
Exemplo n.º 29
0
    def test_missing_func(self, compiler_bin):
        prog = inspect.cleandoc("""
            def f(a: Vector, b: Vector) {
                a + b;
            }

            g(1);
        """)
        assert run(compiler_bin, prog).startswith("TYPE ERROR")
    def test_func_app(self, compiler_bin):
        prog = inspect.cleandoc("""
            def g(a: int, b: int, c: int) {
              b * 2;
              a + b + c;
            }

            g(1, 2, 3);
        """)
        assert run(compiler_bin, prog).startswith("SUCCESS")