Пример #1
0
/* Construct a parameter compression for "bset".
 * We basically just call isl_mat_parameter_compression with the right input
 * and then extend the resulting matrix to include the variables.
 *
 * Let the equalities be given as
 *
 *	B(p) + A x = 0
 *
 * and let [H 0] be the Hermite Normal Form of A, then
 *
 *	H^-1 B(p)
 *
 * needs to be integer, so we impose that each row is divisible by
 * the denominator.
 */
__isl_give isl_morph *isl_basic_set_parameter_compression(
	__isl_keep isl_basic_set *bset)
{
	unsigned nparam;
	unsigned nvar;
	int n_eq;
	isl_mat *H, *B;
	isl_vec *d;
	isl_mat *map, *inv;
	isl_basic_set *dom, *ran;

	if (!bset)
		return NULL;

	if (isl_basic_set_plain_is_empty(bset))
		return isl_morph_empty(bset);
	if (bset->n_eq == 0)
		return isl_morph_identity(bset);

	isl_assert(bset->ctx, bset->n_div == 0, return NULL);

	n_eq = bset->n_eq;
	nparam = isl_basic_set_dim(bset, isl_dim_param);
	nvar = isl_basic_set_dim(bset, isl_dim_set);

	isl_assert(bset->ctx, n_eq <= nvar, return NULL);

	d = isl_vec_alloc(bset->ctx, n_eq);
	B = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, n_eq, 0, 1 + nparam);
	H = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, n_eq, 1 + nparam, nvar);
	H = isl_mat_left_hermite(H, 0, NULL, NULL);
	H = isl_mat_drop_cols(H, n_eq, nvar - n_eq);
	H = isl_mat_lin_to_aff(H);
	H = isl_mat_right_inverse(H);
	if (!H || !d)
		goto error;
	isl_seq_set(d->el, H->row[0][0], d->size);
	H = isl_mat_drop_rows(H, 0, 1);
	H = isl_mat_drop_cols(H, 0, 1);
	B = isl_mat_product(H, B);
	inv = isl_mat_parameter_compression(B, d);
	inv = isl_mat_diagonal(inv, isl_mat_identity(bset->ctx, nvar));
	map = isl_mat_right_inverse(isl_mat_copy(inv));

	dom = isl_basic_set_universe(isl_space_copy(bset->dim));
	ran = isl_basic_set_universe(isl_space_copy(bset->dim));

	return isl_morph_alloc(dom, ran, map, inv);
error:
	isl_mat_free(H);
	isl_mat_free(B);
	isl_vec_free(d);
	return NULL;
}
Пример #2
0
/* Given a set of equalities
 *
 *		B(y) + A x = 0						(*)
 *
 * compute and return an affine transformation T,
 *
 *		y = T y'
 *
 * that bijectively maps the integer vectors y' to integer
 * vectors y that satisfy the modulo constraints for some value of x.
 *
 * Let [H 0] be the Hermite Normal Form of A, i.e.,
 *
 *		A = [H 0] Q
 *
 * Then y is a solution of (*) iff
 *
 *		H^-1 B(y) (= - [I 0] Q x)
 *
 * is an integer vector.  Let d be the common denominator of H^-1.
 * We impose
 *
 *		d H^-1 B(y) = 0 mod d
 *
 * and compute the solution using isl_mat_parameter_compression.
 */
