isl_coalesce.c: set_up_substitutions: extract isl_basic_map_equal_div_expr_part
[isl.git] / polytope_scan.c
blobc78743252fbdc7aac50c965b38f49f38b96c50a4
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #include <assert.h>
11 #include <isl_map_private.h>
12 #include "isl_equalities.h"
13 #include <isl_seq.h>
14 #include "isl_scan.h"
15 #include <isl_mat_private.h>
16 #include <isl_vec_private.h>
18 /* The input of this program is the same as that of the "polytope_scan"
19 * program from the barvinok distribution.
21 * Constraints of set is PolyLib format.
23 * The input set is assumed to be bounded.
26 struct scan_samples {
27 struct isl_scan_callback callback;
28 struct isl_mat *samples;
31 static isl_stat scan_samples_add_sample(struct isl_scan_callback *cb,
32 __isl_take isl_vec *sample)
34 struct scan_samples *ss = (struct scan_samples *)cb;
36 ss->samples = isl_mat_extend(ss->samples, ss->samples->n_row + 1,
37 ss->samples->n_col);
38 if (!ss->samples)
39 goto error;
41 isl_seq_cpy(ss->samples->row[ss->samples->n_row - 1],
42 sample->el, sample->size);
44 isl_vec_free(sample);
45 return isl_stat_ok;
46 error:
47 isl_vec_free(sample);
48 return isl_stat_error;
51 static struct isl_mat *isl_basic_set_scan_samples(struct isl_basic_set *bset)
53 isl_ctx *ctx;
54 unsigned dim;
55 struct scan_samples ss;
57 ctx = isl_basic_set_get_ctx(bset);
58 dim = isl_basic_set_total_dim(bset);
59 ss.callback.add = scan_samples_add_sample;
60 ss.samples = isl_mat_alloc(ctx, 0, 1 + dim);
61 if (!ss.samples)
62 goto error;
64 if (isl_basic_set_scan(bset, &ss.callback) < 0) {
65 isl_mat_free(ss.samples);
66 return NULL;
69 return ss.samples;
70 error:
71 isl_basic_set_free(bset);
72 return NULL;
75 static struct isl_mat *isl_basic_set_samples(struct isl_basic_set *bset)
77 struct isl_mat *T;
78 struct isl_mat *samples;
80 if (!bset)
81 return NULL;
83 if (bset->n_eq == 0)
84 return isl_basic_set_scan_samples(bset);
86 bset = isl_basic_set_remove_equalities(bset, &T, NULL);
87 samples = isl_basic_set_scan_samples(bset);
88 return isl_mat_product(samples, isl_mat_transpose(T));
91 int main(int argc, char **argv)
93 struct isl_ctx *ctx = isl_ctx_alloc();
94 struct isl_basic_set *bset;
95 struct isl_mat *samples;
97 bset = isl_basic_set_read_from_file(ctx, stdin);
98 samples = isl_basic_set_samples(bset);
99 isl_mat_print_internal(samples, stdout, 0);
100 isl_mat_free(samples);
101 isl_ctx_free(ctx);
103 return 0;