add isl_basic_{set,map}_from_constraint_matrices
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 21 Jul 2010 19:19:11 +0000 (21:19 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 25 Sep 2010 16:49:47 +0000 (18:49 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl_map.h
include/isl_set.h
isl_map.c

index 6407be9..dfb22f3 100644 (file)
@@ -806,6 +806,29 @@ Or, alternatively,
        bset = isl_basic_set_read_from_str(ctx,
                "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}", -1);
 
+A basic set or relation can also be constructed from two matrices
+describing the equalities and the inequalities.
+
+       __isl_give isl_basic_set *isl_basic_set_from_constraint_matrices(
+               __isl_take isl_dim *dim,
+               __isl_take isl_mat *eq, __isl_take isl_mat *ineq,
+               enum isl_dim_type c1,
+               enum isl_dim_type c2, enum isl_dim_type c3,
+               enum isl_dim_type c4);
+       __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
+               __isl_take isl_dim *dim,
+               __isl_take isl_mat *eq, __isl_take isl_mat *ineq,
+               enum isl_dim_type c1,
+               enum isl_dim_type c2, enum isl_dim_type c3,
+               enum isl_dim_type c4, enum isl_dim_type c5);
+
+The C<isl_dim_type> arguments indicate the order in which
+different kinds of variables appear in the input matrices
+and should be a permutation of C<isl_dim_cst>, C<isl_dim_param>,
+C<isl_dim_set> and C<isl_dim_div> for sets and
+of C<isl_dim_cst>, C<isl_dim_param>,
+C<isl_dim_in>, C<isl_dim_out> and C<isl_dim_div> for relations.
+
 =head2 Inspecting Sets and Relations
 
 Usually, the user should not have to care about the actual constraints
index bd2c2a0..782d337 100644 (file)
@@ -442,6 +442,11 @@ __isl_give isl_mat *isl_basic_map_inequalities_matrix(
                __isl_keep isl_basic_map *bmap, enum isl_dim_type c1,
                enum isl_dim_type c2, enum isl_dim_type c3,
                enum isl_dim_type c4, enum isl_dim_type c5);
+__isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
+       __isl_take isl_dim *dim,
+       __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1,
+       enum isl_dim_type c2, enum isl_dim_type c3,
+       enum isl_dim_type c4, enum isl_dim_type c5);
 
 #if defined(__cplusplus)
 }
index f49b791..01a86dc 100644 (file)
@@ -361,6 +361,11 @@ __isl_give isl_map *isl_set_lex_gt_set(__isl_take isl_set *set1,
 
 int isl_set_size(__isl_keep isl_set *set);
 
+__isl_give isl_basic_set *isl_basic_set_from_constraint_matrices(
+       __isl_take isl_dim *dim,
+       __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1,
+       enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4);
+
 #if defined(__cplusplus)
 }
 #endif
index fa902f0..cfc9a98 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -7555,3 +7555,88 @@ __isl_give isl_mat *isl_basic_map_inequalities_matrix(
 
        return mat;
 }
+
+__isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
+       __isl_take isl_dim *dim,
+       __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1,
+       enum isl_dim_type c2, enum isl_dim_type c3,
+       enum isl_dim_type c4, enum isl_dim_type c5)
+{
+       enum isl_dim_type c[5] = { c1, c2, c3, c4, c5 };
+       isl_basic_map *bmap;
+       unsigned total;
+       unsigned extra;
+       int i, j, k, l;
+       int pos;
+
+       if (!dim || !eq || !ineq)
+               goto error;
+
+       if (eq->n_col != ineq->n_col)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "equalities and inequalities matrices should have "
+                       "same number of columns", goto error);
+
+       total = 1 + isl_dim_total(dim);
+
+       if (eq->n_col < total)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "number of columns too small", goto error);
+
+       extra = eq->n_col - total;
+
+       bmap = isl_basic_map_alloc_dim(isl_dim_copy(dim), extra,
+                                      eq->n_row, ineq->n_row);
+       if (!bmap)
+               goto error;
+       for (i = 0; i < extra; ++i)
+               if (isl_basic_map_alloc_div(bmap) < 0)
+                       goto error;
+       for (i = 0; i < eq->n_row; ++i) {
+               l = isl_basic_map_alloc_equality(bmap);
+               if (l < 0)
+                       goto error;
+               for (j = 0, pos = 0; j < 5; ++j) {
+                       int off = isl_basic_map_offset(bmap, c[j]);
+                       for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) {
+                               isl_int_set(bmap->eq[l][off + k], 
+                                           eq->row[i][pos]);
+                               ++pos;
+                       }
+               }
+       }
+       for (i = 0; i < ineq->n_row; ++i) {
+               l = isl_basic_map_alloc_inequality(bmap);
+               if (l < 0)
+                       goto error;
+               for (j = 0, pos = 0; j < 5; ++j) {
+                       int off = isl_basic_map_offset(bmap, c[j]);
+                       for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) {
+                               isl_int_set(bmap->ineq[l][off + k], 
+                                           ineq->row[i][pos]);
+                               ++pos;
+                       }
+               }
+       }
+
+       isl_dim_free(dim);
+       isl_mat_free(eq);
+       isl_mat_free(ineq);
+
+       return bmap;
+error:
+       isl_dim_free(dim);
+       isl_mat_free(eq);
+       isl_mat_free(ineq);
+       return NULL;
+}
+
+__isl_give isl_basic_set *isl_basic_set_from_constraint_matrices(
+       __isl_take isl_dim *dim,
+       __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1,
+       enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
+{
+       return (isl_basic_set*)
+           isl_basic_map_from_constraint_matrices(dim, eq, ineq,
+                                                  c1, c2, c3, c4, isl_dim_in);
+}