diff options
author | Sven Verdoolaege <skimo@kotnet.org> | 2012-11-20 11:41:42 +0100 |
---|---|---|
committer | Sven Verdoolaege <skimo@kotnet.org> | 2012-11-20 11:41:42 +0100 |
commit | 2ff4d0ffb9d19b47c4b82842096c12503c50e89d (patch) | |
tree | 01e9081336b53bc71018f06df435d3162f9370ca | |
parent | 89fbd2940acfcde9a18a9574ca0515cc1c4fae70 (diff) | |
download | isl-2ff4d0ffb9d19b47c4b82842096c12503c50e89d.tar.gz isl-2ff4d0ffb9d19b47c4b82842096c12503c50e89d.tar.bz2 isl-2ff4d0ffb9d19b47c4b82842096c12503c50e89d.zip |
isl_tab_sample: extract out compute_min and compute_max
We will be able to reuse them in the next commit.
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
-rw-r--r-- | isl_sample.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/isl_sample.c b/isl_sample.c index d9cdc003..6fcec276 100644 --- a/isl_sample.c +++ b/isl_sample.c @@ -347,6 +347,36 @@ static struct isl_mat *initial_basis(struct isl_tab *tab) return Q; } +/* Compute the minimum of the current ("level") basis row over "tab" + * and store the result in position "level" of "min". + */ +static enum isl_lp_result compute_min(isl_ctx *ctx, struct isl_tab *tab, + __isl_keep isl_vec *min, int level) +{ + return isl_tab_min(tab, tab->basis->row[1 + level], + ctx->one, &min->el[level], NULL, 0); +} + +/* Compute the maximum of the current ("level") basis row over "tab" + * and store the result in position "level" of "max". + */ +static enum isl_lp_result compute_max(isl_ctx *ctx, struct isl_tab *tab, + __isl_keep isl_vec *max, int level) +{ + enum isl_lp_result res; + unsigned dim = tab->n_var; + + isl_seq_neg(tab->basis->row[1 + level] + 1, + tab->basis->row[1 + level] + 1, dim); + res = isl_tab_min(tab, tab->basis->row[1 + level], + ctx->one, &max->el[level], NULL, 0); + isl_seq_neg(tab->basis->row[1 + level] + 1, + tab->basis->row[1 + level] + 1, dim); + isl_int_neg(max->el[level], max->el[level]); + + return res; +} + /* Given a tableau representing a set, find and return * an integer point in the set, if there is any. * @@ -456,8 +486,7 @@ struct isl_vec *isl_tab_sample(struct isl_tab *tab) while (level >= 0) { if (init) { - res = isl_tab_min(tab, tab->basis->row[1 + level], - ctx->one, &min->el[level], NULL, 0); + res = compute_min(ctx, tab, min, level); if (res == isl_lp_error) goto error; if (res != isl_lp_ok) @@ -466,13 +495,7 @@ struct isl_vec *isl_tab_sample(struct isl_tab *tab) goto error); if (isl_tab_sample_is_integer(tab)) break; - isl_seq_neg(tab->basis->row[1 + level] + 1, - tab->basis->row[1 + level] + 1, dim); - res = isl_tab_min(tab, tab->basis->row[1 + level], - ctx->one, &max->el[level], NULL, 0); - isl_seq_neg(tab->basis->row[1 + level] + 1, - tab->basis->row[1 + level] + 1, dim); - isl_int_neg(max->el[level], max->el[level]); + res = compute_max(ctx, tab, max, level); if (res == isl_lp_error) goto error; if (res != isl_lp_ok) |