From 247c4d08de51cfa066580a6102432bc4a4394f62 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 24 Jun 2010 18:10:41 +0200 Subject: [PATCH] add isl_set_is_box --- include/isl_set.h | 1 + isl_map.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/isl_set.h b/include/isl_set.h index 519b26ab..ddbb6cae 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -285,6 +285,7 @@ int isl_set_is_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2); int isl_set_is_strict_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2); int isl_set_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2); int isl_set_is_singleton(__isl_keep isl_set *set); +int isl_set_is_box(__isl_keep isl_set *set); __isl_give isl_set *isl_set_sum(__isl_take isl_set *set1, __isl_take isl_set *set2); diff --git a/isl_map.c b/isl_map.c index 9b87bd8a..51cc286c 100644 --- a/isl_map.c +++ b/isl_map.c @@ -14,7 +14,7 @@ #include #include "isl_ctx.h" #include "isl_blk.h" -#include "isl_dim.h" +#include "isl_dim_private.h" #include "isl_equalities.h" #include "isl_list.h" #include "isl_lp.h" @@ -6826,3 +6826,64 @@ int isl_map_is_translation(__isl_keep isl_map *map) return ok; } + +static int unique(isl_int *p, unsigned pos, unsigned len) +{ + if (isl_seq_first_non_zero(p, pos) != -1) + return 0; + if (isl_seq_first_non_zero(p + pos + 1, len - pos - 1) != -1) + return 0; + return 1; +} + +int isl_basic_set_is_box(__isl_keep isl_basic_set *bset) +{ + int i, j; + unsigned nvar; + unsigned ovar; + + if (!bset) + return -1; + + if (isl_basic_set_dim(bset, isl_dim_div) != 0) + return 0; + + nvar = isl_basic_set_dim(bset, isl_dim_set); + ovar = isl_dim_offset(bset->dim, isl_dim_set); + for (j = 0; j < nvar; ++j) { + int lower = 0, upper = 0; + for (i = 0; i < bset->n_eq; ++i) { + if (isl_int_is_zero(bset->eq[i][1 + ovar + j])) + continue; + if (!unique(bset->eq[i] + 1 + ovar, j, nvar)) + return 0; + break; + } + if (i < bset->n_eq) + continue; + for (i = 0; i < bset->n_ineq; ++i) { + if (isl_int_is_zero(bset->ineq[i][1 + ovar + j])) + continue; + if (!unique(bset->ineq[i] + 1 + ovar, j, nvar)) + return 0; + if (isl_int_is_pos(bset->ineq[i][1 + ovar + j])) + lower = 1; + else + upper = 1; + } + if (!lower || !upper) + return 0; + } + + return 1; +} + +int isl_set_is_box(__isl_keep isl_set *set) +{ + if (!set) + return -1; + if (set->n != 1) + return 0; + + return isl_basic_set_is_box(set->p[0]); +} -- 2.11.4.GIT