2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
18 #include <isl/constraint.h>
19 #include <isl/polynomial.h>
20 #include <isl/union_map.h>
21 #include <isl_factorization.h>
22 #include <isl/schedule.h>
23 #include <isl_options_private.h>
24 #include <isl/vertices.h>
28 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
31 char *pattern = "%s/test_inputs/%s.%s";
33 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
35 filename = isl_alloc_array(ctx, char, length);
40 sprintf(filename, pattern, srcdir, name, suffix);
45 void test_parse_map(isl_ctx *ctx, const char *str)
49 map = isl_map_read_from_str(ctx, str);
54 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
59 map = isl_map_read_from_str(ctx, str);
60 map2 = isl_map_read_from_str(ctx, str2);
61 equal = isl_map_is_equal(map, map2);
68 isl_die(ctx, isl_error_unknown, "maps not equal",
74 void test_parse_pwqp(isl_ctx *ctx, const char *str)
76 isl_pw_qpolynomial *pwqp;
78 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
80 isl_pw_qpolynomial_free(pwqp);
83 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
87 pwaff = isl_pw_aff_read_from_str(ctx, str);
89 isl_pw_aff_free(pwaff);
92 int test_parse(struct isl_ctx *ctx)
95 const char *str, *str2;
97 str = "{ [i] -> [-i] }";
98 map = isl_map_read_from_str(ctx, str);
102 str = "{ A[i] -> L[([i/3])] }";
103 map = isl_map_read_from_str(ctx, str);
107 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
108 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
109 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
111 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
112 str2 = "{ [x, y] : 2y >= 6 - x }";
113 if (test_parse_map_equal(ctx, str, str2) < 0)
116 if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
117 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
119 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
120 if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
124 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
125 map = isl_map_read_from_str(ctx, str);
126 str = "{ [new, old] -> [o0, o1] : "
127 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
128 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
129 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
130 map2 = isl_map_read_from_str(ctx, str);
131 assert(isl_map_is_equal(map, map2));
135 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
136 map = isl_map_read_from_str(ctx, str);
137 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
138 map2 = isl_map_read_from_str(ctx, str);
139 assert(isl_map_is_equal(map, map2));
143 str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
144 str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
145 if (test_parse_map_equal(ctx, str, str2) < 0)
148 str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
149 str2 = "{ [i,j] -> [min(i,j)] }";
150 if (test_parse_map_equal(ctx, str, str2) < 0)
153 str = "{ [i,j] : i != j }";
154 str2 = "{ [i,j] : i < j or i > j }";
155 if (test_parse_map_equal(ctx, str, str2) < 0)
158 str = "{ [i,j] : (i+1)*2 >= j }";
159 str2 = "{ [i, j] : j <= 2 + 2i }";
160 if (test_parse_map_equal(ctx, str, str2) < 0)
163 str = "{ [i] -> [i > 0 ? 4 : 5] }";
164 str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
165 if (test_parse_map_equal(ctx, str, str2) < 0)
168 str = "[N=2,M] -> { [i=[(M+N)/4]] }";
169 str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
170 if (test_parse_map_equal(ctx, str, str2) < 0)
173 str = "{ [x] : x >= 0 }";
174 str2 = "{ [x] : x-0 >= 0 }";
175 if (test_parse_map_equal(ctx, str, str2) < 0)
178 str = "{ [i] : ((i > 10)) }";
179 str2 = "{ [i] : i >= 11 }";
180 if (test_parse_map_equal(ctx, str, str2) < 0)
183 str = "{ [i] -> [0] }";
184 str2 = "{ [i] -> [0 * i] }";
185 if (test_parse_map_equal(ctx, str, str2) < 0)
188 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
189 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
190 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
191 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
193 if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
194 "{ [a] -> [b] : true }") < 0)
200 void test_read(struct isl_ctx *ctx)
204 struct isl_basic_set *bset1, *bset2;
205 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
207 filename = get_filename(ctx, "set", "omega");
209 input = fopen(filename, "r");
212 bset1 = isl_basic_set_read_from_file(ctx, input);
213 bset2 = isl_basic_set_read_from_str(ctx, str);
215 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
217 isl_basic_set_free(bset1);
218 isl_basic_set_free(bset2);
224 void test_bounded(struct isl_ctx *ctx)
229 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
230 bounded = isl_set_is_bounded(set);
234 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
235 bounded = isl_set_is_bounded(set);
239 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
240 bounded = isl_set_is_bounded(set);
245 /* Construct the basic set { [i] : 5 <= i <= N } */
246 void test_construction(struct isl_ctx *ctx)
251 struct isl_basic_set *bset;
252 struct isl_constraint *c;
256 dim = isl_space_set_alloc(ctx, 1, 1);
257 bset = isl_basic_set_universe(isl_space_copy(dim));
258 ls = isl_local_space_from_space(dim);
260 c = isl_inequality_alloc(isl_local_space_copy(ls));
261 isl_int_set_si(v, -1);
262 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
263 isl_int_set_si(v, 1);
264 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
265 bset = isl_basic_set_add_constraint(bset, c);
267 c = isl_inequality_alloc(isl_local_space_copy(ls));
268 isl_int_set_si(v, 1);
269 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
270 isl_int_set_si(v, -5);
271 isl_constraint_set_constant(c, v);
272 bset = isl_basic_set_add_constraint(bset, c);
274 isl_local_space_free(ls);
275 isl_basic_set_free(bset);
280 void test_dim(struct isl_ctx *ctx)
283 isl_map *map1, *map2;
285 map1 = isl_map_read_from_str(ctx,
286 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
287 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
288 map2 = isl_map_read_from_str(ctx,
289 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
290 assert(isl_map_is_equal(map1, map2));
293 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
294 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
295 assert(isl_map_is_equal(map1, map2));
300 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
301 map1 = isl_map_read_from_str(ctx, str);
302 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
303 map2 = isl_map_read_from_str(ctx, str);
304 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
305 assert(isl_map_is_equal(map1, map2));
311 void test_div(struct isl_ctx *ctx)
316 struct isl_basic_set *bset;
317 struct isl_constraint *c;
322 dim = isl_space_set_alloc(ctx, 0, 3);
323 bset = isl_basic_set_universe(isl_space_copy(dim));
324 ls = isl_local_space_from_space(dim);
326 c = isl_equality_alloc(isl_local_space_copy(ls));
327 isl_int_set_si(v, -1);
328 isl_constraint_set_constant(c, v);
329 isl_int_set_si(v, 1);
330 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
331 isl_int_set_si(v, 3);
332 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
333 bset = isl_basic_set_add_constraint(bset, c);
335 c = isl_equality_alloc(isl_local_space_copy(ls));
336 isl_int_set_si(v, 1);
337 isl_constraint_set_constant(c, v);
338 isl_int_set_si(v, -1);
339 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
340 isl_int_set_si(v, 3);
341 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
342 bset = isl_basic_set_add_constraint(bset, c);
344 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
346 assert(bset && bset->n_div == 1);
347 isl_local_space_free(ls);
348 isl_basic_set_free(bset);
351 dim = isl_space_set_alloc(ctx, 0, 3);
352 bset = isl_basic_set_universe(isl_space_copy(dim));
353 ls = isl_local_space_from_space(dim);
355 c = isl_equality_alloc(isl_local_space_copy(ls));
356 isl_int_set_si(v, 1);
357 isl_constraint_set_constant(c, v);
358 isl_int_set_si(v, -1);
359 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
360 isl_int_set_si(v, 3);
361 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
362 bset = isl_basic_set_add_constraint(bset, c);
364 c = isl_equality_alloc(isl_local_space_copy(ls));
365 isl_int_set_si(v, -1);
366 isl_constraint_set_constant(c, v);
367 isl_int_set_si(v, 1);
368 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
369 isl_int_set_si(v, 3);
370 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
371 bset = isl_basic_set_add_constraint(bset, c);
373 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
375 assert(bset && bset->n_div == 1);
376 isl_local_space_free(ls);
377 isl_basic_set_free(bset);
380 dim = isl_space_set_alloc(ctx, 0, 3);
381 bset = isl_basic_set_universe(isl_space_copy(dim));
382 ls = isl_local_space_from_space(dim);
384 c = isl_equality_alloc(isl_local_space_copy(ls));
385 isl_int_set_si(v, 1);
386 isl_constraint_set_constant(c, v);
387 isl_int_set_si(v, -1);
388 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
389 isl_int_set_si(v, 3);
390 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
391 bset = isl_basic_set_add_constraint(bset, c);
393 c = isl_equality_alloc(isl_local_space_copy(ls));
394 isl_int_set_si(v, -3);
395 isl_constraint_set_constant(c, v);
396 isl_int_set_si(v, 1);
397 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
398 isl_int_set_si(v, 4);
399 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
400 bset = isl_basic_set_add_constraint(bset, c);
402 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
404 assert(bset && bset->n_div == 1);
405 isl_local_space_free(ls);
406 isl_basic_set_free(bset);
409 dim = isl_space_set_alloc(ctx, 0, 3);
410 bset = isl_basic_set_universe(isl_space_copy(dim));
411 ls = isl_local_space_from_space(dim);
413 c = isl_equality_alloc(isl_local_space_copy(ls));
414 isl_int_set_si(v, 2);
415 isl_constraint_set_constant(c, v);
416 isl_int_set_si(v, -1);
417 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
418 isl_int_set_si(v, 3);
419 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
420 bset = isl_basic_set_add_constraint(bset, c);
422 c = isl_equality_alloc(isl_local_space_copy(ls));
423 isl_int_set_si(v, -1);
424 isl_constraint_set_constant(c, v);
425 isl_int_set_si(v, 1);
426 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
427 isl_int_set_si(v, 6);
428 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
429 bset = isl_basic_set_add_constraint(bset, c);
431 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
433 assert(isl_basic_set_is_empty(bset));
434 isl_local_space_free(ls);
435 isl_basic_set_free(bset);
438 dim = isl_space_set_alloc(ctx, 0, 3);
439 bset = isl_basic_set_universe(isl_space_copy(dim));
440 ls = isl_local_space_from_space(dim);
442 c = isl_equality_alloc(isl_local_space_copy(ls));
443 isl_int_set_si(v, -1);
444 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
445 isl_int_set_si(v, 3);
446 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
447 bset = isl_basic_set_add_constraint(bset, c);
449 c = isl_equality_alloc(isl_local_space_copy(ls));
450 isl_int_set_si(v, 1);
451 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
452 isl_int_set_si(v, -3);
453 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
454 bset = isl_basic_set_add_constraint(bset, c);
456 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
458 assert(bset && bset->n_div == 0);
459 isl_basic_set_free(bset);
460 isl_local_space_free(ls);
463 dim = isl_space_set_alloc(ctx, 0, 3);
464 bset = isl_basic_set_universe(isl_space_copy(dim));
465 ls = isl_local_space_from_space(dim);
467 c = isl_equality_alloc(isl_local_space_copy(ls));
468 isl_int_set_si(v, -1);
469 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
470 isl_int_set_si(v, 6);
471 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
472 bset = isl_basic_set_add_constraint(bset, c);
474 c = isl_equality_alloc(isl_local_space_copy(ls));
475 isl_int_set_si(v, 1);
476 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
477 isl_int_set_si(v, -3);
478 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
479 bset = isl_basic_set_add_constraint(bset, c);
481 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
483 assert(bset && bset->n_div == 1);
484 isl_basic_set_free(bset);
485 isl_local_space_free(ls);
488 /* This test is a bit tricky. We set up an equality
490 * Normalization of divs creates _two_ divs
493 * Afterwards e0 is removed again because it has coefficient -1
494 * and we end up with the original equality and div again.
495 * Perhaps we can avoid the introduction of this temporary div.
497 dim = isl_space_set_alloc(ctx, 0, 4);
498 bset = isl_basic_set_universe(isl_space_copy(dim));
499 ls = isl_local_space_from_space(dim);
501 c = isl_equality_alloc(isl_local_space_copy(ls));
502 isl_int_set_si(v, -1);
503 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
504 isl_int_set_si(v, -3);
505 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
506 isl_int_set_si(v, -3);
507 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
508 isl_int_set_si(v, 6);
509 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
510 bset = isl_basic_set_add_constraint(bset, c);
512 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
514 /* Test disabled for now */
516 assert(bset && bset->n_div == 1);
518 isl_local_space_free(ls);
519 isl_basic_set_free(bset);
522 dim = isl_space_set_alloc(ctx, 0, 5);
523 bset = isl_basic_set_universe(isl_space_copy(dim));
524 ls = isl_local_space_from_space(dim);
526 c = isl_equality_alloc(isl_local_space_copy(ls));
527 isl_int_set_si(v, -1);
528 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
529 isl_int_set_si(v, -3);
530 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
531 isl_int_set_si(v, -3);
532 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
533 isl_int_set_si(v, 6);
534 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
535 bset = isl_basic_set_add_constraint(bset, c);
537 c = isl_equality_alloc(isl_local_space_copy(ls));
538 isl_int_set_si(v, -1);
539 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
540 isl_int_set_si(v, 1);
541 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
542 isl_int_set_si(v, 1);
543 isl_constraint_set_constant(c, v);
544 bset = isl_basic_set_add_constraint(bset, c);
546 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
548 /* Test disabled for now */
550 assert(bset && bset->n_div == 1);
552 isl_local_space_free(ls);
553 isl_basic_set_free(bset);
556 dim = isl_space_set_alloc(ctx, 0, 4);
557 bset = isl_basic_set_universe(isl_space_copy(dim));
558 ls = isl_local_space_from_space(dim);
560 c = isl_equality_alloc(isl_local_space_copy(ls));
561 isl_int_set_si(v, 1);
562 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
563 isl_int_set_si(v, -1);
564 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
565 isl_int_set_si(v, -2);
566 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
567 bset = isl_basic_set_add_constraint(bset, c);
569 c = isl_equality_alloc(isl_local_space_copy(ls));
570 isl_int_set_si(v, -1);
571 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
572 isl_int_set_si(v, 3);
573 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
574 isl_int_set_si(v, 2);
575 isl_constraint_set_constant(c, v);
576 bset = isl_basic_set_add_constraint(bset, c);
578 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
580 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
582 assert(!isl_basic_set_is_empty(bset));
584 isl_local_space_free(ls);
585 isl_basic_set_free(bset);
588 dim = isl_space_set_alloc(ctx, 0, 3);
589 bset = isl_basic_set_universe(isl_space_copy(dim));
590 ls = isl_local_space_from_space(dim);
592 c = isl_equality_alloc(isl_local_space_copy(ls));
593 isl_int_set_si(v, 1);
594 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
595 isl_int_set_si(v, -2);
596 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
597 bset = isl_basic_set_add_constraint(bset, c);
599 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
601 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
603 isl_local_space_free(ls);
604 isl_basic_set_free(bset);
609 void test_application_case(struct isl_ctx *ctx, const char *name)
613 struct isl_basic_set *bset1, *bset2;
614 struct isl_basic_map *bmap;
616 filename = get_filename(ctx, name, "omega");
618 input = fopen(filename, "r");
621 bset1 = isl_basic_set_read_from_file(ctx, input);
622 bmap = isl_basic_map_read_from_file(ctx, input);
624 bset1 = isl_basic_set_apply(bset1, bmap);
626 bset2 = isl_basic_set_read_from_file(ctx, input);
628 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
630 isl_basic_set_free(bset1);
631 isl_basic_set_free(bset2);
637 void test_application(struct isl_ctx *ctx)
639 test_application_case(ctx, "application");
640 test_application_case(ctx, "application2");
643 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
647 struct isl_basic_set *bset1, *bset2;
649 filename = get_filename(ctx, name, "polylib");
651 input = fopen(filename, "r");
654 bset1 = isl_basic_set_read_from_file(ctx, input);
655 bset2 = isl_basic_set_read_from_file(ctx, input);
657 bset1 = isl_basic_set_affine_hull(bset1);
659 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
661 isl_basic_set_free(bset1);
662 isl_basic_set_free(bset2);
668 int test_affine_hull(struct isl_ctx *ctx)
675 test_affine_hull_case(ctx, "affine2");
676 test_affine_hull_case(ctx, "affine");
677 test_affine_hull_case(ctx, "affine3");
679 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
680 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
681 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
682 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
683 set = isl_set_read_from_str(ctx, str);
684 bset = isl_set_affine_hull(set);
685 n = isl_basic_set_dim(bset, isl_dim_div);
686 isl_basic_set_free(bset);
688 isl_die(ctx, isl_error_unknown, "not expecting any divs",
694 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
698 struct isl_basic_set *bset1, *bset2;
701 filename = get_filename(ctx, name, "polylib");
703 input = fopen(filename, "r");
706 bset1 = isl_basic_set_read_from_file(ctx, input);
707 bset2 = isl_basic_set_read_from_file(ctx, input);
709 set = isl_basic_set_union(bset1, bset2);
710 bset1 = isl_set_convex_hull(set);
712 bset2 = isl_basic_set_read_from_file(ctx, input);
714 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
716 isl_basic_set_free(bset1);
717 isl_basic_set_free(bset2);
723 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
725 const char *str1, *str2;
726 isl_set *set1, *set2;
727 int orig_convex = ctx->opt->convex;
728 ctx->opt->convex = convex;
730 test_convex_hull_case(ctx, "convex0");
731 test_convex_hull_case(ctx, "convex1");
732 test_convex_hull_case(ctx, "convex2");
733 test_convex_hull_case(ctx, "convex3");
734 test_convex_hull_case(ctx, "convex4");
735 test_convex_hull_case(ctx, "convex5");
736 test_convex_hull_case(ctx, "convex6");
737 test_convex_hull_case(ctx, "convex7");
738 test_convex_hull_case(ctx, "convex8");
739 test_convex_hull_case(ctx, "convex9");
740 test_convex_hull_case(ctx, "convex10");
741 test_convex_hull_case(ctx, "convex11");
742 test_convex_hull_case(ctx, "convex12");
743 test_convex_hull_case(ctx, "convex13");
744 test_convex_hull_case(ctx, "convex14");
745 test_convex_hull_case(ctx, "convex15");
747 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
748 "(i0 = 1 and i1 = 0 and i2 = 1) or "
749 "(i0 = 0 and i1 = 0 and i2 = 0) }";
750 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
751 set1 = isl_set_read_from_str(ctx, str1);
752 set2 = isl_set_read_from_str(ctx, str2);
753 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
754 assert(isl_set_is_equal(set1, set2));
758 ctx->opt->convex = orig_convex;
761 void test_convex_hull(struct isl_ctx *ctx)
763 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
764 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
767 void test_gist_case(struct isl_ctx *ctx, const char *name)
771 struct isl_basic_set *bset1, *bset2;
773 filename = get_filename(ctx, name, "polylib");
775 input = fopen(filename, "r");
778 bset1 = isl_basic_set_read_from_file(ctx, input);
779 bset2 = isl_basic_set_read_from_file(ctx, input);
781 bset1 = isl_basic_set_gist(bset1, bset2);
783 bset2 = isl_basic_set_read_from_file(ctx, input);
785 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
787 isl_basic_set_free(bset1);
788 isl_basic_set_free(bset2);
794 void test_gist(struct isl_ctx *ctx)
797 isl_basic_set *bset1, *bset2;
799 test_gist_case(ctx, "gist1");
801 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
802 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
803 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
804 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
805 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
806 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
807 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
808 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
809 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
810 bset1 = isl_basic_set_read_from_str(ctx, str);
811 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
812 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
813 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
814 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
815 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
816 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
817 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
818 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
819 bset2 = isl_basic_set_read_from_str(ctx, str);
820 bset1 = isl_basic_set_gist(bset1, bset2);
821 assert(bset1 && bset1->n_div == 0);
822 isl_basic_set_free(bset1);
825 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
831 set = isl_set_read_from_str(ctx, str);
832 set = isl_set_coalesce(set);
833 set2 = isl_set_read_from_str(ctx, str);
834 equal = isl_set_is_equal(set, set2);
835 one = set && set->n == 1;
842 isl_die(ctx, isl_error_unknown,
843 "coalesced set not equal to input", return -1);
844 if (check_one && !one)
845 isl_die(ctx, isl_error_unknown,
846 "coalesced set should not be a union", return -1);
851 int test_coalesce(struct isl_ctx *ctx)
854 struct isl_set *set, *set2;
855 struct isl_map *map, *map2;
857 set = isl_set_read_from_str(ctx,
858 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
859 "y >= x & x >= 2 & 5 >= y }");
860 set = isl_set_coalesce(set);
861 assert(set && set->n == 1);
864 set = isl_set_read_from_str(ctx,
865 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
866 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
867 set = isl_set_coalesce(set);
868 assert(set && set->n == 1);
871 set = isl_set_read_from_str(ctx,
872 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
873 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
874 set = isl_set_coalesce(set);
875 assert(set && set->n == 2);
878 set = isl_set_read_from_str(ctx,
879 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
880 "y >= 0 & x >= 6 & x <= 10 & y <= x}");
881 set = isl_set_coalesce(set);
882 assert(set && set->n == 1);
885 set = isl_set_read_from_str(ctx,
886 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
887 "y >= 0 & x >= 7 & x <= 10 & y <= x}");
888 set = isl_set_coalesce(set);
889 assert(set && set->n == 2);
892 set = isl_set_read_from_str(ctx,
893 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
894 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}");
895 set = isl_set_coalesce(set);
896 assert(set && set->n == 2);
899 set = isl_set_read_from_str(ctx,
900 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
901 "y >= 0 & x = 6 & y <= 6}");
902 set = isl_set_coalesce(set);
903 assert(set && set->n == 1);
906 set = isl_set_read_from_str(ctx,
907 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
908 "y >= 0 & x = 7 & y <= 6}");
909 set = isl_set_coalesce(set);
910 assert(set && set->n == 2);
913 set = isl_set_read_from_str(ctx,
914 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
915 "y >= 0 & x = 6 & y <= 5}");
916 set = isl_set_coalesce(set);
917 assert(set && set->n == 1);
918 set2 = isl_set_read_from_str(ctx,
919 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
920 "y >= 0 & x = 6 & y <= 5}");
921 assert(isl_set_is_equal(set, set2));
925 set = isl_set_read_from_str(ctx,
926 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
927 "y >= 0 & x = 6 & y <= 7}");
928 set = isl_set_coalesce(set);
929 assert(set && set->n == 2);
932 set = isl_set_read_from_str(ctx,
933 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
934 set = isl_set_coalesce(set);
935 assert(set && set->n == 1);
936 set2 = isl_set_read_from_str(ctx,
937 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
938 assert(isl_set_is_equal(set, set2));
942 set = isl_set_read_from_str(ctx,
943 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
944 set = isl_set_coalesce(set);
945 set2 = isl_set_read_from_str(ctx,
946 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
947 assert(isl_set_is_equal(set, set2));
951 set = isl_set_read_from_str(ctx,
952 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
953 "2 <= i and i <= n }");
954 set = isl_set_coalesce(set);
955 assert(set && set->n == 1);
956 set2 = isl_set_read_from_str(ctx,
957 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
958 "2 <= i and i <= n }");
959 assert(isl_set_is_equal(set, set2));
963 map = isl_map_read_from_str(ctx,
964 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
965 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
966 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
967 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
968 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
969 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
970 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
971 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
972 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
973 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
974 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
975 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
976 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
977 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
978 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
979 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
980 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
981 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
982 map = isl_map_coalesce(map);
983 map2 = isl_map_read_from_str(ctx,
984 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
985 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
986 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
987 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
988 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
989 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
990 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
991 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
992 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
993 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
994 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
995 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
996 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
997 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
998 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
999 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1000 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1001 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1002 assert(isl_map_is_equal(map, map2));
1006 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1007 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1008 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1009 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
1010 map = isl_map_read_from_str(ctx, str);
1011 map = isl_map_coalesce(map);
1012 map2 = isl_map_read_from_str(ctx, str);
1013 assert(isl_map_is_equal(map, map2));
1017 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
1018 "[o0, o1, o2, o3, o4, o5, o6] : "
1019 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1020 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1021 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1022 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1023 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1024 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1025 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1026 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1027 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1028 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1029 "o6 >= i3 + i6 - o3 and M >= 0 and "
1030 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1031 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
1032 map = isl_map_read_from_str(ctx, str);
1033 map = isl_map_coalesce(map);
1034 map2 = isl_map_read_from_str(ctx, str);
1035 assert(isl_map_is_equal(map, map2));
1039 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1040 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1041 "(o0 = 0 and M >= 2 and N >= 3) or "
1042 "(M = 0 and o0 = 0 and N >= 3) }";
1043 map = isl_map_read_from_str(ctx, str);
1044 map = isl_map_coalesce(map);
1045 map2 = isl_map_read_from_str(ctx, str);
1046 assert(isl_map_is_equal(map, map2));
1050 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1051 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1052 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1053 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1054 map = isl_map_read_from_str(ctx, str);
1055 map = isl_map_coalesce(map);
1056 map2 = isl_map_read_from_str(ctx, str);
1057 assert(isl_map_is_equal(map, map2));
1061 test_coalesce_set(ctx,
1062 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1063 "(i1 = M and M >= 1) }", 0);
1064 test_coalesce_set(ctx,
1065 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1066 test_coalesce_set(ctx,
1067 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1068 "(y = 3 and x = 1) }", 1);
1069 test_coalesce_set(ctx,
1070 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1071 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1072 "i1 <= M and i3 <= M and i4 <= M) or "
1073 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1074 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1075 "i4 <= -1 + M) }", 1);
1076 test_coalesce_set(ctx,
1077 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1078 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1079 test_coalesce_set(ctx,
1080 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1081 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1082 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1083 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
1084 if (test_coalesce_set(ctx,
1085 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1087 if (test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
1089 if (test_coalesce_set(ctx,
1090 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1092 if (test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
1094 if (test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
1096 if (test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
1098 if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
1100 if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
1102 if (test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1104 if (test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1106 if (test_coalesce_set(ctx, "{ [a, b] : exists e : 2e = a and "
1107 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
1112 void test_closure(struct isl_ctx *ctx)
1116 isl_map *up, *right;
1117 isl_map *map, *map2;
1120 /* COCOA example 1 */
1121 map = isl_map_read_from_str(ctx,
1122 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1123 "1 <= i and i < n and 1 <= j and j < n or "
1124 "i2 = i + 1 and j2 = j - 1 and "
1125 "1 <= i and i < n and 2 <= j and j <= n }");
1126 map = isl_map_power(map, &exact);
1130 /* COCOA example 1 */
1131 map = isl_map_read_from_str(ctx,
1132 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1133 "1 <= i and i < n and 1 <= j and j < n or "
1134 "i2 = i + 1 and j2 = j - 1 and "
1135 "1 <= i and i < n and 2 <= j and j <= n }");
1136 map = isl_map_transitive_closure(map, &exact);
1138 map2 = isl_map_read_from_str(ctx,
1139 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1140 "1 <= i and i < n and 1 <= j and j <= n and "
1141 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1142 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1143 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1144 assert(isl_map_is_equal(map, map2));
1148 map = isl_map_read_from_str(ctx,
1149 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1150 " 0 <= y and y <= n }");
1151 map = isl_map_transitive_closure(map, &exact);
1152 map2 = isl_map_read_from_str(ctx,
1153 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1154 " 0 <= y and y <= n }");
1155 assert(isl_map_is_equal(map, map2));
1159 /* COCOA example 2 */
1160 map = isl_map_read_from_str(ctx,
1161 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1162 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1163 "i2 = i + 2 and j2 = j - 2 and "
1164 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1165 map = isl_map_transitive_closure(map, &exact);
1167 map2 = isl_map_read_from_str(ctx,
1168 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1169 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1170 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1171 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1172 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1173 assert(isl_map_is_equal(map, map2));
1177 /* COCOA Fig.2 left */
1178 map = isl_map_read_from_str(ctx,
1179 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1180 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1182 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1183 "j <= 2 i - 3 and j <= n - 2 or "
1184 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1185 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1186 map = isl_map_transitive_closure(map, &exact);
1190 /* COCOA Fig.2 right */
1191 map = isl_map_read_from_str(ctx,
1192 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1193 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1195 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1196 "j <= 2 i - 4 and j <= n - 3 or "
1197 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1198 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1199 map = isl_map_power(map, &exact);
1203 /* COCOA Fig.2 right */
1204 map = isl_map_read_from_str(ctx,
1205 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1206 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1208 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1209 "j <= 2 i - 4 and j <= n - 3 or "
1210 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1211 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1212 map = isl_map_transitive_closure(map, &exact);
1214 map2 = isl_map_read_from_str(ctx,
1215 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1216 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1217 "j <= n and 3 + i + 2 j <= 3 n and "
1218 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1219 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1220 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1221 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1222 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1223 assert(isl_map_is_equal(map, map2));
1227 /* COCOA Fig.1 right */
1228 dom = isl_set_read_from_str(ctx,
1229 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1230 "2 x - 3 y + 3 >= 0 }");
1231 right = isl_map_read_from_str(ctx,
1232 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1233 up = isl_map_read_from_str(ctx,
1234 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1235 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1236 right = isl_map_intersect_range(right, isl_set_copy(dom));
1237 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1238 up = isl_map_intersect_range(up, dom);
1239 map = isl_map_union(up, right);
1240 map = isl_map_transitive_closure(map, &exact);
1242 map2 = isl_map_read_from_str(ctx,
1243 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1244 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1245 assert(isl_map_is_equal(map, map2));
1249 /* COCOA Theorem 1 counter example */
1250 map = isl_map_read_from_str(ctx,
1251 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1252 "i2 = 1 and j2 = j or "
1253 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1254 map = isl_map_transitive_closure(map, &exact);
1258 map = isl_map_read_from_str(ctx,
1259 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1260 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1261 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1262 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1263 map = isl_map_transitive_closure(map, &exact);
1267 /* Kelly et al 1996, fig 12 */
1268 map = isl_map_read_from_str(ctx,
1269 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1270 "1 <= i,j,j+1 <= n or "
1271 "j = n and j2 = 1 and i2 = i + 1 and "
1272 "1 <= i,i+1 <= n }");
1273 map = isl_map_transitive_closure(map, &exact);
1275 map2 = isl_map_read_from_str(ctx,
1276 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1277 "1 <= i <= n and i = i2 or "
1278 "1 <= i < i2 <= n and 1 <= j <= n and "
1280 assert(isl_map_is_equal(map, map2));
1284 /* Omega's closure4 */
1285 map = isl_map_read_from_str(ctx,
1286 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1287 "1 <= x,y <= 10 or "
1288 "x2 = x + 1 and y2 = y and "
1289 "1 <= x <= 20 && 5 <= y <= 15 }");
1290 map = isl_map_transitive_closure(map, &exact);
1294 map = isl_map_read_from_str(ctx,
1295 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1296 map = isl_map_transitive_closure(map, &exact);
1298 map2 = isl_map_read_from_str(ctx,
1299 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1300 assert(isl_map_is_equal(map, map2));
1304 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1305 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1306 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1307 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1308 map = isl_map_read_from_str(ctx, str);
1309 map = isl_map_transitive_closure(map, &exact);
1311 map2 = isl_map_read_from_str(ctx, str);
1312 assert(isl_map_is_equal(map, map2));
1316 str = "{[0] -> [1]; [2] -> [3]}";
1317 map = isl_map_read_from_str(ctx, str);
1318 map = isl_map_transitive_closure(map, &exact);
1320 map2 = isl_map_read_from_str(ctx, str);
1321 assert(isl_map_is_equal(map, map2));
1325 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1326 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1327 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1328 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1329 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1330 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1331 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1332 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1333 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1334 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1335 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1336 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1337 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1338 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1339 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1340 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1341 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1342 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1343 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1344 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1345 map = isl_map_read_from_str(ctx, str);
1346 map = isl_map_transitive_closure(map, NULL);
1351 void test_lex(struct isl_ctx *ctx)
1356 dim = isl_space_set_alloc(ctx, 0, 0);
1357 map = isl_map_lex_le(dim);
1358 assert(!isl_map_is_empty(map));
1362 void test_lexmin(struct isl_ctx *ctx)
1365 isl_basic_map *bmap;
1366 isl_map *map, *map2;
1369 isl_pw_multi_aff *pma;
1371 str = "[p0, p1] -> { [] -> [] : "
1372 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1373 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1374 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1375 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1376 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1377 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1378 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1379 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1380 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1381 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1382 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1383 map = isl_map_read_from_str(ctx, str);
1384 map = isl_map_lexmin(map);
1387 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1388 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1389 set = isl_set_read_from_str(ctx, str);
1390 set = isl_set_lexmax(set);
1391 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1392 set2 = isl_set_read_from_str(ctx, str);
1393 set = isl_set_intersect(set, set2);
1394 assert(!isl_set_is_empty(set));
1397 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1398 map = isl_map_read_from_str(ctx, str);
1399 map = isl_map_lexmin(map);
1400 str = "{ [x] -> [5] : 6 <= x <= 8; "
1401 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1402 map2 = isl_map_read_from_str(ctx, str);
1403 assert(isl_map_is_equal(map, map2));
1407 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1408 map = isl_map_read_from_str(ctx, str);
1409 map2 = isl_map_copy(map);
1410 map = isl_map_lexmin(map);
1411 assert(isl_map_is_equal(map, map2));
1415 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1416 map = isl_map_read_from_str(ctx, str);
1417 map = isl_map_lexmin(map);
1418 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1419 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1420 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1421 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1422 map2 = isl_map_read_from_str(ctx, str);
1423 assert(isl_map_is_equal(map, map2));
1427 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1428 " 8i' <= i and 8i' >= -7 + i }";
1429 bmap = isl_basic_map_read_from_str(ctx, str);
1430 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1431 map2 = isl_map_from_pw_multi_aff(pma);
1432 map = isl_map_from_basic_map(bmap);
1433 assert(isl_map_is_equal(map, map2));
1437 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1438 map = isl_map_read_from_str(ctx, str);
1439 map = isl_map_lexmin(map);
1440 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1441 map2 = isl_map_read_from_str(ctx, str);
1442 assert(isl_map_is_equal(map, map2));
1452 static int collect_must_may(__isl_take isl_map *dep, int must,
1453 void *dep_user, void *user)
1455 struct must_may *mm = (struct must_may *)user;
1458 mm->must = isl_map_union(mm->must, dep);
1460 mm->may = isl_map_union(mm->may, dep);
1465 static int common_space(void *first, void *second)
1467 int depth = *(int *)first;
1471 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1479 map2 = isl_map_read_from_str(map->ctx, str);
1480 equal = isl_map_is_equal(map, map2);
1486 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1490 equal = map_is_equal(map, str);
1494 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1495 "result not as expected", return -1);
1499 void test_dep(struct isl_ctx *ctx)
1504 isl_access_info *ai;
1511 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1512 map = isl_map_read_from_str(ctx, str);
1513 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1515 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1516 map = isl_map_read_from_str(ctx, str);
1517 ai = isl_access_info_add_source(ai, map, 1, &depth);
1519 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1520 map = isl_map_read_from_str(ctx, str);
1521 ai = isl_access_info_add_source(ai, map, 1, &depth);
1523 flow = isl_access_info_compute_flow(ai);
1524 dim = isl_space_alloc(ctx, 0, 3, 3);
1525 mm.must = isl_map_empty(isl_space_copy(dim));
1526 mm.may = isl_map_empty(dim);
1528 isl_flow_foreach(flow, collect_must_may, &mm);
1530 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1531 " [1,10,0] -> [2,5,0] }";
1532 assert(map_is_equal(mm.must, str));
1533 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1534 assert(map_is_equal(mm.may, str));
1536 isl_map_free(mm.must);
1537 isl_map_free(mm.may);
1538 isl_flow_free(flow);
1541 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1542 map = isl_map_read_from_str(ctx, str);
1543 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1545 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1546 map = isl_map_read_from_str(ctx, str);
1547 ai = isl_access_info_add_source(ai, map, 1, &depth);
1549 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1550 map = isl_map_read_from_str(ctx, str);
1551 ai = isl_access_info_add_source(ai, map, 0, &depth);
1553 flow = isl_access_info_compute_flow(ai);
1554 dim = isl_space_alloc(ctx, 0, 3, 3);
1555 mm.must = isl_map_empty(isl_space_copy(dim));
1556 mm.may = isl_map_empty(dim);
1558 isl_flow_foreach(flow, collect_must_may, &mm);
1560 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1561 assert(map_is_equal(mm.must, str));
1562 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1563 assert(map_is_equal(mm.may, str));
1565 isl_map_free(mm.must);
1566 isl_map_free(mm.may);
1567 isl_flow_free(flow);
1570 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1571 map = isl_map_read_from_str(ctx, str);
1572 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1574 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1575 map = isl_map_read_from_str(ctx, str);
1576 ai = isl_access_info_add_source(ai, map, 0, &depth);
1578 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1579 map = isl_map_read_from_str(ctx, str);
1580 ai = isl_access_info_add_source(ai, map, 0, &depth);
1582 flow = isl_access_info_compute_flow(ai);
1583 dim = isl_space_alloc(ctx, 0, 3, 3);
1584 mm.must = isl_map_empty(isl_space_copy(dim));
1585 mm.may = isl_map_empty(dim);
1587 isl_flow_foreach(flow, collect_must_may, &mm);
1589 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1590 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1591 assert(map_is_equal(mm.may, str));
1592 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1593 assert(map_is_equal(mm.must, str));
1595 isl_map_free(mm.must);
1596 isl_map_free(mm.may);
1597 isl_flow_free(flow);
1600 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1601 map = isl_map_read_from_str(ctx, str);
1602 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1604 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1605 map = isl_map_read_from_str(ctx, str);
1606 ai = isl_access_info_add_source(ai, map, 0, &depth);
1608 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1609 map = isl_map_read_from_str(ctx, str);
1610 ai = isl_access_info_add_source(ai, map, 0, &depth);
1612 flow = isl_access_info_compute_flow(ai);
1613 dim = isl_space_alloc(ctx, 0, 3, 3);
1614 mm.must = isl_map_empty(isl_space_copy(dim));
1615 mm.may = isl_map_empty(dim);
1617 isl_flow_foreach(flow, collect_must_may, &mm);
1619 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1620 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1621 assert(map_is_equal(mm.may, str));
1622 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1623 assert(map_is_equal(mm.must, str));
1625 isl_map_free(mm.must);
1626 isl_map_free(mm.may);
1627 isl_flow_free(flow);
1630 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1631 map = isl_map_read_from_str(ctx, str);
1632 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1634 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1635 map = isl_map_read_from_str(ctx, str);
1636 ai = isl_access_info_add_source(ai, map, 0, &depth);
1638 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1639 map = isl_map_read_from_str(ctx, str);
1640 ai = isl_access_info_add_source(ai, map, 0, &depth);
1642 flow = isl_access_info_compute_flow(ai);
1643 dim = isl_space_alloc(ctx, 0, 3, 3);
1644 mm.must = isl_map_empty(isl_space_copy(dim));
1645 mm.may = isl_map_empty(dim);
1647 isl_flow_foreach(flow, collect_must_may, &mm);
1649 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1650 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1651 assert(map_is_equal(mm.may, str));
1652 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1653 assert(map_is_equal(mm.must, str));
1655 isl_map_free(mm.must);
1656 isl_map_free(mm.may);
1657 isl_flow_free(flow);
1662 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1663 map = isl_map_read_from_str(ctx, str);
1664 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1666 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1667 map = isl_map_read_from_str(ctx, str);
1668 ai = isl_access_info_add_source(ai, map, 1, &depth);
1670 flow = isl_access_info_compute_flow(ai);
1671 dim = isl_space_alloc(ctx, 0, 5, 5);
1672 mm.must = isl_map_empty(isl_space_copy(dim));
1673 mm.may = isl_map_empty(dim);
1675 isl_flow_foreach(flow, collect_must_may, &mm);
1677 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1678 assert(map_is_equal(mm.must, str));
1679 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1680 assert(map_is_equal(mm.may, str));
1682 isl_map_free(mm.must);
1683 isl_map_free(mm.may);
1684 isl_flow_free(flow);
1687 int test_sv(isl_ctx *ctx)
1691 isl_union_map *umap;
1694 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1695 map = isl_map_read_from_str(ctx, str);
1696 sv = isl_map_is_single_valued(map);
1701 isl_die(ctx, isl_error_internal,
1702 "map not detected as single valued", return -1);
1704 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1705 map = isl_map_read_from_str(ctx, str);
1706 sv = isl_map_is_single_valued(map);
1711 isl_die(ctx, isl_error_internal,
1712 "map detected as single valued", return -1);
1714 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1715 umap = isl_union_map_read_from_str(ctx, str);
1716 sv = isl_union_map_is_single_valued(umap);
1717 isl_union_map_free(umap);
1721 isl_die(ctx, isl_error_internal,
1722 "map not detected as single valued", return -1);
1724 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1725 umap = isl_union_map_read_from_str(ctx, str);
1726 sv = isl_union_map_is_single_valued(umap);
1727 isl_union_map_free(umap);
1731 isl_die(ctx, isl_error_internal,
1732 "map detected as single valued", return -1);
1737 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1741 map = isl_map_read_from_str(ctx, str);
1743 assert(isl_map_is_bijective(map));
1745 assert(!isl_map_is_bijective(map));
1749 void test_bijective(struct isl_ctx *ctx)
1751 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1752 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1753 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1754 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1755 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1756 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1757 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1758 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1759 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1760 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1761 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1762 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1763 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1766 void test_pwqp(struct isl_ctx *ctx)
1770 isl_pw_qpolynomial *pwqp1, *pwqp2;
1772 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1773 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1775 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1778 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1779 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1781 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1783 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1785 isl_pw_qpolynomial_free(pwqp1);
1787 str = "{ [i] -> i }";
1788 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1789 str = "{ [k] : exists a : k = 2a }";
1790 set = isl_set_read_from_str(ctx, str);
1791 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1792 str = "{ [i] -> i }";
1793 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1795 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1797 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1799 isl_pw_qpolynomial_free(pwqp1);
1801 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1802 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1804 set = isl_set_read_from_str(ctx, str);
1805 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1806 str = "{ [i] -> 16 }";
1807 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1809 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1811 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1813 isl_pw_qpolynomial_free(pwqp1);
1815 str = "{ [i] -> ([(i)/2]) }";
1816 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1817 str = "{ [k] : exists a : k = 2a+1 }";
1818 set = isl_set_read_from_str(ctx, str);
1819 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1820 str = "{ [i] -> -1/2 + 1/2 * i }";
1821 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1823 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1825 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1827 isl_pw_qpolynomial_free(pwqp1);
1829 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1830 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1831 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1832 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1834 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1836 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1838 isl_pw_qpolynomial_free(pwqp1);
1840 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1841 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1842 str = "{ [x] -> x }";
1843 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1845 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1847 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1849 isl_pw_qpolynomial_free(pwqp1);
1851 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1852 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1853 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1854 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
1855 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1856 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1857 isl_pw_qpolynomial_free(pwqp1);
1860 void test_split_periods(isl_ctx *ctx)
1863 isl_pw_qpolynomial *pwqp;
1865 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1866 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1867 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1868 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1870 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1873 isl_pw_qpolynomial_free(pwqp);
1876 void test_union(isl_ctx *ctx)
1879 isl_union_set *uset1, *uset2;
1880 isl_union_map *umap1, *umap2;
1882 str = "{ [i] : 0 <= i <= 1 }";
1883 uset1 = isl_union_set_read_from_str(ctx, str);
1884 str = "{ [1] -> [0] }";
1885 umap1 = isl_union_map_read_from_str(ctx, str);
1887 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1888 assert(isl_union_map_is_equal(umap1, umap2));
1890 isl_union_map_free(umap1);
1891 isl_union_map_free(umap2);
1893 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1894 umap1 = isl_union_map_read_from_str(ctx, str);
1895 str = "{ A[i]; B[i] }";
1896 uset1 = isl_union_set_read_from_str(ctx, str);
1898 uset2 = isl_union_map_domain(umap1);
1900 assert(isl_union_set_is_equal(uset1, uset2));
1902 isl_union_set_free(uset1);
1903 isl_union_set_free(uset2);
1906 void test_bound(isl_ctx *ctx)
1909 isl_pw_qpolynomial *pwqp;
1910 isl_pw_qpolynomial_fold *pwf;
1912 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1913 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1914 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1915 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
1916 isl_pw_qpolynomial_fold_free(pwf);
1918 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1919 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1920 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1921 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
1922 isl_pw_qpolynomial_fold_free(pwf);
1925 void test_lift(isl_ctx *ctx)
1928 isl_basic_map *bmap;
1929 isl_basic_set *bset;
1931 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1932 bset = isl_basic_set_read_from_str(ctx, str);
1933 bset = isl_basic_set_lift(bset);
1934 bmap = isl_basic_map_from_range(bset);
1935 bset = isl_basic_map_domain(bmap);
1936 isl_basic_set_free(bset);
1939 void test_subset(isl_ctx *ctx)
1942 isl_set *set1, *set2;
1944 str = "{ [112, 0] }";
1945 set1 = isl_set_read_from_str(ctx, str);
1946 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1947 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1948 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1949 set2 = isl_set_read_from_str(ctx, str);
1950 assert(isl_set_is_subset(set1, set2));
1955 void test_factorize(isl_ctx *ctx)
1958 isl_basic_set *bset;
1961 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1962 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1963 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1964 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1965 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1966 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1967 "3i5 >= -2i0 - i2 + 3i4 }";
1968 bset = isl_basic_set_read_from_str(ctx, str);
1969 f = isl_basic_set_factorizer(bset);
1971 isl_basic_set_free(bset);
1972 isl_factorizer_free(f);
1974 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1975 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1976 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1977 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1978 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1979 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1980 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1981 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1982 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1983 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1984 bset = isl_basic_set_read_from_str(ctx, str);
1985 f = isl_basic_set_factorizer(bset);
1987 isl_basic_set_free(bset);
1988 isl_factorizer_free(f);
1991 static int check_injective(__isl_take isl_map *map, void *user)
1993 int *injective = user;
1995 *injective = isl_map_is_injective(map);
1998 if (*injective < 0 || !*injective)
2004 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2005 const char *r, const char *s, int tilable, int parallel)
2009 isl_union_map *W, *R, *S;
2010 isl_union_map *empty;
2011 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2012 isl_union_map *validity, *proximity;
2013 isl_union_map *schedule;
2014 isl_union_map *test;
2015 isl_union_set *delta;
2016 isl_union_set *domain;
2020 isl_schedule *sched;
2021 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2023 D = isl_union_set_read_from_str(ctx, d);
2024 W = isl_union_map_read_from_str(ctx, w);
2025 R = isl_union_map_read_from_str(ctx, r);
2026 S = isl_union_map_read_from_str(ctx, s);
2028 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2029 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2031 empty = isl_union_map_empty(isl_union_map_get_space(S));
2032 isl_union_map_compute_flow(isl_union_map_copy(R),
2033 isl_union_map_copy(W), empty,
2034 isl_union_map_copy(S),
2035 &dep_raw, NULL, NULL, NULL);
2036 isl_union_map_compute_flow(isl_union_map_copy(W),
2037 isl_union_map_copy(W),
2038 isl_union_map_copy(R),
2039 isl_union_map_copy(S),
2040 &dep_waw, &dep_war, NULL, NULL);
2042 dep = isl_union_map_union(dep_waw, dep_war);
2043 dep = isl_union_map_union(dep, dep_raw);
2044 validity = isl_union_map_copy(dep);
2045 proximity = isl_union_map_copy(dep);
2047 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
2048 validity, proximity);
2049 schedule = isl_schedule_get_map(sched);
2050 isl_schedule_free(sched);
2051 isl_union_map_free(W);
2052 isl_union_map_free(R);
2053 isl_union_map_free(S);
2056 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2058 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2059 is_complete = isl_union_set_is_subset(D, domain);
2060 isl_union_set_free(D);
2061 isl_union_set_free(domain);
2063 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2064 test = isl_union_map_apply_range(test, dep);
2065 test = isl_union_map_apply_range(test, schedule);
2067 delta = isl_union_map_deltas(test);
2068 if (isl_union_set_n_set(delta) == 0) {
2072 isl_union_set_free(delta);
2074 delta_set = isl_set_from_union_set(delta);
2076 slice = isl_set_universe(isl_set_get_space(delta_set));
2077 for (i = 0; i < tilable; ++i)
2078 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2079 is_tilable = isl_set_is_subset(delta_set, slice);
2080 isl_set_free(slice);
2082 slice = isl_set_universe(isl_set_get_space(delta_set));
2083 for (i = 0; i < parallel; ++i)
2084 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2085 is_parallel = isl_set_is_subset(delta_set, slice);
2086 isl_set_free(slice);
2088 origin = isl_set_universe(isl_set_get_space(delta_set));
2089 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2090 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2092 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2093 delta_set = isl_set_lexmin(delta_set);
2095 is_nonneg = isl_set_is_equal(delta_set, origin);
2097 isl_set_free(origin);
2098 isl_set_free(delta_set);
2101 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2102 is_injection < 0 || is_complete < 0)
2105 isl_die(ctx, isl_error_unknown,
2106 "generated schedule incomplete", return -1);
2108 isl_die(ctx, isl_error_unknown,
2109 "generated schedule not injective on each statement",
2112 isl_die(ctx, isl_error_unknown,
2113 "negative dependences in generated schedule",
2116 isl_die(ctx, isl_error_unknown,
2117 "generated schedule not as tilable as expected",
2120 isl_die(ctx, isl_error_unknown,
2121 "generated schedule not as parallel as expected",
2127 int test_special_schedule(isl_ctx *ctx, const char *domain,
2128 const char *validity, const char *proximity, const char *expected_sched)
2132 isl_union_map *prox;
2133 isl_union_map *sched1, *sched2;
2134 isl_schedule *schedule;
2137 dom = isl_union_set_read_from_str(ctx, domain);
2138 dep = isl_union_map_read_from_str(ctx, validity);
2139 prox = isl_union_map_read_from_str(ctx, proximity);
2140 schedule = isl_union_set_compute_schedule(dom, dep, prox);
2141 sched1 = isl_schedule_get_map(schedule);
2142 isl_schedule_free(schedule);
2144 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2146 equal = isl_union_map_is_equal(sched1, sched2);
2147 isl_union_map_free(sched1);
2148 isl_union_map_free(sched2);
2153 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2159 int test_schedule(isl_ctx *ctx)
2161 const char *D, *W, *R, *V, *P, *S;
2164 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2165 W = "{ S1[t,i] -> a[t,i] }";
2166 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2167 "S1[t,i] -> a[t-1,i+1] }";
2168 S = "{ S1[t,i] -> [t,i] }";
2169 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2172 /* Fig. 5 of CC2008 */
2173 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2175 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2176 "j >= 2 and j <= -1 + N }";
2177 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2178 "j >= 2 and j <= -1 + N; "
2179 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2180 "j >= 2 and j <= -1 + N }";
2181 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2182 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2185 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2186 W = "{ S1[i] -> a[i] }";
2187 R = "{ S2[i] -> a[i+1] }";
2188 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2189 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2192 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2193 W = "{ S1[i] -> a[i] }";
2194 R = "{ S2[i] -> a[9-i] }";
2195 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2196 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2199 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2200 W = "{ S1[i] -> a[i] }";
2201 R = "[N] -> { S2[i] -> a[N-1-i] }";
2202 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2203 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2206 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2207 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2208 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2209 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2210 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2213 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2214 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2215 R = "{ S2[i,j] -> a[i-1,j] }";
2216 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2217 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2220 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2221 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2222 R = "{ S2[i,j] -> a[i,j-1] }";
2223 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2224 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2227 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2228 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2229 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2230 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2231 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2232 "S_0[] -> [0, 0, 0] }";
2233 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2235 ctx->opt->schedule_parametric = 0;
2236 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2238 ctx->opt->schedule_parametric = 1;
2240 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2241 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2242 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2243 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2244 "S4[i] -> a[i,N] }";
2245 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2246 "S4[i] -> [4,i,0] }";
2247 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2250 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2251 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2253 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2255 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2257 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2258 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2261 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2262 " S_2[t] : t >= 0 and t <= -1 + N; "
2263 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2265 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2266 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2267 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2268 "i >= 0 and i <= -1 + N }";
2269 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2270 "i >= 0 and i <= -1 + N; "
2271 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2272 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2273 " S_0[t] -> [0, t, 0] }";
2275 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2277 ctx->opt->schedule_parametric = 0;
2278 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2280 ctx->opt->schedule_parametric = 1;
2282 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2283 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2284 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2287 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2288 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2289 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2290 "j >= 0 and j <= -1 + N; "
2291 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2292 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2293 "j >= 0 and j <= -1 + N; "
2294 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2295 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2296 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2299 D = "{ S_0[i] : i >= 0 }";
2300 W = "{ S_0[i] -> a[i] : i >= 0 }";
2301 R = "{ S_0[i] -> a[0] : i >= 0 }";
2302 S = "{ S_0[i] -> [0, i, 0] }";
2303 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2306 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2307 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2308 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2309 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2310 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2313 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2314 "k <= -1 + n and k >= 0 }";
2315 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2316 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2317 "k <= -1 + n and k >= 0; "
2318 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2319 "k <= -1 + n and k >= 0; "
2320 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2321 "k <= -1 + n and k >= 0 }";
2322 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2323 ctx->opt->schedule_outer_zero_distance = 1;
2324 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2326 ctx->opt->schedule_outer_zero_distance = 0;
2328 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
2329 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2330 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2331 "Stmt_for_body24[i0, i1, 1, 0]:"
2332 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2333 "Stmt_for_body7[i0, i1, i2]:"
2334 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2337 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
2338 "Stmt_for_body24[1, i1, i2, i3]:"
2339 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2341 "Stmt_for_body24[0, i1, i2, i3] -> "
2342 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2343 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2345 "Stmt_for_body24[0, i1, i2, i3] ->"
2346 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2347 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2348 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2349 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2350 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2351 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2352 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2353 "i1 <= 6 and i1 >= 0;"
2354 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2355 "Stmt_for_body7[i0, i1, i2] -> "
2356 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2357 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2358 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2359 "Stmt_for_body7[i0, i1, i2] -> "
2360 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2361 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2362 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2364 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2365 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2366 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2368 if (test_special_schedule(ctx, D, V, P, S) < 0)
2371 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2372 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2373 "j >= 1 and j <= 7;"
2374 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2375 "j >= 1 and j <= 8 }";
2377 S = "{ S_0[i, j] -> [i + j, j] }";
2378 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2379 if (test_special_schedule(ctx, D, V, P, S) < 0)
2381 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2383 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2384 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2385 "j >= 0 and j <= -1 + i }";
2386 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2387 "i <= -1 + N and j >= 0;"
2388 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2391 S = "{ S_0[i, j] -> [i, j] }";
2392 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2393 if (test_special_schedule(ctx, D, V, P, S) < 0)
2395 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2397 /* Test both algorithms on a case with only proximity dependences. */
2398 D = "{ S[i,j] : 0 <= i <= 10 }";
2400 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2401 S = "{ S[i, j] -> [j, i] }";
2402 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2403 if (test_special_schedule(ctx, D, V, P, S) < 0)
2405 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2406 return test_special_schedule(ctx, D, V, P, S);
2409 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2411 isl_union_map *umap;
2414 umap = isl_union_map_read_from_str(ctx, str);
2415 test = isl_union_map_plain_is_injective(umap);
2416 isl_union_map_free(umap);
2419 if (test == injective)
2422 isl_die(ctx, isl_error_unknown,
2423 "map not detected as injective", return -1);
2425 isl_die(ctx, isl_error_unknown,
2426 "map detected as injective", return -1);
2429 int test_injective(isl_ctx *ctx)
2433 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2435 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2437 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2439 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2441 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2443 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2445 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2447 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2450 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2451 if (test_plain_injective(ctx, str, 1))
2453 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2454 if (test_plain_injective(ctx, str, 0))
2460 int test_aff(isl_ctx *ctx)
2465 isl_local_space *ls;
2469 dim = isl_space_set_alloc(ctx, 0, 1);
2470 ls = isl_local_space_from_space(dim);
2471 aff = isl_aff_zero_on_domain(ls);
2473 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2474 aff = isl_aff_scale_down_ui(aff, 3);
2475 aff = isl_aff_floor(aff);
2476 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2477 aff = isl_aff_scale_down_ui(aff, 2);
2478 aff = isl_aff_floor(aff);
2479 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2482 set = isl_set_read_from_str(ctx, str);
2483 aff = isl_aff_gist(aff, set);
2485 aff = isl_aff_add_constant_si(aff, -16);
2486 zero = isl_aff_plain_is_zero(aff);
2492 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2497 int test_dim_max(isl_ctx *ctx)
2501 isl_set *set1, *set2;
2506 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2507 set = isl_set_read_from_str(ctx, str);
2508 pwaff = isl_set_dim_max(set, 0);
2509 set1 = isl_set_from_pw_aff(pwaff);
2510 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2511 set2 = isl_set_read_from_str(ctx, str);
2512 equal = isl_set_is_equal(set1, set2);
2518 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2520 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2521 set = isl_set_read_from_str(ctx, str);
2522 pwaff = isl_set_dim_max(set, 0);
2523 set1 = isl_set_from_pw_aff(pwaff);
2524 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2525 set2 = isl_set_read_from_str(ctx, str);
2526 equal = isl_set_is_equal(set1, set2);
2532 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2534 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2535 set = isl_set_read_from_str(ctx, str);
2536 pwaff = isl_set_dim_max(set, 0);
2537 set1 = isl_set_from_pw_aff(pwaff);
2538 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2539 set2 = isl_set_read_from_str(ctx, str);
2540 equal = isl_set_is_equal(set1, set2);
2546 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2548 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2549 "0 <= i < N and 0 <= j < M }";
2550 map = isl_map_read_from_str(ctx, str);
2551 set = isl_map_range(map);
2553 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
2554 set1 = isl_set_from_pw_aff(pwaff);
2555 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2556 set2 = isl_set_read_from_str(ctx, str);
2557 equal = isl_set_is_equal(set1, set2);
2561 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
2562 set1 = isl_set_from_pw_aff(pwaff);
2563 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2564 set2 = isl_set_read_from_str(ctx, str);
2565 if (equal >= 0 && equal)
2566 equal = isl_set_is_equal(set1, set2);
2575 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2580 int test_product(isl_ctx *ctx)
2584 isl_union_set *uset1, *uset2;
2588 set = isl_set_read_from_str(ctx, str);
2589 set = isl_set_product(set, isl_set_copy(set));
2590 ok = isl_set_is_wrapping(set);
2595 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2598 uset1 = isl_union_set_read_from_str(ctx, str);
2599 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
2600 str = "{ [[] -> []] }";
2601 uset2 = isl_union_set_read_from_str(ctx, str);
2602 ok = isl_union_set_is_equal(uset1, uset2);
2603 isl_union_set_free(uset1);
2604 isl_union_set_free(uset2);
2608 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2613 int test_equal(isl_ctx *ctx)
2616 isl_set *set, *set2;
2620 set = isl_set_read_from_str(ctx, str);
2622 set2 = isl_set_read_from_str(ctx, str);
2623 equal = isl_set_is_equal(set, set2);
2629 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2634 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
2635 enum isl_dim_type type, unsigned pos, int fixed)
2639 test = isl_map_plain_is_fixed(map, type, pos, NULL);
2646 isl_die(ctx, isl_error_unknown,
2647 "map not detected as fixed", return -1);
2649 isl_die(ctx, isl_error_unknown,
2650 "map detected as fixed", return -1);
2653 int test_fixed(isl_ctx *ctx)
2658 str = "{ [i] -> [i] }";
2659 map = isl_map_read_from_str(ctx, str);
2660 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
2662 str = "{ [i] -> [1] }";
2663 map = isl_map_read_from_str(ctx, str);
2664 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2666 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2667 map = isl_map_read_from_str(ctx, str);
2668 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2670 map = isl_map_read_from_str(ctx, str);
2671 map = isl_map_neg(map);
2672 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2678 int test_vertices(isl_ctx *ctx)
2681 isl_basic_set *bset;
2682 isl_vertices *vertices;
2684 str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2685 bset = isl_basic_set_read_from_str(ctx, str);
2686 vertices = isl_basic_set_compute_vertices(bset);
2687 isl_basic_set_free(bset);
2688 isl_vertices_free(vertices);
2692 str = "{ A[t, i] : t = 14 and i = 1 }";
2693 bset = isl_basic_set_read_from_str(ctx, str);
2694 vertices = isl_basic_set_compute_vertices(bset);
2695 isl_basic_set_free(bset);
2696 isl_vertices_free(vertices);
2703 int test_union_pw(isl_ctx *ctx)
2707 isl_union_set *uset;
2708 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
2710 str = "{ [x] -> x^2 }";
2711 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
2712 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
2713 uset = isl_union_pw_qpolynomial_domain(upwqp1);
2714 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
2715 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
2716 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
2717 isl_union_pw_qpolynomial_free(upwqp1);
2718 isl_union_pw_qpolynomial_free(upwqp2);
2722 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2727 int test_output(isl_ctx *ctx)
2735 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2736 pa = isl_pw_aff_read_from_str(ctx, str);
2738 p = isl_printer_to_str(ctx);
2739 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
2740 p = isl_printer_print_pw_aff(p, pa);
2741 s = isl_printer_get_str(p);
2742 isl_printer_free(p);
2743 isl_pw_aff_free(pa);
2744 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2749 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2754 int test_sample(isl_ctx *ctx)
2757 isl_basic_set *bset1, *bset2;
2760 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2761 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2762 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2763 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2764 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2765 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2766 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2767 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2768 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2769 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2770 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2771 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2772 "d - 1073741821e and "
2773 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2774 "3j >= 1 - a + b + 2e and "
2775 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2776 "3i <= 4 - a + 4b - e and "
2777 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2778 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2779 "c <= -1 + a and 3i >= -2 - a + 3e and "
2780 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2781 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2782 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2783 "1073741823e >= 1 + 1073741823b - d and "
2784 "3i >= 1073741823b + c - 1073741823e - f and "
2785 "3i >= 1 + 2b + e + 3g }";
2786 bset1 = isl_basic_set_read_from_str(ctx, str);
2787 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
2788 empty = isl_basic_set_is_empty(bset2);
2789 subset = isl_basic_set_is_subset(bset2, bset1);
2790 isl_basic_set_free(bset1);
2791 isl_basic_set_free(bset2);
2793 isl_die(ctx, isl_error_unknown, "point not found", return -1);
2795 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
2800 int test_fixed_power(isl_ctx *ctx)
2808 str = "{ [i] -> [i + 1] }";
2809 map = isl_map_read_from_str(ctx, str);
2810 isl_int_set_si(exp, 23);
2811 map = isl_map_fixed_power(map, exp);
2812 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
2823 struct isl_ctx *ctx;
2825 srcdir = getenv("srcdir");
2828 ctx = isl_ctx_alloc();
2829 if (test_fixed_power(ctx) < 0)
2831 if (test_sample(ctx) < 0)
2833 if (test_output(ctx) < 0)
2835 if (test_vertices(ctx) < 0)
2837 if (test_fixed(ctx) < 0)
2839 if (test_equal(ctx) < 0)
2841 if (test_product(ctx) < 0)
2843 if (test_dim_max(ctx) < 0)
2845 if (test_aff(ctx) < 0)
2847 if (test_injective(ctx) < 0)
2849 if (test_schedule(ctx) < 0)
2851 if (test_union_pw(ctx) < 0)
2853 test_factorize(ctx);
2858 test_split_periods(ctx);
2859 if (test_parse(ctx) < 0)
2863 if (test_sv(ctx) < 0)
2865 test_bijective(ctx);
2869 test_construction(ctx);
2872 test_application(ctx);
2873 if (test_affine_hull(ctx) < 0)
2875 test_convex_hull(ctx);
2877 if (test_coalesce(ctx) < 0)