From d99a30cdb34b6de97a4aaa620a081273ccacd2a5 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 1 Mar 2010 11:20:08 +0100 Subject: [PATCH] add isl_set_sample_point --- doc/user.pod | 11 +++++++++++ include/isl_set.h | 1 + isl_sample.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 666637a5..10d7af41 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1094,6 +1094,17 @@ enumerating and return C<-1> as well. If the enumeration is performed successfully and to completion, then C returns C<0>. +To obtain a single point of a set, use + + __isl_give isl_point *isl_set_sample_point( + __isl_take isl_set *set); + +If C does not contain any (integer) points, then the +resulting point will be ``void'', a property that can be +tested using + + int isl_point_is_void(__isl_keep isl_point *pnt); + =head2 Dependence Analysis C contains specialized functionality for performing diff --git a/include/isl_set.h b/include/isl_set.h index 146d99f5..a2216644 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -206,6 +206,7 @@ void isl_set_free(__isl_take isl_set *set); struct isl_set *isl_set_dup(struct isl_set *set); __isl_give isl_set *isl_set_from_basic_set(__isl_take isl_basic_set *bset); __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set); +__isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set); __isl_give isl_set *isl_set_detect_equalities(__isl_take isl_set *set); __isl_give isl_basic_set *isl_set_affine_hull(__isl_take isl_set *set); __isl_give isl_basic_set *isl_set_convex_hull(__isl_take isl_set *set); diff --git a/isl_sample.c b/isl_sample.c index ed627531..f7c1c879 100644 --- a/isl_sample.c +++ b/isl_sample.c @@ -16,6 +16,7 @@ #include "isl_equalities.h" #include "isl_tab.h" #include "isl_basis_reduction.h" +#include static struct isl_vec *empty_sample(struct isl_basic_set *bset) { @@ -1246,3 +1247,41 @@ __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set) { return (isl_basic_set *) isl_map_sample((isl_map *)set); } + +__isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset) +{ + isl_vec *vec; + isl_dim *dim; + + dim = isl_basic_set_get_dim(bset); + bset = isl_basic_set_underlying_set(bset); + vec = isl_basic_set_sample_vec(bset); + + return isl_point_alloc(dim, vec); +} + +__isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set) +{ + int i; + isl_point *pnt; + + if (!set) + return NULL; + + for (i = 0; i < set->n; ++i) { + pnt = isl_basic_set_sample_point(isl_basic_set_copy(set->p[i])); + if (!pnt) + goto error; + if (!isl_point_is_void(pnt)) + break; + isl_point_free(pnt); + } + if (i == set->n) + pnt = isl_point_void(isl_set_get_dim(set)); + + isl_set_free(set); + return pnt; +error: + isl_set_free(set); + return NULL; +} -- 2.11.4.GIT