isl_map_convex_hull: handle non full-dimensional pairs of basic sets
[platform/upstream/isl.git] / isl_test.c
index 1188628..d6b6f1b 100644 (file)
@@ -482,6 +482,9 @@ void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
 
 void test_convex_hull(struct isl_ctx *ctx)
 {
+       const char *str1, *str2;
+       isl_set *set1, *set2;
+
        test_convex_hull_case(ctx, "convex0");
        test_convex_hull_case(ctx, "convex1");
        test_convex_hull_case(ctx, "convex2");
@@ -498,6 +501,17 @@ void test_convex_hull(struct isl_ctx *ctx)
        test_convex_hull_case(ctx, "convex13");
        test_convex_hull_case(ctx, "convex14");
        test_convex_hull_case(ctx, "convex15");
+
+       str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
+              "(i0 = 1 and i1 = 0 and i2 = 1) or "
+              "(i0 = 0 and i1 = 0 and i2 = 0) }";
+       str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
+       set1 = isl_set_read_from_str(ctx, str1, -1);
+       set2 = isl_set_read_from_str(ctx, str2, -1);
+       set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
+       assert(isl_set_is_equal(set1, set2));
+       isl_set_free(set1);
+       isl_set_free(set2);
 }
 
 void test_gist_case(struct isl_ctx *ctx, const char *name)
@@ -720,6 +734,28 @@ void test_coalesce(struct isl_ctx *ctx)
        assert(isl_map_is_equal(map, map2));
        isl_map_free(map);
        isl_map_free(map2);
+
+       str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
+               "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
+               "(o0 = 0 and M >= 2 and N >= 3) or "
+               "(M = 0 and o0 = 0 and N >= 3) }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       map = isl_map_coalesce(map);
+       map2 = isl_map_read_from_str(ctx, str, -1);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
+
+       str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
+               "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
+               "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
+               "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       map = isl_map_coalesce(map);
+       map2 = isl_map_read_from_str(ctx, str, -1);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
 }
 
 void test_closure(struct isl_ctx *ctx)
@@ -851,7 +887,12 @@ void test_closure(struct isl_ctx *ctx)
        up = isl_map_intersect_range(up, dom);
        map = isl_map_union(up, right);
        map = isl_map_transitive_closure(map, &exact);
-       assert(!exact);
+       assert(exact);
+       map2 = isl_map_read_from_str(ctx,
+               "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
+               "  [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map2);
        isl_map_free(map);
 
        /* COCOA Theorem 1 counter example */
@@ -920,6 +961,37 @@ void test_closure(struct isl_ctx *ctx)
        assert(isl_map_is_equal(map, map2));
        isl_map_free(map);
        isl_map_free(map2);
+
+       str = "{[0] -> [1]; [2] -> [3]}";
+       map = isl_map_read_from_str(ctx, str, -1);
+       map = isl_map_transitive_closure(map, &exact);
+       assert(exact);
+       map2 = isl_map_read_from_str(ctx, str, -1);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
+}
+
+void test_lexmin(struct isl_ctx *ctx)
+{
+       const char *str;
+       isl_map *map;
+
+       str = "[p0, p1] -> { [] -> [] : "
+           "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
+           "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
+           "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
+           "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
+           "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
+           "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
+           "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
+           "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
+           "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
+           "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
+           "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       map = isl_map_lexmin(map);
+       isl_map_free(map);
 }
 
 int main()
@@ -940,6 +1012,7 @@ int main()
        test_gist(ctx);
        test_coalesce(ctx);
        test_closure(ctx);
+       test_lexmin(ctx);
        isl_ctx_free(ctx);
        return 0;
 }