* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
*/
+#include <isl_ctx_private.h>
+#include <isl_map_private.h>
#include "isl_sample.h"
#include "isl_sample_piplib.h"
-#include "isl_vec.h"
-#include "isl_mat.h"
-#include "isl_seq.h"
-#include "isl_map_private.h"
+#include <isl/vec.h>
+#include <isl/mat.h>
+#include <isl/seq.h>
#include "isl_equalities.h"
#include "isl_tab.h"
#include "isl_basis_reduction.h"
+#include <isl_factorization.h>
#include <isl_point_private.h>
static struct isl_vec *empty_sample(struct isl_basic_set *bset)
bset = isl_basic_set_simplify(bset);
if (!bset)
return NULL;
- if (isl_basic_set_fast_is_empty(bset))
+ if (isl_basic_set_plain_is_empty(bset))
return empty_sample(bset);
if (bset->n_eq == 0 && bset->n_ineq == 0)
return zero_sample(bset);
sample = isl_vec_alloc(bset->ctx, 2);
+ if (!sample)
+ goto error;
+ if (!bset)
+ return NULL;
isl_int_set_si(sample->block.data[0], 1);
if (bset->n_eq > 0) {
struct isl_mat *eq;
struct isl_mat *Q;
- n_eq = tab->n_var - tab->n_col + tab->n_dead;
+ tab->n_unbounded = 0;
+ tab->n_zero = n_eq = tab->n_var - tab->n_col + tab->n_dead;
if (tab->empty || n_eq == 0 || n_eq == tab->n_var)
return isl_mat_identity(tab->mat->ctx, 1 + tab->n_var);
continue;
}
isl_int_neg(tab->basis->row[1 + level][0], min->el[level]);
- tab = isl_tab_add_valid_eq(tab, tab->basis->row[1 + level]);
+ if (isl_tab_add_valid_eq(tab, tab->basis->row[1 + level]) < 0)
+ goto error;
isl_int_set_si(tab->basis->row[1 + level][0], 0);
if (level + tab->n_unbounded < dim - 1) {
++level;
return NULL;
}
+static struct isl_vec *sample_bounded(struct isl_basic_set *bset);
+
+/* Compute a sample point of the given basic set, based on the given,
+ * non-trivial factorization.
+ */
+static __isl_give isl_vec *factored_sample(__isl_take isl_basic_set *bset,
+ __isl_take isl_factorizer *f)
+{
+ int i, n;
+ isl_vec *sample = NULL;
+ isl_ctx *ctx;
+ unsigned nparam;
+ unsigned nvar;
+
+ ctx = isl_basic_set_get_ctx(bset);
+ if (!ctx)
+ goto error;
+
+ nparam = isl_basic_set_dim(bset, isl_dim_param);
+ nvar = isl_basic_set_dim(bset, isl_dim_set);
+
+ sample = isl_vec_alloc(ctx, 1 + isl_basic_set_total_dim(bset));
+ if (!sample)
+ goto error;
+ isl_int_set_si(sample->el[0], 1);
+
+ bset = isl_morph_basic_set(isl_morph_copy(f->morph), bset);
+
+ for (i = 0, n = 0; i < f->n_group; ++i) {
+ isl_basic_set *bset_i;
+ isl_vec *sample_i;
+
+ bset_i = isl_basic_set_copy(bset);
+ bset_i = isl_basic_set_drop_constraints_involving(bset_i,
+ nparam + n + f->len[i], nvar - n - f->len[i]);
+ bset_i = isl_basic_set_drop_constraints_involving(bset_i,
+ nparam, n);
+ bset_i = isl_basic_set_drop(bset_i, isl_dim_set,
+ n + f->len[i], nvar - n - f->len[i]);
+ bset_i = isl_basic_set_drop(bset_i, isl_dim_set, 0, n);
+
+ sample_i = sample_bounded(bset_i);
+ if (!sample_i)
+ goto error;
+ if (sample_i->size == 0) {
+ isl_basic_set_free(bset);
+ isl_factorizer_free(f);
+ isl_vec_free(sample);
+ return sample_i;
+ }
+ isl_seq_cpy(sample->el + 1 + nparam + n,
+ sample_i->el + 1, f->len[i]);
+ isl_vec_free(sample_i);
+
+ n += f->len[i];
+ }
+
+ f->morph = isl_morph_inverse(f->morph);
+ sample = isl_morph_vec(isl_morph_copy(f->morph), sample);
+
+ isl_basic_set_free(bset);
+ isl_factorizer_free(f);
+ return sample;
+error:
+ isl_basic_set_free(bset);
+ isl_factorizer_free(f);
+ isl_vec_free(sample);
+ return NULL;
+}
+
/* Given a basic set that is known to be bounded, find and return
* an integer point in the basic set, if there is any.
*
struct isl_ctx *ctx;
struct isl_vec *sample;
struct isl_tab *tab = NULL;
+ isl_factorizer *f;
if (!bset)
return NULL;
- if (isl_basic_set_fast_is_empty(bset))
+ if (isl_basic_set_plain_is_empty(bset))
return empty_sample(bset);
dim = isl_basic_set_total_dim(bset);
if (bset->n_eq > 0)
return sample_eq(bset, sample_bounded);
+ f = isl_basic_set_factorizer(bset);
+ if (!f)
+ goto error;
+ if (f->n_group != 0)
+ return factored_sample(bset, f);
+ isl_factorizer_free(f);
+
ctx = bset->ctx;
tab = isl_tab_from_basic_set(bset);
if (isl_tab_track_bset(tab, isl_basic_set_copy(bset)) < 0)
goto error;
if (!ISL_F_ISSET(bset, ISL_BASIC_SET_NO_IMPLICIT))
- tab = isl_tab_detect_implicit_equalities(tab);
- if (!tab)
- goto error;
+ if (isl_tab_detect_implicit_equalities(tab) < 0)
+ goto error;
sample = isl_tab_sample(tab);
if (!sample)
total = isl_basic_set_total_dim(cone);
cone = isl_basic_set_preimage(cone, U);
- cone = isl_basic_set_remove_dims(cone, 0, total - (vec->size - 1));
+ cone = isl_basic_set_remove_dims(cone, isl_dim_set,
+ 0, total - (vec->size - 1));
cone = shift_cone(cone, vec);
return NULL;
}
-/* Drop all constraints in bset that involve any of the dimensions
- * first to first+n-1.
- */
-static struct isl_basic_set *drop_constraints_involving
- (struct isl_basic_set *bset, unsigned first, unsigned n)
-{
- int i;
-
- if (!bset)
- return NULL;
-
- bset = isl_basic_set_cow(bset);
-
- for (i = bset->n_ineq - 1; i >= 0; --i) {
- if (isl_seq_first_non_zero(bset->ineq[i] + 1 + first, n) == -1)
- continue;
- isl_basic_set_drop_inequality(bset, i);
- }
-
- return bset;
-}
-
/* Give a basic set "bset" with recession cone "cone", compute and
* return an integer point in bset, if any.
*
total = isl_basic_set_total_dim(cone);
cone_dim = total - cone->n_eq;
- M = isl_mat_sub_alloc(bset->ctx, cone->eq, 0, cone->n_eq, 1, total);
+ M = isl_mat_sub_alloc6(bset->ctx, cone->eq, 0, cone->n_eq, 1, total);
M = isl_mat_left_hermite(M, 0, &U, NULL);
if (!M)
goto error;
bset = isl_basic_set_preimage(bset, isl_mat_copy(U));
bounded = isl_basic_set_copy(bset);
- bounded = drop_constraints_involving(bounded, total - cone_dim, cone_dim);
+ bounded = isl_basic_set_drop_constraints_involving(bounded,
+ total - cone_dim, cone_dim);
bounded = isl_basic_set_drop_dims(bounded, total - cone_dim, cone_dim);
sample = sample_bounded(bounded);
if (!sample || sample->size == 0) {
dim = isl_basic_set_total_dim(bset);
cone = isl_basic_set_recession_cone(isl_basic_set_copy(bset));
+ if (!cone)
+ goto error;
if (cone->n_eq < dim)
return isl_basic_set_sample_with_cone(bset, cone);
isl_basic_set_free(cone);
return sample_bounded(bset);
+error:
+ isl_basic_set_free(bset);
+ return NULL;
}
static struct isl_vec *pip_sample(struct isl_basic_set *bset)
return NULL;
ctx = bset->ctx;
- if (isl_basic_set_fast_is_empty(bset))
+ if (isl_basic_set_plain_is_empty(bset))
return empty_sample(bset);
dim = isl_basic_set_n_dim(bset);