From 0e01a0e995b09c76526cd27d0046bf93697c4dde Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 2 Feb 2013 10:45:32 +0100 Subject: [PATCH] summate.c: sum_with_equalities: extract out sum_over_polytope_0D We will be able to reuse this function is the next commit. Note that we use P->Dimension instead of new_dim in sum_over_polytope_0D, but these values should be the same. Signed-off-by: Sven Verdoolaege --- summate.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/summate.c b/summate.c index b34fc06..abbf22b 100644 --- a/summate.c +++ b/summate.c @@ -56,6 +56,28 @@ static void transform_polynomial(evalue *E, Matrix *T, Matrix *CP, free(subs); } +/* Compute the sum of the quasi-polynomial E + * over a 0D (non-empty, but possibly parametric) polytope P. + * + * Consumes P and E. + * + * We simply return a partition evalue with P as domain and E as value. + */ +static evalue *sum_over_polytope_0D(Polyhedron *P, evalue *E) +{ + evalue *sum; + + sum = ALLOC(evalue); + value_init(sum->d); + sum->x.p = new_enode(partition, 2, P->Dimension); + EVALUE_SET_DOMAIN(sum->x.p->arr[0], P); + value_clear(sum->x.p->arr[1].d); + sum->x.p->arr[1] = *E; + free(E); + + return sum; +} + static evalue *sum_with_equalities(Polyhedron *P, evalue *E, unsigned nvar, struct evalue_section_array *sections, struct barvinok_options *options, @@ -93,13 +115,7 @@ static evalue *sum_with_equalities(Polyhedron *P, evalue *E, evalue_free(E); Polyhedron_Free(P); } else { - sum = ALLOC(evalue); - value_init(sum->d); - sum->x.p = new_enode(partition, 2, new_dim); - EVALUE_SET_DOMAIN(sum->x.p->arr[0], P); - value_clear(sum->x.p->arr[1].d); - sum->x.p->arr[1] = *E; - free(E); + sum = sum_over_polytope_0D(P, E); } if (CP) { -- 2.11.4.GIT