-/* Check if "c" is a direction that is independent of the previously found "n"
- * bounds in "dirs".
- * If so, add it to the list, with the negative of the lower bound
- * in the constant position, i.e., such that c corresponds to a bounding
- * hyperplane (but not necessarily a facet).
- * Assumes set "set" is bounded.
- */
-static int is_independent_bound(struct isl_set *set, isl_int *c,
- struct isl_mat *dirs, int n)
-{
- int is_bound;
- int i = 0;
-
- isl_seq_cpy(dirs->row[n]+1, c+1, dirs->n_col-1);
- if (n != 0) {
- int pos = isl_seq_first_non_zero(dirs->row[n]+1, dirs->n_col-1);
- if (pos < 0)
- return 0;
- for (i = 0; i < n; ++i) {
- int pos_i;
- pos_i = isl_seq_first_non_zero(dirs->row[i]+1, dirs->n_col-1);
- if (pos_i < pos)
- continue;
- if (pos_i > pos)
- break;
- isl_seq_elim(dirs->row[n]+1, dirs->row[i]+1, pos,
- dirs->n_col-1, NULL);
- pos = isl_seq_first_non_zero(dirs->row[n]+1, dirs->n_col-1);
- if (pos < 0)
- return 0;
- }
- }
-
- is_bound = uset_is_bound(set, dirs->row[n], dirs->n_col);
- if (is_bound != 1)
- return is_bound;
- isl_seq_normalize(set->ctx, dirs->row[n], dirs->n_col);
- if (i < n) {
- int k;
- isl_int *t = dirs->row[n];
- for (k = n; k > i; --k)
- dirs->row[k] = dirs->row[k-1];
- dirs->row[i] = t;
- }
- return 1;
-}
-
-/* Compute and return a maximal set of linearly independent bounds
- * on the set "set", based on the constraints of the basic sets
- * in "set".
- */
-static struct isl_mat *independent_bounds(struct isl_set *set)
-{
- int i, j, n;
- struct isl_mat *dirs = NULL;
- unsigned dim = isl_set_n_dim(set);
-
- dirs = isl_mat_alloc(set->ctx, dim, 1+dim);
- if (!dirs)
- goto error;
-
- n = 0;
- for (i = 0; n < dim && i < set->n; ++i) {
- int f;
- struct isl_basic_set *bset = set->p[i];
-
- for (j = 0; n < dim && j < bset->n_eq; ++j) {
- f = is_independent_bound(set, bset->eq[j], dirs, n);
- if (f < 0)
- goto error;
- if (f)
- ++n;
- }
- for (j = 0; n < dim && j < bset->n_ineq; ++j) {
- f = is_independent_bound(set, bset->ineq[j], dirs, n);
- if (f < 0)
- goto error;
- if (f)
- ++n;
- }
- }
- dirs->n_row = n;
- return dirs;
-error:
- isl_mat_free(dirs);
- return NULL;
-}
-