isl_basic_set_sample: remove equalities first
[platform/upstream/isl.git] / isl_sample.c
1 #include "isl_sample.h"
2 #include "isl_sample_piplib.h"
3 #include "isl_vec.h"
4 #include "isl_mat.h"
5 #include "isl_map_private.h"
6 #include "isl_equalities.h"
7
8 struct isl_vec *isl_basic_set_sample(struct isl_ctx *ctx,
9         struct isl_basic_set *bset)
10 {
11         if (!bset)
12                 return NULL;
13
14         if (F_ISSET(bset, ISL_BASIC_SET_EMPTY)) {
15                 isl_basic_set_free(ctx, bset);
16                 return isl_vec_alloc(ctx, 0);
17         }
18
19         isl_assert(ctx, bset->nparam == 0, goto error);
20         isl_assert(ctx, bset->n_div == 0, goto error);
21
22         if (bset->n_eq > 0) {
23                 struct isl_mat *T;
24                 struct isl_vec *sample;
25
26                 bset = isl_basic_set_remove_equalities(ctx, bset, &T, NULL);
27                 sample = isl_basic_set_sample(ctx, bset);
28                 if (sample && sample->size != 0)
29                         sample = isl_mat_vec_product(ctx, T, sample);
30                 else
31                         isl_mat_free(ctx, T);
32                 return sample;
33         }
34         return isl_pip_basic_set_sample(ctx, bset);
35 error:
36         isl_basic_set_free(ctx, bset);
37         return NULL;
38 }