isl_basic_set_factorizer: make sure group information gets updated
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 20 Jan 2011 13:42:37 +0000 (14:42 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 21 Jan 2011 21:07:54 +0000 (22:07 +0100)
We lazily keep track of which group a column belongs to.
The actual construction of the factors assumes the groups have been
updated, however, so we need to make sure that the group of each
column eventually gets updated.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
include/isl/ctx.h
isl_factorization.c
isl_test.c

index 223c61e..daf4ef7 100644 (file)
@@ -63,6 +63,7 @@ struct isl_stats {
 enum isl_error {
        isl_error_none = 0,
        isl_error_unknown,
+       isl_error_internal,
        isl_error_invalid
 };
 struct isl_ctx {
index 5ca1487..8792e22 100644 (file)
@@ -229,6 +229,8 @@ static int update_groups(struct isl_factor_groups *g, __isl_keep isl_mat *H)
                                return -1;
                }
        }
+       for (i = 1; i < H->n_col; ++i)
+               update_group(g, i);
 
        return 0;
 }
@@ -303,6 +305,9 @@ __isl_give isl_factorizer *isl_basic_set_factorizer(
                        for (j = done + g.cnt[group]; j < nvar; ++j)
                                if (g.group[j] == group)
                                        break;
+                       if (j == nvar)
+                               isl_die(bset->ctx, isl_error_internal,
+                                       "internal error", goto error);
                        g.group[j] = g.group[done + i];
                        Q = isl_mat_swap_rows(Q, done + i, j);
                        U = isl_mat_swap_cols(U, done + i, j);
index af517f1..04623a4 100644 (file)
@@ -17,6 +17,7 @@
 #include <isl/polynomial.h>
 #include <isl/union_map.h>
 #include <isl_map_private.h>
+#include <isl_factorization.h>
 
 static char *srcdir;
 
@@ -1593,6 +1594,42 @@ void test_subset(isl_ctx *ctx)
        isl_set_free(set2);
 }
 
+void test_factorize(isl_ctx *ctx)
+{
+       const char *str;
+       isl_basic_set *bset;
+       isl_factorizer *f;
+
+       str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
+           "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
+           "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
+           "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
+           "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
+           "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
+           "3i5 >= -2i0 - i2 + 3i4 }";
+       bset = isl_basic_set_read_from_str(ctx, str, 0);
+       f = isl_basic_set_factorizer(bset);
+       assert(f);
+       isl_basic_set_free(bset);
+       isl_factorizer_free(f);
+
+       str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
+           "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
+           "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
+           "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
+           "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
+           "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
+           "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
+           "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
+           "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
+           "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
+       bset = isl_basic_set_read_from_str(ctx, str, 0);
+       f = isl_basic_set_factorizer(bset);
+       assert(f);
+       isl_basic_set_free(bset);
+       isl_factorizer_free(f);
+}
+
 int main()
 {
        struct isl_ctx *ctx;
@@ -1601,6 +1638,7 @@ int main()
        assert(srcdir);
 
        ctx = isl_ctx_alloc();
+       test_factorize(ctx);
        test_subset(ctx);
        test_lift(ctx);
        test_bound(ctx);