From 60a12cfe806e853fe1e793973ab6db8f68b0ba53 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 7 Mar 2010 19:03:04 +0100 Subject: [PATCH] iscc: add @ operator --- doc/isl.tex | 16 +++++++++++++ iscc.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/doc/isl.tex b/doc/isl.tex index 93605ab..0fef5bf 100644 --- a/doc/isl.tex +++ b/doc/isl.tex @@ -45,11 +45,15 @@ card P; f := [n,m] -> { [i,j] -> i*j + n*i*i*j : i,j >= 0 and 5i + 27j <= n+m }; sum f; +s := sum f; +s @ [n,m] -> { [] : 0 <= n,m <= 20 }; f := [n] -> { [i] -> 2*n*i - n*n + 3*n - 1/2*i*i - 3/2*i-1 : (exists j : 0 <= i < 4*n-1 and 0 <= j < n and 2*n-1 <= i+j <= 4*n-2 and i <= 2*n-1 ) }; ub f; +u := ub f; +u @ [n] -> { [] : 0 <= n <= 10 }; \end{verbatim} \begin{table} @@ -124,6 +128,18 @@ map & \ai{$*$} & map & map & intersection \\ pwqp & \ai{$*$} & pwqp & pwqp & product \\ +pwqp & \ai{@} & set & pwqp & +evaluate the piecewise quasipolynomial in each element +of the set and return a piecewise quasipolynomial +mapping each of the individual elements to the resulting +constant +\\ +pw qp fold & \ai{@} & set & pwqp & +evaluate the piecewise quasipolynomial fold in each element +of the set and return a piecewise quasipolynomial +mapping each of the individual elements to the resulting +constant +\\ \end{tabular} \caption{\protect\ai[\tt]{iscc} binary operations} \label{t:iscc:binary} diff --git a/iscc.c b/iscc.c index 3f1061d..b809167 100644 --- a/iscc.c +++ b/iscc.c @@ -19,6 +19,79 @@ struct isc_bin_op { isc_bin_op_fn fn; }; +struct iscc_at { + isl_pw_qpolynomial *pwqp; + isl_pw_qpolynomial *res; +}; + +static int eval_at(__isl_take isl_point *pnt, void *user) +{ + struct iscc_at *at = (struct iscc_at *) user; + isl_qpolynomial *qp; + isl_set *set; + + set = isl_set_from_point(isl_point_copy(pnt)); + qp = isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(at->pwqp), pnt); + + at->res = isl_pw_qpolynomial_add_disjoint(at->res, + isl_pw_qpolynomial_alloc(set, qp)); + + return 0; +} + +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_at( + __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_set *set) +{ + struct iscc_at at; + + at.pwqp = pwqp; + at.res = isl_pw_qpolynomial_zero(isl_set_get_dim(set)); + + isl_set_foreach_point(set, eval_at, &at); + + isl_pw_qpolynomial_free(pwqp); + isl_set_free(set); + + return at.res; +} + +struct iscc_fold_at { + isl_pw_qpolynomial_fold *pwf; + isl_pw_qpolynomial *res; +}; + +static int eval_fold_at(__isl_take isl_point *pnt, void *user) +{ + struct iscc_fold_at *at = (struct iscc_fold_at *) user; + isl_qpolynomial *qp; + isl_set *set; + + set = isl_set_from_point(isl_point_copy(pnt)); + qp = isl_pw_qpolynomial_fold_eval(isl_pw_qpolynomial_fold_copy(at->pwf), + pnt); + + at->res = isl_pw_qpolynomial_add_disjoint(at->res, + isl_pw_qpolynomial_alloc(set, qp)); + + return 0; +} + +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_fold_at( + __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set) +{ + struct iscc_fold_at at; + + at.pwf = pwf; + at.res = isl_pw_qpolynomial_zero(isl_set_get_dim(set)); + + isl_set_foreach_point(set, eval_fold_at, &at); + + isl_pw_qpolynomial_fold_free(pwf); + isl_set_free(set); + + return at.res; +} + struct isc_bin_op bin_ops[] = { { '+', isl_obj_set, isl_obj_set, isl_obj_set, @@ -47,6 +120,12 @@ struct isc_bin_op bin_ops[] = { { '*', isl_obj_pw_qpolynomial, isl_obj_pw_qpolynomial, isl_obj_pw_qpolynomial, (isc_bin_op_fn) &isl_pw_qpolynomial_mul }, + { '@', isl_obj_pw_qpolynomial, isl_obj_set, + isl_obj_pw_qpolynomial, + (isc_bin_op_fn) &isl_pw_qpolynomial_at }, + { '@', isl_obj_pw_qpolynomial_fold, isl_obj_set, + isl_obj_pw_qpolynomial, + (isc_bin_op_fn) &isl_pw_qpolynomial_fold_at }, 0 }; -- 2.11.4.GIT