__isl_give isl_mat *isl_mat_parameter_compression_ext(__isl_take isl_mat *B,
	__isl_take isl_mat *A)
{
	isl_ctx *ctx;
	isl_vec *d;
	int n_row, n_col;

	if (!A)
		return isl_mat_free(B);

	ctx = isl_mat_get_ctx(A);
	n_row = A->n_row;
	n_col = A->n_col;
	A = isl_mat_left_hermite(A, 0, NULL, NULL);
	A = isl_mat_drop_cols(A, n_row, n_col - n_row);
	A = isl_mat_lin_to_aff(A);
	A = isl_mat_right_inverse(A);
	d = isl_vec_alloc(ctx, n_row);
	if (A)
		d = isl_vec_set(d, A->row[0][0]);
	A = isl_mat_drop_rows(A, 0, 1);
	A = isl_mat_drop_cols(A, 0, 1);
	B = isl_mat_product(A, B);

	return isl_mat_parameter_compression(B, d);
}
Пример #3
0
/* Compute a common lattice of solutions to the linear modulo
 * constraints specified by B and d.
 * See also the documentation of isl_mat_parameter_compression.
 * We put the matrix
 * 
 *		A = [ L_1^{-T} L_2^{-T} ... L_k^{-T} ]
 *
 * on a common denominator.  This denominator D is the lcm of modulos d.
 * Since L_i = U_i^{-1} diag(d_i, 1, ... 1), we have
 * L_i^{-T} = U_i^T diag(d_i, 1, ... 1)^{-T} = U_i^T diag(1/d_i, 1, ..., 1).
 * Putting this on the common denominator, we have
 * D * L_i^{-T} = U_i^T diag(D/d_i, D, ..., D).
 */
static struct isl_mat *parameter_compression_multi(
			struct isl_mat *B, struct isl_vec *d)
{
	int i, j, k;
	isl_int D;
	struct isl_mat *A = NULL, *U = NULL;
	struct isl_mat *T;
	unsigned size;

	isl_int_init(D);

	isl_vec_lcm(d, &D);

	size = B->n_col - 1;
	A = isl_mat_alloc(B->ctx, size, B->n_row * size);
	U = isl_mat_alloc(B->ctx, size, size);
	if (!U || !A)
		goto error;
	for (i = 0; i < B->n_row; ++i) {
		isl_seq_cpy(U->row[0], B->row[i] + 1, size);
		U = isl_mat_unimodular_complete(U, 1);
		if (!U)
			goto error;
		isl_int_divexact(D, D, d->block.data[i]);
		for (k = 0; k < U->n_col; ++k)
			isl_int_mul(A->row[k][i*size+0], D, U->row[0][k]);
		isl_int_mul(D, D, d->block.data[i]);
		for (j = 1; j < U->n_row; ++j)
			for (k = 0; k < U->n_col; ++k)
				isl_int_mul(A->row[k][i*size+j],
						D, U->row[j][k]);
	}
	A = isl_mat_left_hermite(A, 0, NULL, NULL);
	T = isl_mat_sub_alloc(A, 0, A->n_row, 0, A->n_row);
	T = isl_mat_lin_to_aff(T);
	if (!T)
		goto error;
	isl_int_set(T->row[0][0], D);
	T = isl_mat_right_inverse(T);
	if (!T)
		goto error;
	isl_assert(T->ctx, isl_int_is_one(T->row[0][0]), goto error);
	T = isl_mat_transpose(T);
	isl_mat_free(A);
	isl_mat_free(U);

	isl_int_clear(D);
	return T;
error:
	isl_mat_free(A);
	isl_mat_free(U);
	isl_int_clear(D);
	return NULL;
}
Пример #4
0
/* Compute and return the matrix
 *
 *		U_1^{-1} diag(d_1, 1, ..., 1)
 *
 * with U_1 the unimodular completion of the first (and only) row of B.
 * The columns of this matrix generate the lattice that satisfies
 * the single (linear) modulo constraint.
 */
static struct isl_mat *parameter_compression_1(
			struct isl_mat *B, struct isl_vec *d)
{
	struct isl_mat *U;

	U = isl_mat_alloc(B->ctx, B->n_col - 1, B->n_col - 1);
	if (!U)
		return NULL;
	isl_seq_cpy(U->row[0], B->row[0] + 1, B->n_col - 1);
	U = isl_mat_unimodular_complete(U, 1);
	U = isl_mat_right_inverse(U);
	if (!U)
		return NULL;
	isl_mat_col_mul(U, 0, d->block.data[0], 0);
	U = isl_mat_lin_to_aff(U);
	return U;
}