From 8ea7e34cd4772c8be223e65799dfb5f56cdaff48 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 2 Oct 2010 11:16:17 +0200 Subject: [PATCH] export isl_basic_set_reduced_basis Since this function will now be available from the outside, we add some more checks and we allow the input to contain equalities. Signed-off-by: Sven Verdoolaege --- basis_reduction_templ.c | 35 +++++++++++++++++++++++++++++++++-- include/isl_set.h | 2 ++ isl_basis_reduction.h | 1 - 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/basis_reduction_templ.c b/basis_reduction_templ.c index 305431f0..375549d1 100644 --- a/basis_reduction_templ.c +++ b/basis_reduction_templ.c @@ -302,15 +302,46 @@ error: return tab; } +/* Compute an affine form of a reduced basis of the given basic + * non-parametric set, which is assumed to be bounded and not + * include any integer divisions. + * The first column and the first row correspond to the constant term. + * + * If the input contains any equalities, we first create an initial + * basis with the equalities first. Otherwise, we start off with + * the identity matrix. + */ struct isl_mat *isl_basic_set_reduced_basis(struct isl_basic_set *bset) { struct isl_mat *basis; struct isl_tab *tab; - isl_assert(bset->ctx, bset->n_eq == 0, return NULL); + if (!bset) + return NULL; + + if (isl_basic_set_dim(bset, isl_dim_div) != 0) + isl_die(bset->ctx, isl_error_invalid, + "no integer division allowed", return NULL); + if (isl_basic_set_dim(bset, isl_dim_param) != 0) + isl_die(bset->ctx, isl_error_invalid, + "no parameters allowed", return NULL); tab = isl_tab_from_basic_set(bset); - tab->basis = isl_mat_identity(bset->ctx, 1 + tab->n_var); + if (!tab) + return NULL; + + if (bset->n_eq == 0) + tab->basis = isl_mat_identity(bset->ctx, 1 + tab->n_var); + else { + isl_mat *eq; + unsigned nvar = isl_basic_set_total_dim(bset); + eq = isl_mat_sub_alloc(bset->ctx, bset->eq, 0, bset->n_eq, + 1, nvar); + eq = isl_mat_left_hermite(eq, 0, NULL, &tab->basis); + tab->basis = isl_mat_lin_to_aff(tab->basis); + tab->n_zero = bset->n_eq; + isl_mat_free(eq); + } tab = isl_tab_compute_reduced_basis(tab); if (!tab) return NULL; diff --git a/include/isl_set.h b/include/isl_set.h index 4e8f7259..c978d38e 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -374,6 +374,8 @@ __isl_give isl_basic_set *isl_basic_set_from_constraint_matrices( __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4); +__isl_give isl_mat *isl_basic_set_reduced_basis(__isl_keep isl_basic_set *bset); + #if defined(__cplusplus) } #endif diff --git a/isl_basis_reduction.h b/isl_basis_reduction.h index e9eb760f..9b9b721d 100644 --- a/isl_basis_reduction.h +++ b/isl_basis_reduction.h @@ -19,7 +19,6 @@ extern "C" { #endif struct isl_tab *isl_tab_compute_reduced_basis(struct isl_tab *tab); -struct isl_mat *isl_basic_set_reduced_basis(struct isl_basic_set *bset); #if defined(__cplusplus) } -- 2.11.4.GIT