/* Return a new isl_schedule_band with partial schedule "mupa".
 * First replace "mupa" by its greatest integer part to ensure
 * that the schedule is always integral.
 * The band is not marked permutable, the dimensions are not
 * marked coincident and the AST build options are empty.
 * Since there are no build options, the node is not anchored.
 */
__isl_give isl_schedule_band *isl_schedule_band_from_multi_union_pw_aff(
	__isl_take isl_multi_union_pw_aff *mupa)
{
	isl_ctx *ctx;
	isl_schedule_band *band;
	isl_space *space;

	mupa = isl_multi_union_pw_aff_floor(mupa);
	if (!mupa)
		return NULL;
	ctx = isl_multi_union_pw_aff_get_ctx(mupa);
	band = isl_schedule_band_alloc(ctx);
	if (!band)
		goto error;

	band->n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set);
	band->coincident = isl_calloc_array(ctx, int, band->n);
	band->mupa = mupa;
	space = isl_space_params_alloc(ctx, 0);
	band->ast_build_options = isl_union_set_empty(space);
	band->anchored = 0;

	if ((band->n && !band->coincident) || !band->ast_build_options)
		return isl_schedule_band_free(band);

	return band;
error:
	isl_multi_union_pw_aff_free(mupa);
	return NULL;
}
/* Compute the union of all the constraints in domain.  */
isl_union_set *nfm_union_domain_union_domains(isl_ctx *ctx,
		struct nfm_union_domain *union_domain)
{
	isl_union_set *union_set;

	assert(union_domain);
	assert(union_domain->domain);

	IF_DEBUG(fprintf(stdout, " Starting the union function.\n"));

	nfm_union_domain *head = union_domain;
	union_set = isl_union_set_empty(nfm_domain_get_space(ctx, union_domain->domain));

	IF_DEBUG(fprintf(stdout, " Initial value for the union set is:"));
	IF_DEBUG(isl_union_set_dump(union_set));

	while (head != NULL)
	{
		nfm_domain *domain = head->domain;
		isl_bset_list *bset_list = nfm_domain_intersect_constraints(ctx, domain);
		IF_DEBUG(fprintf(stdout, " The constraints at this iteration,"
					 " represented as a set, are:"));
		IF_DEBUG(isl_bset_list_dump(bset_list));

	  	while (bset_list != NULL)
		{
			union_set = isl_union_set_union(union_set,
					isl_union_set_from_set(
						isl_set_from_basic_set(
							bset_list->bset)));
			bset_list = bset_list->next;
		}

		IF_DEBUG(fprintf(stdout, " Results of the union:"));
		IF_DEBUG(isl_union_set_dump(union_set));
		head  = head->next;
	}

	IF_DEBUG(fprintf(stdout, " End of the union function.\n"));

	return union_set;
}