isl_map_convex_hull: remove lineality space if any before computing convex hull
[platform/upstream/isl.git] / isl_sample_piplib.c
index b0bf2cf..478749e 100644 (file)
@@ -1,5 +1,6 @@
 #include "isl_mat.h"
 #include "isl_vec.h"
+#include "isl_seq.h"
 #include "isl_piplib.h"
 #include "isl_sample_piplib.h"
 
@@ -16,29 +17,31 @@ static struct isl_mat *independent_bounds(struct isl_ctx *ctx,
        int i, j, n;
        struct isl_mat *dirs = NULL;
        struct isl_mat *bounds = NULL;
+       unsigned dim;
 
        if (!bset)
                return NULL;
 
-       bounds = isl_mat_alloc(ctx, 1+bset->dim, 1+bset->dim);
+       dim = isl_basic_set_n_dim(bset);
+       bounds = isl_mat_alloc(ctx, 1+dim, 1+dim);
        if (!bounds)
                return NULL;
 
        isl_int_set_si(bounds->row[0][0], 1);
-       isl_seq_clr(bounds->row[0]+1, bset->dim);
+       isl_seq_clr(bounds->row[0]+1, dim);
        bounds->n_row = 1;
 
        if (bset->n_ineq == 0)
                return bounds;
 
-       dirs = isl_mat_alloc(ctx, bset->dim, bset->dim);
+       dirs = isl_mat_alloc(ctx, dim, dim);
        if (!dirs) {
                isl_mat_free(ctx, bounds);
                return NULL;
        }
        isl_seq_cpy(dirs->row[0], bset->ineq[0]+1, dirs->n_col);
        isl_seq_cpy(bounds->row[1], bset->ineq[0], bounds->n_col);
-       for (j = 1, n = 1; n < bset->dim && j < bset->n_ineq; ++j) {
+       for (j = 1, n = 1; n < dim && j < bset->n_ineq; ++j) {
                int pos;
 
                isl_seq_cpy(dirs->row[n], bset->ineq[j]+1, dirs->n_col);
@@ -78,30 +81,31 @@ static struct isl_mat *independent_bounds(struct isl_ctx *ctx,
 
 /* Skew into positive orthant and project out lineality space */
 static struct isl_basic_set *isl_basic_set_skew_to_positive_orthant(
-       struct isl_ctx *ctx, struct isl_basic_set *bset,
-       struct isl_mat **T)
+       struct isl_basic_set *bset, struct isl_mat **T)
 {
        struct isl_mat *U = NULL;
        struct isl_mat *bounds = NULL;
        int i, j;
        unsigned old_dim, new_dim;
+       struct isl_ctx *ctx;
 
        *T = NULL;
        if (!bset)
                return NULL;
 
-       isl_assert(ctx, bset->nparam == 0, goto error);
+       ctx = bset->ctx;
+       isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error);
        isl_assert(ctx, bset->n_div == 0, goto error);
        isl_assert(ctx, bset->n_eq == 0, goto error);
        
+       old_dim = isl_basic_set_n_dim(bset);
        /* Try to move (multiples of) unit rows up. */
        for (i = 0, j = 0; i < bset->n_ineq; ++i) {
-               int pos = isl_seq_first_non_zero(bset->ineq[i]+1,
-                                                           bset->dim);
+               int pos = isl_seq_first_non_zero(bset->ineq[i]+1, old_dim);
                if (pos < 0)
                        continue;
                if (isl_seq_first_non_zero(bset->ineq[i]+1+pos+1,
-                                               bset->dim-pos-1) >= 0)
+                                               old_dim-pos-1) >= 0)
                        continue;
                if (i != j)
                        swap_inequality(bset, i, j);
@@ -110,13 +114,12 @@ static struct isl_basic_set *isl_basic_set_skew_to_positive_orthant(
        bounds = independent_bounds(ctx, bset);
        if (!bounds)
                goto error;
-       old_dim = bset->dim;
        new_dim = bounds->n_row - 1;
        bounds = isl_mat_left_hermite(ctx, bounds, 1, &U, NULL);
        if (!bounds)
                goto error;
        U = isl_mat_drop_cols(ctx, U, 1 + new_dim, old_dim - new_dim);
-       bset = isl_basic_set_preimage(ctx, bset, isl_mat_copy(ctx, U));
+       bset = isl_basic_set_preimage(bset, isl_mat_copy(ctx, U));
        if (!bset)
                goto error;
        *T = U;
@@ -125,12 +128,11 @@ static struct isl_basic_set *isl_basic_set_skew_to_positive_orthant(
 error:
        isl_mat_free(ctx, bounds);
        isl_mat_free(ctx, U);
-       isl_basic_set_free(ctx, bset);
+       isl_basic_set_free(bset);
        return NULL;
 }
 
-struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx,
-       struct isl_basic_set *bset)
+struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset)
 {
        PipOptions      *options = NULL;
        PipMatrix       *domain = NULL;
@@ -138,15 +140,17 @@ struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx,
        struct isl_vec *vec = NULL;
        unsigned        dim;
        struct isl_mat *T;
+       struct isl_ctx *ctx;
 
        if (!bset)
                goto error;
-       isl_assert(ctx, bset->nparam == 0, goto error);
+       ctx = bset->ctx;
+       isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error);
        isl_assert(ctx, bset->n_div == 0, goto error);
-       bset = isl_basic_set_skew_to_positive_orthant(ctx, bset, &T);
+       bset = isl_basic_set_skew_to_positive_orthant(bset, &T);
        if (!bset)
                goto error;
-       dim = bset->dim;
+       dim = isl_basic_set_n_dim(bset);
        domain = isl_basic_map_to_pip((struct isl_basic_map *)bset, 0, 0, 0);
        if (!domain)
                goto error;
@@ -181,11 +185,11 @@ struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx,
        pip_options_free(options);
        pip_matrix_free(domain);
 
-       isl_basic_set_free(ctx, bset);
+       isl_basic_set_free(bset);
        return vec;
 error:
        isl_vec_free(ctx, vec);
-       isl_basic_set_free(ctx, bset);
+       isl_basic_set_free(bset);
        if (sol)
                pip_quast_free(sol);
        if (domain)