From f581cf983404ee67d06ecfaa6fe6349b916fa739 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 21 Jul 2010 21:19:11 +0200 Subject: [PATCH] add isl_basic_{set,map}_from_constraint_matrices Signed-off-by: Sven Verdoolaege --- doc/user.pod | 23 +++++++++++++++ include/isl_map.h | 5 ++++ include/isl_set.h | 5 ++++ isl_map.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 6407be9..dfb22f3 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -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 arguments indicate the order in which +different kinds of variables appear in the input matrices +and should be a permutation of C, C, +C and C for sets and +of C, C, +C, C and C for relations. + =head2 Inspecting Sets and Relations Usually, the user should not have to care about the actual constraints diff --git a/include/isl_map.h b/include/isl_map.h index bd2c2a0..782d337 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -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) } diff --git a/include/isl_set.h b/include/isl_set.h index f49b791..01a86dc 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -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 diff --git a/isl_map.c b/isl_map.c index fa902f0..cfc9a98 100644 --- 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); +} -- 2.7.4