export isl_token_free and isl_stream_error
[isl.git] / isl_sample_piplib.c
blob11acfa227e128cdf905fead897b76b4e6180571a
1 #include "isl_mat.h"
2 #include "isl_vec.h"
3 #include "isl_seq.h"
4 #include "isl_piplib.h"
5 #include "isl_sample_piplib.h"
7 struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset)
9 PipOptions *options = NULL;
10 PipMatrix *domain = NULL;
11 PipQuast *sol = NULL;
12 struct isl_vec *vec = NULL;
13 unsigned dim;
14 struct isl_ctx *ctx;
16 if (!bset)
17 goto error;
18 ctx = bset->ctx;
19 isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error);
20 isl_assert(ctx, bset->n_div == 0, goto error);
21 dim = isl_basic_set_n_dim(bset);
22 domain = isl_basic_map_to_pip((struct isl_basic_map *)bset, 0, 0, 0);
23 if (!domain)
24 goto error;
26 options = pip_options_init();
27 if (!options)
28 goto error;
29 sol = pip_solve(domain, NULL, -1, options);
30 if (!sol)
31 goto error;
32 if (!sol->list)
33 vec = isl_vec_alloc(ctx, 0);
34 else {
35 PipList *l;
36 int i;
37 vec = isl_vec_alloc(ctx, 1 + dim);
38 if (!vec)
39 goto error;
40 isl_int_set_si(vec->block.data[0], 1);
41 for (i = 0, l = sol->list; l && i < dim; ++i, l = l->next) {
42 isl_seq_cpy_from_pip(&vec->block.data[1+i],
43 &l->vector->the_vector[0], 1);
44 isl_assert(ctx, !entier_zero_p(l->vector->the_deno[0]),
45 goto error);
47 isl_assert(ctx, i == dim, goto error);
50 pip_quast_free(sol);
51 pip_options_free(options);
52 pip_matrix_free(domain);
54 isl_basic_set_free(bset);
55 return vec;
56 error:
57 isl_vec_free(vec);
58 isl_basic_set_free(bset);
59 if (sol)
60 pip_quast_free(sol);
61 if (domain)
62 pip_matrix_free(domain);
63 return NULL;