6 #include <isl_constraint.h>
10 void test_read(struct isl_ctx *ctx)
12 char filename[PATH_MAX];
15 struct isl_basic_set *bset1, *bset2;
16 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
18 n = snprintf(filename, sizeof(filename),
19 "%s/test_inputs/set.omega", srcdir);
20 assert(n < sizeof(filename));
21 input = fopen(filename, "r");
24 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
25 bset2 = isl_basic_set_read_from_str(ctx, str, 0, ISL_FORMAT_OMEGA);
27 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
29 isl_basic_set_free(bset1);
30 isl_basic_set_free(bset2);
35 /* Construct the basic set { [i] : 5 <= i <= N } */
36 void test_construction(struct isl_ctx *ctx)
40 struct isl_basic_set *bset;
41 struct isl_constraint *c;
45 dim = isl_dim_set_alloc(ctx, 1, 1);
46 bset = isl_basic_set_universe(dim);
48 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
49 isl_int_set_si(v, -1);
50 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
52 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
53 bset = isl_basic_set_add_constraint(bset, c);
55 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
57 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
58 isl_int_set_si(v, -5);
59 isl_constraint_set_constant(c, v);
60 bset = isl_basic_set_add_constraint(bset, c);
62 isl_basic_set_free(bset);
67 void test_div(struct isl_ctx *ctx)
73 struct isl_basic_set *bset;
74 struct isl_constraint *c;
79 dim = isl_dim_set_alloc(ctx, 0, 1);
80 bset = isl_basic_set_universe(dim);
82 c = isl_equality_alloc(isl_dim_copy(bset->dim));
83 isl_int_set_si(v, -1);
84 isl_constraint_set_constant(c, v);
86 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
87 div = isl_div_alloc(isl_dim_copy(bset->dim));
88 c = isl_constraint_add_div(c, div, &pos);
90 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
91 bset = isl_basic_set_add_constraint(bset, c);
93 c = isl_equality_alloc(isl_dim_copy(bset->dim));
95 isl_constraint_set_constant(c, v);
96 isl_int_set_si(v, -1);
97 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
98 div = isl_div_alloc(isl_dim_copy(bset->dim));
99 c = isl_constraint_add_div(c, div, &pos);
100 isl_int_set_si(v, 3);
101 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
102 bset = isl_basic_set_add_constraint(bset, c);
104 assert(bset->n_div == 1);
105 isl_basic_set_free(bset);
108 dim = isl_dim_set_alloc(ctx, 0, 1);
109 bset = isl_basic_set_universe(dim);
111 c = isl_equality_alloc(isl_dim_copy(bset->dim));
112 isl_int_set_si(v, 1);
113 isl_constraint_set_constant(c, v);
114 isl_int_set_si(v, -1);
115 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
116 div = isl_div_alloc(isl_dim_copy(bset->dim));
117 c = isl_constraint_add_div(c, div, &pos);
118 isl_int_set_si(v, 3);
119 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
120 bset = isl_basic_set_add_constraint(bset, c);
122 c = isl_equality_alloc(isl_dim_copy(bset->dim));
123 isl_int_set_si(v, -1);
124 isl_constraint_set_constant(c, v);
125 isl_int_set_si(v, 1);
126 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
127 div = isl_div_alloc(isl_dim_copy(bset->dim));
128 c = isl_constraint_add_div(c, div, &pos);
129 isl_int_set_si(v, 3);
130 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
131 bset = isl_basic_set_add_constraint(bset, c);
133 assert(bset->n_div == 1);
134 isl_basic_set_free(bset);
137 dim = isl_dim_set_alloc(ctx, 0, 1);
138 bset = isl_basic_set_universe(dim);
140 c = isl_equality_alloc(isl_dim_copy(bset->dim));
141 isl_int_set_si(v, 1);
142 isl_constraint_set_constant(c, v);
143 isl_int_set_si(v, -1);
144 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
145 div = isl_div_alloc(isl_dim_copy(bset->dim));
146 c = isl_constraint_add_div(c, div, &pos);
147 isl_int_set_si(v, 3);
148 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
149 bset = isl_basic_set_add_constraint(bset, c);
151 c = isl_equality_alloc(isl_dim_copy(bset->dim));
152 isl_int_set_si(v, -3);
153 isl_constraint_set_constant(c, v);
154 isl_int_set_si(v, 1);
155 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
156 div = isl_div_alloc(isl_dim_copy(bset->dim));
157 c = isl_constraint_add_div(c, div, &pos);
158 isl_int_set_si(v, 4);
159 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
160 bset = isl_basic_set_add_constraint(bset, c);
162 assert(bset->n_div == 1);
163 isl_basic_set_free(bset);
166 dim = isl_dim_set_alloc(ctx, 0, 1);
167 bset = isl_basic_set_universe(dim);
169 c = isl_equality_alloc(isl_dim_copy(bset->dim));
170 isl_int_set_si(v, 2);
171 isl_constraint_set_constant(c, v);
172 isl_int_set_si(v, -1);
173 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
174 div = isl_div_alloc(isl_dim_copy(bset->dim));
175 c = isl_constraint_add_div(c, div, &pos);
176 isl_int_set_si(v, 3);
177 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
178 bset = isl_basic_set_add_constraint(bset, c);
180 c = isl_equality_alloc(isl_dim_copy(bset->dim));
181 isl_int_set_si(v, -1);
182 isl_constraint_set_constant(c, v);
183 isl_int_set_si(v, 1);
184 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
185 div = isl_div_alloc(isl_dim_copy(bset->dim));
186 c = isl_constraint_add_div(c, div, &pos);
187 isl_int_set_si(v, 6);
188 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
189 bset = isl_basic_set_add_constraint(bset, c);
191 assert(isl_basic_set_is_empty(bset));
192 isl_basic_set_free(bset);
195 dim = isl_dim_set_alloc(ctx, 0, 2);
196 bset = isl_basic_set_universe(dim);
198 c = isl_equality_alloc(isl_dim_copy(bset->dim));
199 isl_int_set_si(v, -1);
200 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
201 div = isl_div_alloc(isl_dim_copy(bset->dim));
202 c = isl_constraint_add_div(c, div, &pos);
203 isl_int_set_si(v, 3);
204 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
205 bset = isl_basic_set_add_constraint(bset, c);
207 c = isl_equality_alloc(isl_dim_copy(bset->dim));
208 isl_int_set_si(v, 1);
209 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
210 isl_int_set_si(v, -3);
211 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
212 bset = isl_basic_set_add_constraint(bset, c);
214 assert(bset->n_div == 0);
215 isl_basic_set_free(bset);
218 dim = isl_dim_set_alloc(ctx, 0, 2);
219 bset = isl_basic_set_universe(dim);
221 c = isl_equality_alloc(isl_dim_copy(bset->dim));
222 isl_int_set_si(v, -1);
223 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
224 div = isl_div_alloc(isl_dim_copy(bset->dim));
225 c = isl_constraint_add_div(c, div, &pos);
226 isl_int_set_si(v, 6);
227 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
228 bset = isl_basic_set_add_constraint(bset, c);
230 c = isl_equality_alloc(isl_dim_copy(bset->dim));
231 isl_int_set_si(v, 1);
232 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
233 isl_int_set_si(v, -3);
234 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
235 bset = isl_basic_set_add_constraint(bset, c);
237 assert(bset->n_div == 1);
238 isl_basic_set_free(bset);
243 void test_application_case(struct isl_ctx *ctx, const char *name)
245 char filename[PATH_MAX];
248 struct isl_basic_set *bset1, *bset2;
249 struct isl_basic_map *bmap;
251 n = snprintf(filename, sizeof(filename),
252 "%s/test_inputs/%s.omega", srcdir, name);
253 assert(n < sizeof(filename));
254 input = fopen(filename, "r");
257 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
258 bmap = isl_basic_map_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
260 bset1 = isl_basic_set_apply(bset1, bmap);
262 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
264 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
266 isl_basic_set_free(bset1);
267 isl_basic_set_free(bset2);
272 void test_application(struct isl_ctx *ctx)
274 test_application_case(ctx, "application");
275 test_application_case(ctx, "application2");
278 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
280 char filename[PATH_MAX];
283 struct isl_basic_set *bset1, *bset2;
285 n = snprintf(filename, sizeof(filename),
286 "%s/test_inputs/%s.polylib", srcdir, name);
287 assert(n < sizeof(filename));
288 input = fopen(filename, "r");
291 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
292 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
294 bset1 = isl_basic_set_affine_hull(bset1);
296 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
298 isl_basic_set_free(bset1);
299 isl_basic_set_free(bset2);
304 void test_affine_hull(struct isl_ctx *ctx)
306 test_affine_hull_case(ctx, "affine2");
307 test_affine_hull_case(ctx, "affine");
310 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
312 char filename[PATH_MAX];
315 struct isl_basic_set *bset1, *bset2;
318 n = snprintf(filename, sizeof(filename),
319 "%s/test_inputs/%s.polylib", srcdir, name);
320 assert(n < sizeof(filename));
321 input = fopen(filename, "r");
324 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
325 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
327 set = isl_basic_set_union(bset1, bset2);
328 bset1 = isl_set_convex_hull(set);
330 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
332 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
334 isl_basic_set_free(bset1);
335 isl_basic_set_free(bset2);
340 void test_convex_hull(struct isl_ctx *ctx)
342 test_convex_hull_case(ctx, "convex0");
343 test_convex_hull_case(ctx, "convex1");
344 test_convex_hull_case(ctx, "convex2");
345 test_convex_hull_case(ctx, "convex3");
346 test_convex_hull_case(ctx, "convex4");
347 test_convex_hull_case(ctx, "convex5");
348 test_convex_hull_case(ctx, "convex6");
349 test_convex_hull_case(ctx, "convex7");
350 test_convex_hull_case(ctx, "convex8");
351 test_convex_hull_case(ctx, "convex9");
352 test_convex_hull_case(ctx, "convex10");
353 test_convex_hull_case(ctx, "convex11");
356 void test_gist_case(struct isl_ctx *ctx, const char *name)
358 char filename[PATH_MAX];
361 struct isl_basic_set *bset1, *bset2;
364 n = snprintf(filename, sizeof(filename),
365 "%s/test_inputs/%s.polylib", srcdir, name);
366 assert(n < sizeof(filename));
367 input = fopen(filename, "r");
370 bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
371 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
373 bset1 = isl_basic_set_gist(bset1, bset2);
375 bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB);
377 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
379 isl_basic_set_free(bset1);
380 isl_basic_set_free(bset2);
385 void test_gist(struct isl_ctx *ctx)
387 test_gist_case(ctx, "gist1");
394 srcdir = getenv("srcdir");
396 ctx = isl_ctx_alloc();
398 test_construction(ctx);
400 test_application(ctx);
401 test_affine_hull(ctx);
402 test_convex_hull(ctx);