isl_tab_pip.c: fix typo in comment
[platform/upstream/isl.git] / isl_test.c
index 2f19799..d65ae0e 100644 (file)
@@ -10,8 +10,8 @@
 #include <assert.h>
 #include <stdio.h>
 #include <limits.h>
+#include <isl_ctx_private.h>
 #include <isl_map_private.h>
-#include <isl/ctx.h>
 #include <isl/set.h>
 #include <isl/flow.h>
 #include <isl/constraint.h>
@@ -30,6 +30,17 @@ void test_parse_map(isl_ctx *ctx, const char *str)
        isl_map_free(map);
 }
 
+void test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
+{
+       isl_map *map, *map2;
+
+       map = isl_map_read_from_str(ctx, str, -1);
+       map2 = isl_map_read_from_str(ctx, str2, -1);
+       assert(map && map2 && isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
+}
+
 void test_parse_pwqp(isl_ctx *ctx, const char *str)
 {
        isl_pw_qpolynomial *pwqp;
@@ -42,7 +53,7 @@ void test_parse_pwqp(isl_ctx *ctx, const char *str)
 void test_parse(struct isl_ctx *ctx)
 {
        isl_map *map, *map2;
-       const char *str;
+       const char *str, *str2;
 
        str = "{ [i] -> [-i] }";
        map = isl_map_read_from_str(ctx, str, -1);
@@ -58,6 +69,15 @@ void test_parse(struct isl_ctx *ctx)
        test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
                                "p1 = 1 && (y1 <= y2 || y2 = 0) }");
 
+       str = "{ [x,y]  : [([x/2]+y)/3] >= 1 }";
+       str2 = "{ [x, y] : 2y >= 6 - x }";
+       test_parse_map_equal(ctx, str, str2);
+
+       test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
+                                 "{ [x,y] : x <= y, 2*y + 3 }");
+       str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
+       test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }", str);
+
        str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
        map = isl_map_read_from_str(ctx, str, -1);
        str = "{ [new, old] -> [o0, o1] : "
@@ -77,7 +97,12 @@ void test_parse(struct isl_ctx *ctx)
        isl_map_free(map);
        isl_map_free(map2);
 
+       str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
+       str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
+       test_parse_map_equal(ctx, str, str2);
+
        test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
+       test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
 }
 
 void test_read(struct isl_ctx *ctx)
@@ -650,7 +675,33 @@ void test_gist_case(struct isl_ctx *ctx, const char *name)
 
 void test_gist(struct isl_ctx *ctx)
 {
+       const char *str;
+       isl_basic_set *bset1, *bset2;
+
        test_gist_case(ctx, "gist1");
+
+       str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
+           "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
+           "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
+           "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
+           "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
+           "16e0 >= 16 + 16p6 + 15p10 and  p2 <= 15 and p3 >= 0 and "
+           "p3 <= 31 and  p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
+           "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
+           "p10 <= 15 and p10 <= -1 + p0 - p6) }";
+       bset1 = isl_basic_set_read_from_str(ctx, str, -1);
+       str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
+           "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
+           "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
+           "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
+           "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
+           "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
+           "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
+           "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
+       bset2 = isl_basic_set_read_from_str(ctx, str, -1);
+       bset1 = isl_basic_set_gist(bset1, bset2);
+       assert(bset1 && bset1->n_div == 0);
+       isl_basic_set_free(bset1);
 }
 
 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
@@ -906,6 +957,12 @@ void test_coalesce(struct isl_ctx *ctx)
        test_coalesce_set(ctx,
                "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
        test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
+       test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
+       test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
+       test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
+       test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
+       test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
+       test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
 }
 
 void test_closure(struct isl_ctx *ctx)
@@ -918,11 +975,11 @@ void test_closure(struct isl_ctx *ctx)
 
        /* COCOA example 1 */
        map = isl_map_read_from_str(ctx,
-               "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
+               "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
                        "1 <= i and i < n and 1 <= j and j < n or "
                        "i2 = i + 1 and j2 = j - 1 and "
                        "1 <= i and i < n and 2 <= j and j <= n }", -1);
-       map = isl_map_power(map, 1, &exact);
+       map = isl_map_power(map, &exact);
        assert(exact);
        isl_map_free(map);
 
@@ -988,14 +1045,14 @@ void test_closure(struct isl_ctx *ctx)
 
        /* COCOA Fig.2 right */
        map = isl_map_read_from_str(ctx,
-               "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
+               "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
                        "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
                        "j <= n or "
                        "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
                        "j <= 2 i - 4 and j <= n - 3 or "
                        "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
                        "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
-       map = isl_map_power(map, 1, &exact);
+       map = isl_map_power(map, &exact);
        assert(exact);
        isl_map_free(map);
 
@@ -1449,20 +1506,54 @@ void test_dep(struct isl_ctx *ctx)
        isl_flow_free(flow);
 }
 
-void test_sv(struct isl_ctx *ctx)
+int test_sv(isl_ctx *ctx)
 {
        const char *str;
        isl_map *map;
+       isl_union_map *umap;
+       int sv;
 
        str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
        map = isl_map_read_from_str(ctx, str, -1);
-       assert(isl_map_is_single_valued(map));
+       sv = isl_map_is_single_valued(map);
        isl_map_free(map);
+       if (sv < 0)
+               return -1;
+       if (!sv)
+               isl_die(ctx, isl_error_internal,
+                       "map not detected as single valued", return -1);
 
        str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
        map = isl_map_read_from_str(ctx, str, -1);
-       assert(!isl_map_is_single_valued(map));
+       sv = isl_map_is_single_valued(map);
        isl_map_free(map);
+       if (sv < 0)
+               return -1;
+       if (sv)
+               isl_die(ctx, isl_error_internal,
+                       "map detected as single valued", return -1);
+
+       str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
+       umap = isl_union_map_read_from_str(ctx, str);
+       sv = isl_union_map_is_single_valued(umap);
+       isl_union_map_free(umap);
+       if (sv < 0)
+               return -1;
+       if (!sv)
+               isl_die(ctx, isl_error_internal,
+                       "map not detected as single valued", return -1);
+
+       str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
+       umap = isl_union_map_read_from_str(ctx, str);
+       sv = isl_union_map_is_single_valued(umap);
+       isl_union_map_free(umap);
+       if (sv < 0)
+               return -1;
+       if (sv)
+               isl_die(ctx, isl_error_internal,
+                       "map detected as single valued", return -1);
+
+       return 0;
 }
 
 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
@@ -1637,6 +1728,12 @@ void test_bound(isl_ctx *ctx)
        pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
        assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
        isl_pw_qpolynomial_fold_free(pwf);
+
+       str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
+       pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
+       pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
+       assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 1);
+       isl_pw_qpolynomial_fold_free(pwf);
 }
 
 void test_lift(isl_ctx *ctx)
@@ -1722,7 +1819,8 @@ int main()
        test_parse(ctx);
        test_pwqp(ctx);
        test_lex(ctx);
-       test_sv(ctx);
+       if (test_sv(ctx) < 0)
+               goto error;
        test_bijective(ctx);
        test_dep(ctx);
        test_read(ctx);
@@ -1739,4 +1837,7 @@ int main()
        test_lexmin(ctx);
        isl_ctx_free(ctx);
        return 0;
+error:
+       isl_ctx_free(ctx);
+       return -1;
 }