From a363eab87f3765c4d02daaaeef4aee2a6956c29b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 1 Mar 2010 15:40:25 +0100 Subject: [PATCH] privately export isl_set_contains_point Since we are now using the isl_point abstraction, we are more strict about dimensions and so the code in pip.c that actually used the wrong dimensions but just happened to work, needs to be changed too. --- isl_map_private.h | 4 +++ isl_map_subtract.c | 51 ++++++--------------------------------- isl_point.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pip.c | 10 ++++---- 4 files changed, 88 insertions(+), 48 deletions(-) diff --git a/isl_map_private.h b/isl_map_private.h index 911c59a..19355e9 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -150,3 +150,7 @@ struct isl_set *isl_set_preimage(struct isl_set *set, struct isl_mat *mat); isl_int *isl_set_wrap_facet(__isl_keep isl_set *set, isl_int *facet, isl_int *ridge); + +int isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap, + __isl_keep isl_point *point); +int isl_set_contains_point(__isl_keep isl_set *set, __isl_keep isl_point *point); diff --git a/isl_map_subtract.c b/isl_map_subtract.c index 5a383fd..2cbdb01 100644 --- a/isl_map_subtract.c +++ b/isl_map_subtract.c @@ -12,6 +12,7 @@ #include "isl_map.h" #include "isl_map_private.h" #include "isl_tab.h" +#include static void expand_constraint(isl_vec *v, unsigned dim, isl_int *c, int *div_map, unsigned n_div) @@ -613,9 +614,10 @@ int isl_map_is_singleton(__isl_keep isl_map *map) } /* Given a singleton basic map, extract the single element - * as an isl_vec. + * as an isl_point. */ -static __isl_give isl_vec *singleton_extract_point(__isl_keep isl_basic_map *bmap) +static __isl_give isl_point *singleton_extract_point( + __isl_keep isl_basic_map *bmap) { int i, j; unsigned dim; @@ -658,50 +660,13 @@ static __isl_give isl_vec *singleton_extract_point(__isl_keep isl_basic_map *bma } isl_int_clear(m); - return point; + return isl_point_alloc(isl_basic_map_get_dim(bmap), point); error: isl_int_clear(m); isl_vec_free(point); return NULL; } -/* Return 1 if "bmap" contains the point "point". - * "bmap" is assumed to have known divs. - * The point is first extended with the divs and then passed - * to basic_map_contains. - */ -static int basic_map_contains_point(__isl_keep isl_basic_map *bmap, - __isl_keep isl_vec *point) -{ - int i; - struct isl_vec *vec; - unsigned dim; - int contains; - - if (!bmap || !point) - return -1; - if (bmap->n_div == 0) - return isl_basic_map_contains(bmap, point); - - dim = isl_basic_map_total_dim(bmap) - bmap->n_div; - vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div); - if (!vec) - return -1; - - isl_seq_cpy(vec->el, point->el, point->size); - for (i = 0; i < bmap->n_div; ++i) { - isl_seq_inner_product(bmap->div[i] + 1, vec->el, - 1 + dim + i, &vec->el[1+dim+i]); - isl_int_fdiv_q(vec->el[1+dim+i], vec->el[1+dim+i], - bmap->div[i][0]); - } - - contains = isl_basic_map_contains(bmap, vec); - - isl_vec_free(vec); - return contains; -} - /* Return 1 is the singleton map "map1" is a subset of "map2", * i.e., if the single element of "map1" is also an element of "map2". */ @@ -710,7 +675,7 @@ static int map_is_singleton_subset(__isl_keep isl_map *map1, { int i; int is_subset = 0; - struct isl_vec *point; + struct isl_point *point; if (!map1 || !map2) return -1; @@ -722,12 +687,12 @@ static int map_is_singleton_subset(__isl_keep isl_map *map1, return -1; for (i = 0; i < map2->n; ++i) { - is_subset = basic_map_contains_point(map2->p[i], point); + is_subset = isl_basic_map_contains_point(map2->p[i], point); if (is_subset) break; } - isl_vec_free(point); + isl_point_free(point); return is_subset; } diff --git a/isl_point.c b/isl_point.c index 23dbb50..a8f278e 100644 --- a/isl_point.c +++ b/isl_point.c @@ -248,6 +248,77 @@ error: return -1; } +/* Return 1 if "bmap" contains the point "point". + * "bmap" is assumed to have known divs. + * The point is first extended with the divs and then passed + * to basic_map_contains. + */ +int isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap, + __isl_keep isl_point *point) +{ + int i; + struct isl_vec *vec; + unsigned dim; + int contains; + + if (!bmap || !point) + return -1; + isl_assert(bmap->ctx, isl_dim_equal(bmap->dim, point->dim), return -1); + if (bmap->n_div == 0) + return isl_basic_map_contains(bmap, point->vec); + + dim = isl_basic_map_total_dim(bmap) - bmap->n_div; + vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div); + if (!vec) + return -1; + + isl_seq_cpy(vec->el, point->vec->el, point->vec->size); + for (i = 0; i < bmap->n_div; ++i) { + isl_seq_inner_product(bmap->div[i] + 1, vec->el, + 1 + dim + i, &vec->el[1+dim+i]); + isl_int_fdiv_q(vec->el[1+dim+i], vec->el[1+dim+i], + bmap->div[i][0]); + } + + contains = isl_basic_map_contains(bmap, vec); + + isl_vec_free(vec); + return contains; +} + +int isl_map_contains_point(__isl_keep isl_map *map, __isl_keep isl_point *point) +{ + int i; + int found = 0; + + if (!map || !point) + return -1; + + map = isl_map_copy(map); + map = isl_map_compute_divs(map); + if (!map) + return -1; + + for (i = 0; i < map->n; ++i) { + found = isl_basic_map_contains_point(map->p[i], point); + if (found < 0) + goto error; + if (found) + break; + } + isl_map_free(map); + + return found; +error: + isl_map_free(map); + return -1; +} + +int isl_set_contains_point(__isl_keep isl_set *set, __isl_keep isl_point *point) +{ + return isl_map_contains_point((isl_map *)set, point); +} + __isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1, __isl_take isl_point *pnt2) { diff --git a/pip.c b/pip.c index 6c0ffe1..5b50e8a 100644 --- a/pip.c +++ b/pip.c @@ -16,6 +16,7 @@ #include "isl_scan.h" #include "isl_seq.h" #include "isl_ilp.h" +#include /* The input of this program is the same as that of the "example" program * from the PipLib distribution, except that the "big parameter column" @@ -215,11 +216,10 @@ static int scan_one(struct isl_scan_callback *callback, assert(opt); if (opt->size == 0) { - isl_set *sample_set; - sample_set = isl_set_from_basic_set( - isl_basic_set_from_vec(sample)); - assert(isl_set_is_subset(sample_set, sp->empty)); - isl_set_free(sample_set); + isl_point *sample_pnt; + sample_pnt = isl_point_alloc(isl_set_get_dim(sp->empty), sample); + assert(isl_set_contains_point(sp->empty, sample_pnt)); + isl_point_free(sample_pnt); isl_vec_free(opt); } else { isl_set *sol; -- 2.7.4