add isl_map_set_rational
[platform/upstream/isl.git] / isl_convex_hull.c
index 4e07acf..8d02b7c 100644 (file)
@@ -7,6 +7,7 @@
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
  */
 
+#include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl/lp.h>
 #include <isl/map.h>
 
 static struct isl_basic_set *uset_convex_hull_wrap_bounded(struct isl_set *set);
 
-static void swap_ineq(struct isl_basic_map *bmap, unsigned i, unsigned j)
-{
-       isl_int *t;
-
-       if (i != j) {
-               t = bmap->ineq[i];
-               bmap->ineq[i] = bmap->ineq[j];
-               bmap->ineq[j] = t;
-       }
-}
-
 /* Return 1 if constraint c is redundant with respect to the constraints
  * in bmap.  If c is a lower [upper] bound in some variable and bmap
  * does not have a lower [upper] bound in that variable, then c cannot
@@ -126,6 +116,19 @@ __isl_give isl_basic_set *isl_basic_set_remove_redundancies(
                isl_basic_map_remove_redundancies((struct isl_basic_map *)bset);
 }
 
+/* Remove redundant constraints in each of the basic maps.
+ */
+__isl_give isl_map *isl_map_remove_redundancies(__isl_take isl_map *map)
+{
+       return isl_map_inline_foreach_basic_map(map,
+                                           &isl_basic_map_remove_redundancies);
+}
+
+__isl_give isl_set *isl_set_remove_redundancies(__isl_take isl_set *set)
+{
+       return isl_map_remove_redundancies(set);
+}
+
 /* Check if the set set is bound in the direction of the affine
  * constraint c and if so, set the constant term such that the
  * resulting constraint is a bounding constraint for the set.
@@ -174,41 +177,53 @@ error:
        return -1;
 }
 
-struct isl_basic_set *isl_basic_set_set_rational(struct isl_basic_set *bset)
+__isl_give isl_basic_map *isl_basic_map_set_rational(
+       __isl_take isl_basic_set *bmap)
 {
-       if (!bset)
+       if (!bmap)
                return NULL;
 
-       if (ISL_F_ISSET(bset, ISL_BASIC_MAP_RATIONAL))
-               return bset;
+       if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL))
+               return bmap;
 
-       bset = isl_basic_set_cow(bset);
-       if (!bset)
+       bmap = isl_basic_map_cow(bmap);
+       if (!bmap)
                return NULL;
 
-       ISL_F_SET(bset, ISL_BASIC_MAP_RATIONAL);
+       ISL_F_SET(bmap, ISL_BASIC_MAP_RATIONAL);
+
+       return isl_basic_map_finalize(bmap);
+}
 
-       return isl_basic_set_finalize(bset);
+__isl_give isl_basic_set *isl_basic_set_set_rational(
+       __isl_take isl_basic_set *bset)
+{
+       return isl_basic_map_set_rational(bset);
 }
 
-static struct isl_set *isl_set_set_rational(struct isl_set *set)
+__isl_give isl_map *isl_map_set_rational(__isl_take isl_map *map)
 {
        int i;
 
-       set = isl_set_cow(set);
-       if (!set)
+       map = isl_map_cow(map);
+       if (!map)
                return NULL;
-       for (i = 0; i < set->n; ++i) {
-               set->p[i] = isl_basic_set_set_rational(set->p[i]);
-               if (!set->p[i])
+       for (i = 0; i < map->n; ++i) {
+               map->p[i] = isl_basic_map_set_rational(map->p[i]);
+               if (!map->p[i])
                        goto error;
        }
-       return set;
+       return map;
 error:
-       isl_set_free(set);
+       isl_map_free(map);
        return NULL;
 }
 
+__isl_give isl_set *isl_set_set_rational(__isl_take isl_set *set)
+{
+       return isl_map_set_rational(set);
+}
+
 static struct isl_basic_set *isl_basic_set_add_equality(
        struct isl_basic_set *bset, isl_int *c)
 {
@@ -290,6 +305,7 @@ static struct isl_basic_set *wrap_constraints(struct isl_set *set)
                n_ineq += set->p[i]->n_ineq;
        }
        lp = isl_basic_set_alloc(set->ctx, 0, dim * set->n, 0, n_eq, n_ineq);
+       lp = isl_basic_set_set_rational(lp);
        if (!lp)
                return NULL;
        lp_dim = isl_basic_set_n_dim(lp);
@@ -786,13 +802,6 @@ error:
        return NULL;
 }
 
-/* Project out final n dimensions using Fourier-Motzkin */
-static struct isl_set *set_project_out(struct isl_ctx *ctx,
-       struct isl_set *set, unsigned n)
-{
-       return isl_set_remove_dims(set, isl_dim_set, isl_set_n_dim(set) - n, n);
-}
-
 static struct isl_basic_set *convex_hull_0d(struct isl_set *set)
 {
        struct isl_basic_set *convex_hull;
@@ -890,7 +899,7 @@ int isl_basic_set_is_bounded(__isl_keep isl_basic_set *bset)
 
        if (!bset)
                return -1;
-       if (isl_basic_set_fast_is_empty(bset))
+       if (isl_basic_set_plain_is_empty(bset))
                return 1;
 
        tab = isl_tab_from_recession_cone(bset, 1);
@@ -1030,7 +1039,7 @@ static struct isl_basic_set *modulo_lineality(struct isl_set *set,
        if (!set || !lin)
                goto error;
        lin_dim = total - lin->n_eq;
-       M = isl_mat_sub_alloc(set->ctx, lin->eq, 0, lin->n_eq, 1, total);
+       M = isl_mat_sub_alloc6(set->ctx, lin->eq, 0, lin->n_eq, 1, total);
        M = isl_mat_left_hermite(M, 0, &U, &Q);
        if (!M)
                goto error;
@@ -1663,7 +1672,7 @@ static struct isl_basic_set *common_constraints(struct isl_basic_set *hull,
 
        total = isl_dim_total(set->dim);
        for (i = 0; i < set->p[best]->n_ineq; ++i) {
-               constraints[i].c = isl_mat_sub_alloc(hull->ctx,
+               constraints[i].c = isl_mat_sub_alloc6(hull->ctx,
                        set->p[best]->ineq + i, 0, 1, 0, 1 + total);
                if (!constraints[i].c)
                        goto error;