summaryrefslogtreecommitdiff
path: root/cloog-0.17.0/isl/isl_sample_piplib.c
blob: 37550080d69d508e57f184592a8dc891ec51bfa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright 2008-2009 Katholieke Universiteit Leuven
 *
 * Use of this software is governed by the GNU LGPLv2.1 license
 *
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
 */

#include <isl/mat.h>
#include <isl/vec.h>
#include <isl/seq.h>
#include "isl_piplib.h"
#include "isl_sample_piplib.h"

struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset)
{
	PipOptions	*options = NULL;
	PipMatrix	*domain = NULL;
	PipQuast	*sol = NULL;
	struct isl_vec *vec = NULL;
	unsigned	dim;
	struct isl_ctx *ctx;

	if (!bset)
		goto error;
	ctx = isl_basic_set_get_ctx(bset);
	isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error);
	isl_assert(ctx, isl_basic_set_dim(bset, isl_dim_div) == 0, goto error);
	dim = isl_basic_set_n_dim(bset);
	domain = isl_basic_map_to_pip((struct isl_basic_map *)bset, 0, 0, 0);
	if (!domain)
		goto error;

	options = pip_options_init();
	if (!options)
		goto error;
	sol = pip_solve(domain, NULL, -1, options);
	if (!sol)
		goto error;
	if (!sol->list)
		vec = isl_vec_alloc(ctx, 0);
	else {
		PipList *l;
		int i;
		vec = isl_vec_alloc(ctx, 1 + dim);
		if (!vec)
			goto error;
		isl_int_set_si(vec->block.data[0], 1);
		for (i = 0, l = sol->list; l && i < dim; ++i, l = l->next) {
			isl_seq_cpy_from_pip(&vec->block.data[1+i],
					&l->vector->the_vector[0], 1);
			isl_assert(ctx, !entier_zero_p(l->vector->the_deno[0]),
					goto error);
		}
		isl_assert(ctx, i == dim, goto error);
	}

	pip_quast_free(sol);
	pip_options_free(options);
	pip_matrix_free(domain);

	isl_basic_set_free(bset);
	return vec;
error:
	isl_vec_free(vec);
	isl_basic_set_free(bset);
	if (sol)
		pip_quast_free(sol);
	if (domain)
		pip_matrix_free(domain);
	return NULL;
}