struct isl_basic_map *isl_map_affine_hull(struct isl_map *map) { int i; struct isl_basic_map *model = NULL; struct isl_basic_map *hull = NULL; struct isl_set *set; map = isl_map_detect_equalities(map); map = isl_map_align_divs(map); if (!map) return NULL; if (map->n == 0) { hull = isl_basic_map_empty_like_map(map); isl_map_free(map); return hull; } model = isl_basic_map_copy(map->p[0]); set = isl_map_underlying_set(map); set = isl_set_cow(set); if (!set) goto error; for (i = 0; i < set->n; ++i) { set->p[i] = isl_basic_set_cow(set->p[i]); set->p[i] = isl_basic_set_affine_hull(set->p[i]); set->p[i] = isl_basic_set_gauss(set->p[i], NULL); if (!set->p[i]) goto error; } set = isl_set_remove_empty_parts(set); if (set->n == 0) { hull = isl_basic_map_empty_like(model); isl_basic_map_free(model); } else { struct isl_basic_set *bset; while (set->n > 1) { set->p[0] = affine_hull(set->p[0], set->p[--set->n]); if (!set->p[0]) goto error; } bset = isl_basic_set_copy(set->p[0]); hull = isl_basic_map_overlying_set(bset, model); } isl_set_free(set); hull = isl_basic_map_simplify(hull); return isl_basic_map_finalize(hull); error: isl_basic_map_free(model); isl_set_free(set); return NULL; }
struct isl_basic_set *isl_basic_set_remove_equalities( struct isl_basic_set *bset, struct isl_mat **T, struct isl_mat **T2) { if (T) *T = NULL; if (T2) *T2 = NULL; if (!bset) return NULL; isl_assert(bset->ctx, isl_basic_set_n_param(bset) == 0, goto error); bset = isl_basic_set_gauss(bset, NULL); if (ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY)) return bset; bset = compress_variables(bset, T, T2); return bset; error: isl_basic_set_free(bset); *T = NULL; return NULL; }
/* Given an unbounded tableau and an integer point satisfying the tableau, * construct an initial affine hull containing the recession cone * shifted to the given point. * * The unbounded directions are taken from the last rows of the basis, * which is assumed to have been initialized appropriately. */ static __isl_give isl_basic_set *initial_hull(struct isl_tab *tab, __isl_take isl_vec *vec) { int i; int k; struct isl_basic_set *bset = NULL; struct isl_ctx *ctx; unsigned dim; if (!vec || !tab) return NULL; ctx = vec->ctx; isl_assert(ctx, vec->size != 0, goto error); bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0); if (!bset) goto error; dim = isl_basic_set_n_dim(bset) - tab->n_unbounded; for (i = 0; i < dim; ++i) { k = isl_basic_set_alloc_equality(bset); if (k < 0) goto error; isl_seq_cpy(bset->eq[k] + 1, tab->basis->row[1 + i] + 1, vec->size - 1); isl_seq_inner_product(bset->eq[k] + 1, vec->el +1, vec->size - 1, &bset->eq[k][0]); isl_int_neg(bset->eq[k][0], bset->eq[k][0]); } bset->sample = vec; bset = isl_basic_set_gauss(bset, NULL); return bset; error: isl_basic_set_free(bset); isl_vec_free(vec); return NULL; }