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)
1109 if (test_coalesce_set(ctx,
1110 "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1111 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1112 "j >= 1 and j' <= i + j - i' and i >= 1; "
1113 "[1, 1, 1, 1] }", 0) < 0)
1118 void test_closure(struct isl_ctx *ctx)
1122 isl_map *up, *right;
1123 isl_map *map, *map2;
1126 /* COCOA example 1 */
1127 map = isl_map_read_from_str(ctx,
1128 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1129 "1 <= i and i < n and 1 <= j and j < n or "
1130 "i2 = i + 1 and j2 = j - 1 and "
1131 "1 <= i and i < n and 2 <= j and j <= n }");
1132 map = isl_map_power(map, &exact);
1136 /* COCOA example 1 */
1137 map = isl_map_read_from_str(ctx,
1138 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1139 "1 <= i and i < n and 1 <= j and j < n or "
1140 "i2 = i + 1 and j2 = j - 1 and "
1141 "1 <= i and i < n and 2 <= j and j <= n }");
1142 map = isl_map_transitive_closure(map, &exact);
1144 map2 = isl_map_read_from_str(ctx,
1145 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1146 "1 <= i and i < n and 1 <= j and j <= n and "
1147 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1148 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1149 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1150 assert(isl_map_is_equal(map, map2));
1154 map = isl_map_read_from_str(ctx,
1155 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1156 " 0 <= y and y <= n }");
1157 map = isl_map_transitive_closure(map, &exact);
1158 map2 = isl_map_read_from_str(ctx,
1159 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1160 " 0 <= y and y <= n }");
1161 assert(isl_map_is_equal(map, map2));
1165 /* COCOA example 2 */
1166 map = isl_map_read_from_str(ctx,
1167 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1168 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1169 "i2 = i + 2 and j2 = j - 2 and "
1170 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1171 map = isl_map_transitive_closure(map, &exact);
1173 map2 = isl_map_read_from_str(ctx,
1174 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1175 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1176 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1177 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1178 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1179 assert(isl_map_is_equal(map, map2));
1183 /* COCOA Fig.2 left */
1184 map = isl_map_read_from_str(ctx,
1185 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1186 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1188 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1189 "j <= 2 i - 3 and j <= n - 2 or "
1190 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1191 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1192 map = isl_map_transitive_closure(map, &exact);
1196 /* COCOA Fig.2 right */
1197 map = isl_map_read_from_str(ctx,
1198 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1199 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1201 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1202 "j <= 2 i - 4 and j <= n - 3 or "
1203 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1204 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1205 map = isl_map_power(map, &exact);
1209 /* COCOA Fig.2 right */
1210 map = isl_map_read_from_str(ctx,
1211 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1212 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1214 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1215 "j <= 2 i - 4 and j <= n - 3 or "
1216 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1217 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1218 map = isl_map_transitive_closure(map, &exact);
1220 map2 = isl_map_read_from_str(ctx,
1221 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1222 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1223 "j <= n and 3 + i + 2 j <= 3 n and "
1224 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1225 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1226 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1227 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1228 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1229 assert(isl_map_is_equal(map, map2));
1233 /* COCOA Fig.1 right */
1234 dom = isl_set_read_from_str(ctx,
1235 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1236 "2 x - 3 y + 3 >= 0 }");
1237 right = isl_map_read_from_str(ctx,
1238 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1239 up = isl_map_read_from_str(ctx,
1240 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1241 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1242 right = isl_map_intersect_range(right, isl_set_copy(dom));
1243 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1244 up = isl_map_intersect_range(up, dom);
1245 map = isl_map_union(up, right);
1246 map = isl_map_transitive_closure(map, &exact);
1248 map2 = isl_map_read_from_str(ctx,
1249 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1250 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1251 assert(isl_map_is_equal(map, map2));
1255 /* COCOA Theorem 1 counter example */
1256 map = isl_map_read_from_str(ctx,
1257 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1258 "i2 = 1 and j2 = j or "
1259 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1260 map = isl_map_transitive_closure(map, &exact);
1264 map = isl_map_read_from_str(ctx,
1265 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1266 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1267 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1268 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1269 map = isl_map_transitive_closure(map, &exact);
1273 /* Kelly et al 1996, fig 12 */
1274 map = isl_map_read_from_str(ctx,
1275 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1276 "1 <= i,j,j+1 <= n or "
1277 "j = n and j2 = 1 and i2 = i + 1 and "
1278 "1 <= i,i+1 <= n }");
1279 map = isl_map_transitive_closure(map, &exact);
1281 map2 = isl_map_read_from_str(ctx,
1282 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1283 "1 <= i <= n and i = i2 or "
1284 "1 <= i < i2 <= n and 1 <= j <= n and "
1286 assert(isl_map_is_equal(map, map2));
1290 /* Omega's closure4 */
1291 map = isl_map_read_from_str(ctx,
1292 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1293 "1 <= x,y <= 10 or "
1294 "x2 = x + 1 and y2 = y and "
1295 "1 <= x <= 20 && 5 <= y <= 15 }");
1296 map = isl_map_transitive_closure(map, &exact);
1300 map = isl_map_read_from_str(ctx,
1301 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1302 map = isl_map_transitive_closure(map, &exact);
1304 map2 = isl_map_read_from_str(ctx,
1305 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1306 assert(isl_map_is_equal(map, map2));
1310 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1311 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1312 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1313 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1314 map = isl_map_read_from_str(ctx, str);
1315 map = isl_map_transitive_closure(map, &exact);
1317 map2 = isl_map_read_from_str(ctx, str);
1318 assert(isl_map_is_equal(map, map2));
1322 str = "{[0] -> [1]; [2] -> [3]}";
1323 map = isl_map_read_from_str(ctx, str);
1324 map = isl_map_transitive_closure(map, &exact);
1326 map2 = isl_map_read_from_str(ctx, str);
1327 assert(isl_map_is_equal(map, map2));
1331 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1332 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1333 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1334 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1335 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1336 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1337 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1338 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1339 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1340 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1341 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1342 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1343 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1344 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1345 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1346 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1347 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1348 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1349 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1350 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1351 map = isl_map_read_from_str(ctx, str);
1352 map = isl_map_transitive_closure(map, NULL);
1357 void test_lex(struct isl_ctx *ctx)
1362 dim = isl_space_set_alloc(ctx, 0, 0);
1363 map = isl_map_lex_le(dim);
1364 assert(!isl_map_is_empty(map));
1368 void test_lexmin(struct isl_ctx *ctx)
1371 isl_basic_map *bmap;
1372 isl_map *map, *map2;
1375 isl_pw_multi_aff *pma;
1377 str = "[p0, p1] -> { [] -> [] : "
1378 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1379 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1380 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1381 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1382 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1383 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1384 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1385 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1386 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1387 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1388 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1389 map = isl_map_read_from_str(ctx, str);
1390 map = isl_map_lexmin(map);
1393 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1394 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1395 set = isl_set_read_from_str(ctx, str);
1396 set = isl_set_lexmax(set);
1397 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1398 set2 = isl_set_read_from_str(ctx, str);
1399 set = isl_set_intersect(set, set2);
1400 assert(!isl_set_is_empty(set));
1403 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1404 map = isl_map_read_from_str(ctx, str);
1405 map = isl_map_lexmin(map);
1406 str = "{ [x] -> [5] : 6 <= x <= 8; "
1407 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1408 map2 = isl_map_read_from_str(ctx, str);
1409 assert(isl_map_is_equal(map, map2));
1413 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1414 map = isl_map_read_from_str(ctx, str);
1415 map2 = isl_map_copy(map);
1416 map = isl_map_lexmin(map);
1417 assert(isl_map_is_equal(map, map2));
1421 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1422 map = isl_map_read_from_str(ctx, str);
1423 map = isl_map_lexmin(map);
1424 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1425 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1426 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1427 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1428 map2 = isl_map_read_from_str(ctx, str);
1429 assert(isl_map_is_equal(map, map2));
1433 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1434 " 8i' <= i and 8i' >= -7 + i }";
1435 bmap = isl_basic_map_read_from_str(ctx, str);
1436 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1437 map2 = isl_map_from_pw_multi_aff(pma);
1438 map = isl_map_from_basic_map(bmap);
1439 assert(isl_map_is_equal(map, map2));
1443 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1444 map = isl_map_read_from_str(ctx, str);
1445 map = isl_map_lexmin(map);
1446 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1447 map2 = isl_map_read_from_str(ctx, str);
1448 assert(isl_map_is_equal(map, map2));
1458 static int collect_must_may(__isl_take isl_map *dep, int must,
1459 void *dep_user, void *user)
1461 struct must_may *mm = (struct must_may *)user;
1464 mm->must = isl_map_union(mm->must, dep);
1466 mm->may = isl_map_union(mm->may, dep);
1471 static int common_space(void *first, void *second)
1473 int depth = *(int *)first;
1477 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1485 map2 = isl_map_read_from_str(map->ctx, str);
1486 equal = isl_map_is_equal(map, map2);
1492 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1496 equal = map_is_equal(map, str);
1500 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1501 "result not as expected", return -1);
1505 void test_dep(struct isl_ctx *ctx)
1510 isl_access_info *ai;
1517 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1518 map = isl_map_read_from_str(ctx, str);
1519 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1521 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1522 map = isl_map_read_from_str(ctx, str);
1523 ai = isl_access_info_add_source(ai, map, 1, &depth);
1525 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1526 map = isl_map_read_from_str(ctx, str);
1527 ai = isl_access_info_add_source(ai, map, 1, &depth);
1529 flow = isl_access_info_compute_flow(ai);
1530 dim = isl_space_alloc(ctx, 0, 3, 3);
1531 mm.must = isl_map_empty(isl_space_copy(dim));
1532 mm.may = isl_map_empty(dim);
1534 isl_flow_foreach(flow, collect_must_may, &mm);
1536 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1537 " [1,10,0] -> [2,5,0] }";
1538 assert(map_is_equal(mm.must, str));
1539 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1540 assert(map_is_equal(mm.may, str));
1542 isl_map_free(mm.must);
1543 isl_map_free(mm.may);
1544 isl_flow_free(flow);
1547 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1548 map = isl_map_read_from_str(ctx, str);
1549 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1551 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1552 map = isl_map_read_from_str(ctx, str);
1553 ai = isl_access_info_add_source(ai, map, 1, &depth);
1555 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1556 map = isl_map_read_from_str(ctx, str);
1557 ai = isl_access_info_add_source(ai, map, 0, &depth);
1559 flow = isl_access_info_compute_flow(ai);
1560 dim = isl_space_alloc(ctx, 0, 3, 3);
1561 mm.must = isl_map_empty(isl_space_copy(dim));
1562 mm.may = isl_map_empty(dim);
1564 isl_flow_foreach(flow, collect_must_may, &mm);
1566 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1567 assert(map_is_equal(mm.must, str));
1568 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1569 assert(map_is_equal(mm.may, str));
1571 isl_map_free(mm.must);
1572 isl_map_free(mm.may);
1573 isl_flow_free(flow);
1576 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1577 map = isl_map_read_from_str(ctx, str);
1578 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1580 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1581 map = isl_map_read_from_str(ctx, str);
1582 ai = isl_access_info_add_source(ai, map, 0, &depth);
1584 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1585 map = isl_map_read_from_str(ctx, str);
1586 ai = isl_access_info_add_source(ai, map, 0, &depth);
1588 flow = isl_access_info_compute_flow(ai);
1589 dim = isl_space_alloc(ctx, 0, 3, 3);
1590 mm.must = isl_map_empty(isl_space_copy(dim));
1591 mm.may = isl_map_empty(dim);
1593 isl_flow_foreach(flow, collect_must_may, &mm);
1595 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1596 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1597 assert(map_is_equal(mm.may, str));
1598 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1599 assert(map_is_equal(mm.must, str));
1601 isl_map_free(mm.must);
1602 isl_map_free(mm.may);
1603 isl_flow_free(flow);
1606 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1607 map = isl_map_read_from_str(ctx, str);
1608 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1610 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1611 map = isl_map_read_from_str(ctx, str);
1612 ai = isl_access_info_add_source(ai, map, 0, &depth);
1614 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1615 map = isl_map_read_from_str(ctx, str);
1616 ai = isl_access_info_add_source(ai, map, 0, &depth);
1618 flow = isl_access_info_compute_flow(ai);
1619 dim = isl_space_alloc(ctx, 0, 3, 3);
1620 mm.must = isl_map_empty(isl_space_copy(dim));
1621 mm.may = isl_map_empty(dim);
1623 isl_flow_foreach(flow, collect_must_may, &mm);
1625 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1626 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1627 assert(map_is_equal(mm.may, str));
1628 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1629 assert(map_is_equal(mm.must, str));
1631 isl_map_free(mm.must);
1632 isl_map_free(mm.may);
1633 isl_flow_free(flow);
1636 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1637 map = isl_map_read_from_str(ctx, str);
1638 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1640 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1641 map = isl_map_read_from_str(ctx, str);
1642 ai = isl_access_info_add_source(ai, map, 0, &depth);
1644 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1645 map = isl_map_read_from_str(ctx, str);
1646 ai = isl_access_info_add_source(ai, map, 0, &depth);
1648 flow = isl_access_info_compute_flow(ai);
1649 dim = isl_space_alloc(ctx, 0, 3, 3);
1650 mm.must = isl_map_empty(isl_space_copy(dim));
1651 mm.may = isl_map_empty(dim);
1653 isl_flow_foreach(flow, collect_must_may, &mm);
1655 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1656 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1657 assert(map_is_equal(mm.may, str));
1658 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1659 assert(map_is_equal(mm.must, str));
1661 isl_map_free(mm.must);
1662 isl_map_free(mm.may);
1663 isl_flow_free(flow);
1668 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1669 map = isl_map_read_from_str(ctx, str);
1670 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1672 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1673 map = isl_map_read_from_str(ctx, str);
1674 ai = isl_access_info_add_source(ai, map, 1, &depth);
1676 flow = isl_access_info_compute_flow(ai);
1677 dim = isl_space_alloc(ctx, 0, 5, 5);
1678 mm.must = isl_map_empty(isl_space_copy(dim));
1679 mm.may = isl_map_empty(dim);
1681 isl_flow_foreach(flow, collect_must_may, &mm);
1683 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1684 assert(map_is_equal(mm.must, str));
1685 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1686 assert(map_is_equal(mm.may, str));
1688 isl_map_free(mm.must);
1689 isl_map_free(mm.may);
1690 isl_flow_free(flow);
1693 int test_sv(isl_ctx *ctx)
1697 isl_union_map *umap;
1700 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1701 map = isl_map_read_from_str(ctx, str);
1702 sv = isl_map_is_single_valued(map);
1707 isl_die(ctx, isl_error_internal,
1708 "map not detected as single valued", return -1);
1710 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1711 map = isl_map_read_from_str(ctx, str);
1712 sv = isl_map_is_single_valued(map);
1717 isl_die(ctx, isl_error_internal,
1718 "map detected as single valued", return -1);
1720 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1721 umap = isl_union_map_read_from_str(ctx, str);
1722 sv = isl_union_map_is_single_valued(umap);
1723 isl_union_map_free(umap);
1727 isl_die(ctx, isl_error_internal,
1728 "map not detected as single valued", return -1);
1730 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1731 umap = isl_union_map_read_from_str(ctx, str);
1732 sv = isl_union_map_is_single_valued(umap);
1733 isl_union_map_free(umap);
1737 isl_die(ctx, isl_error_internal,
1738 "map detected as single valued", return -1);
1743 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1747 map = isl_map_read_from_str(ctx, str);
1749 assert(isl_map_is_bijective(map));
1751 assert(!isl_map_is_bijective(map));
1755 void test_bijective(struct isl_ctx *ctx)
1757 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1758 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1759 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1760 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1761 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1762 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1763 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1764 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1765 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1766 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1767 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1768 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1769 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1772 void test_pwqp(struct isl_ctx *ctx)
1776 isl_pw_qpolynomial *pwqp1, *pwqp2;
1778 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1779 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1781 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1784 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1785 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1787 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1789 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1791 isl_pw_qpolynomial_free(pwqp1);
1793 str = "{ [i] -> i }";
1794 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1795 str = "{ [k] : exists a : k = 2a }";
1796 set = isl_set_read_from_str(ctx, str);
1797 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1798 str = "{ [i] -> i }";
1799 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1801 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1803 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1805 isl_pw_qpolynomial_free(pwqp1);
1807 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1808 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1810 set = isl_set_read_from_str(ctx, str);
1811 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1812 str = "{ [i] -> 16 }";
1813 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1815 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1817 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1819 isl_pw_qpolynomial_free(pwqp1);
1821 str = "{ [i] -> ([(i)/2]) }";
1822 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1823 str = "{ [k] : exists a : k = 2a+1 }";
1824 set = isl_set_read_from_str(ctx, str);
1825 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1826 str = "{ [i] -> -1/2 + 1/2 * i }";
1827 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1829 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1831 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1833 isl_pw_qpolynomial_free(pwqp1);
1835 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1836 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1837 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1838 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1840 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1842 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1844 isl_pw_qpolynomial_free(pwqp1);
1846 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1847 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1848 str = "{ [x] -> x }";
1849 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1851 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1853 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1855 isl_pw_qpolynomial_free(pwqp1);
1857 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1858 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1859 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1860 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
1861 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1862 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1863 isl_pw_qpolynomial_free(pwqp1);
1866 void test_split_periods(isl_ctx *ctx)
1869 isl_pw_qpolynomial *pwqp;
1871 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1872 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1873 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1874 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1876 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1879 isl_pw_qpolynomial_free(pwqp);
1882 void test_union(isl_ctx *ctx)
1885 isl_union_set *uset1, *uset2;
1886 isl_union_map *umap1, *umap2;
1888 str = "{ [i] : 0 <= i <= 1 }";
1889 uset1 = isl_union_set_read_from_str(ctx, str);
1890 str = "{ [1] -> [0] }";
1891 umap1 = isl_union_map_read_from_str(ctx, str);
1893 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1894 assert(isl_union_map_is_equal(umap1, umap2));
1896 isl_union_map_free(umap1);
1897 isl_union_map_free(umap2);
1899 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1900 umap1 = isl_union_map_read_from_str(ctx, str);
1901 str = "{ A[i]; B[i] }";
1902 uset1 = isl_union_set_read_from_str(ctx, str);
1904 uset2 = isl_union_map_domain(umap1);
1906 assert(isl_union_set_is_equal(uset1, uset2));
1908 isl_union_set_free(uset1);
1909 isl_union_set_free(uset2);
1912 void test_bound(isl_ctx *ctx)
1915 isl_pw_qpolynomial *pwqp;
1916 isl_pw_qpolynomial_fold *pwf;
1918 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
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) == 4);
1922 isl_pw_qpolynomial_fold_free(pwf);
1924 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1925 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1926 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1927 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
1928 isl_pw_qpolynomial_fold_free(pwf);
1931 void test_lift(isl_ctx *ctx)
1934 isl_basic_map *bmap;
1935 isl_basic_set *bset;
1937 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1938 bset = isl_basic_set_read_from_str(ctx, str);
1939 bset = isl_basic_set_lift(bset);
1940 bmap = isl_basic_map_from_range(bset);
1941 bset = isl_basic_map_domain(bmap);
1942 isl_basic_set_free(bset);
1945 void test_subset(isl_ctx *ctx)
1948 isl_set *set1, *set2;
1950 str = "{ [112, 0] }";
1951 set1 = isl_set_read_from_str(ctx, str);
1952 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1953 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1954 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1955 set2 = isl_set_read_from_str(ctx, str);
1956 assert(isl_set_is_subset(set1, set2));
1961 void test_factorize(isl_ctx *ctx)
1964 isl_basic_set *bset;
1967 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1968 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1969 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1970 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1971 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1972 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1973 "3i5 >= -2i0 - i2 + 3i4 }";
1974 bset = isl_basic_set_read_from_str(ctx, str);
1975 f = isl_basic_set_factorizer(bset);
1977 isl_basic_set_free(bset);
1978 isl_factorizer_free(f);
1980 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1981 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1982 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1983 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1984 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1985 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1986 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1987 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1988 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1989 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1990 bset = isl_basic_set_read_from_str(ctx, str);
1991 f = isl_basic_set_factorizer(bset);
1993 isl_basic_set_free(bset);
1994 isl_factorizer_free(f);
1997 static int check_injective(__isl_take isl_map *map, void *user)
1999 int *injective = user;
2001 *injective = isl_map_is_injective(map);
2004 if (*injective < 0 || !*injective)
2010 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2011 const char *r, const char *s, int tilable, int parallel)
2015 isl_union_map *W, *R, *S;
2016 isl_union_map *empty;
2017 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2018 isl_union_map *validity, *proximity;
2019 isl_union_map *schedule;
2020 isl_union_map *test;
2021 isl_union_set *delta;
2022 isl_union_set *domain;
2026 isl_schedule *sched;
2027 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2029 D = isl_union_set_read_from_str(ctx, d);
2030 W = isl_union_map_read_from_str(ctx, w);
2031 R = isl_union_map_read_from_str(ctx, r);
2032 S = isl_union_map_read_from_str(ctx, s);
2034 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2035 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2037 empty = isl_union_map_empty(isl_union_map_get_space(S));
2038 isl_union_map_compute_flow(isl_union_map_copy(R),
2039 isl_union_map_copy(W), empty,
2040 isl_union_map_copy(S),
2041 &dep_raw, NULL, NULL, NULL);
2042 isl_union_map_compute_flow(isl_union_map_copy(W),
2043 isl_union_map_copy(W),
2044 isl_union_map_copy(R),
2045 isl_union_map_copy(S),
2046 &dep_waw, &dep_war, NULL, NULL);
2048 dep = isl_union_map_union(dep_waw, dep_war);
2049 dep = isl_union_map_union(dep, dep_raw);
2050 validity = isl_union_map_copy(dep);
2051 proximity = isl_union_map_copy(dep);
2053 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
2054 validity, proximity);
2055 schedule = isl_schedule_get_map(sched);
2056 isl_schedule_free(sched);
2057 isl_union_map_free(W);
2058 isl_union_map_free(R);
2059 isl_union_map_free(S);
2062 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2064 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2065 is_complete = isl_union_set_is_subset(D, domain);
2066 isl_union_set_free(D);
2067 isl_union_set_free(domain);
2069 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2070 test = isl_union_map_apply_range(test, dep);
2071 test = isl_union_map_apply_range(test, schedule);
2073 delta = isl_union_map_deltas(test);
2074 if (isl_union_set_n_set(delta) == 0) {
2078 isl_union_set_free(delta);
2080 delta_set = isl_set_from_union_set(delta);
2082 slice = isl_set_universe(isl_set_get_space(delta_set));
2083 for (i = 0; i < tilable; ++i)
2084 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2085 is_tilable = isl_set_is_subset(delta_set, slice);
2086 isl_set_free(slice);
2088 slice = isl_set_universe(isl_set_get_space(delta_set));
2089 for (i = 0; i < parallel; ++i)
2090 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2091 is_parallel = isl_set_is_subset(delta_set, slice);
2092 isl_set_free(slice);
2094 origin = isl_set_universe(isl_set_get_space(delta_set));
2095 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2096 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2098 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2099 delta_set = isl_set_lexmin(delta_set);
2101 is_nonneg = isl_set_is_equal(delta_set, origin);
2103 isl_set_free(origin);
2104 isl_set_free(delta_set);
2107 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2108 is_injection < 0 || is_complete < 0)
2111 isl_die(ctx, isl_error_unknown,
2112 "generated schedule incomplete", return -1);
2114 isl_die(ctx, isl_error_unknown,
2115 "generated schedule not injective on each statement",
2118 isl_die(ctx, isl_error_unknown,
2119 "negative dependences in generated schedule",
2122 isl_die(ctx, isl_error_unknown,
2123 "generated schedule not as tilable as expected",
2126 isl_die(ctx, isl_error_unknown,
2127 "generated schedule not as parallel as expected",
2133 int test_special_schedule(isl_ctx *ctx, const char *domain,
2134 const char *validity, const char *proximity, const char *expected_sched)
2138 isl_union_map *prox;
2139 isl_union_map *sched1, *sched2;
2140 isl_schedule *schedule;
2143 dom = isl_union_set_read_from_str(ctx, domain);
2144 dep = isl_union_map_read_from_str(ctx, validity);
2145 prox = isl_union_map_read_from_str(ctx, proximity);
2146 schedule = isl_union_set_compute_schedule(dom, dep, prox);
2147 sched1 = isl_schedule_get_map(schedule);
2148 isl_schedule_free(schedule);
2150 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2152 equal = isl_union_map_is_equal(sched1, sched2);
2153 isl_union_map_free(sched1);
2154 isl_union_map_free(sched2);
2159 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2165 int test_schedule(isl_ctx *ctx)
2167 const char *D, *W, *R, *V, *P, *S;
2170 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2171 W = "{ S1[t,i] -> a[t,i] }";
2172 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2173 "S1[t,i] -> a[t-1,i+1] }";
2174 S = "{ S1[t,i] -> [t,i] }";
2175 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2178 /* Fig. 5 of CC2008 */
2179 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2181 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2182 "j >= 2 and j <= -1 + N }";
2183 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2184 "j >= 2 and j <= -1 + N; "
2185 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2186 "j >= 2 and j <= -1 + N }";
2187 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2188 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2191 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2192 W = "{ S1[i] -> a[i] }";
2193 R = "{ S2[i] -> a[i+1] }";
2194 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2195 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2198 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2199 W = "{ S1[i] -> a[i] }";
2200 R = "{ S2[i] -> a[9-i] }";
2201 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2202 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2205 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2206 W = "{ S1[i] -> a[i] }";
2207 R = "[N] -> { S2[i] -> a[N-1-i] }";
2208 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2209 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2212 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2213 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2214 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2215 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2216 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2219 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2220 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2221 R = "{ S2[i,j] -> a[i-1,j] }";
2222 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2223 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2226 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2227 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2228 R = "{ S2[i,j] -> a[i,j-1] }";
2229 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2230 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2233 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2234 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2235 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2236 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2237 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2238 "S_0[] -> [0, 0, 0] }";
2239 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2241 ctx->opt->schedule_parametric = 0;
2242 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2244 ctx->opt->schedule_parametric = 1;
2246 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2247 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2248 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2249 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2250 "S4[i] -> a[i,N] }";
2251 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2252 "S4[i] -> [4,i,0] }";
2253 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2256 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2257 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2259 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2261 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2263 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2264 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2267 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2268 " S_2[t] : t >= 0 and t <= -1 + N; "
2269 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2271 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2272 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2273 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2274 "i >= 0 and i <= -1 + N }";
2275 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2276 "i >= 0 and i <= -1 + N; "
2277 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2278 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2279 " S_0[t] -> [0, t, 0] }";
2281 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2283 ctx->opt->schedule_parametric = 0;
2284 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2286 ctx->opt->schedule_parametric = 1;
2288 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2289 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2290 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2293 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2294 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2295 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2296 "j >= 0 and j <= -1 + N; "
2297 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2298 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2299 "j >= 0 and j <= -1 + N; "
2300 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2301 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2302 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2305 D = "{ S_0[i] : i >= 0 }";
2306 W = "{ S_0[i] -> a[i] : i >= 0 }";
2307 R = "{ S_0[i] -> a[0] : i >= 0 }";
2308 S = "{ S_0[i] -> [0, i, 0] }";
2309 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2312 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2313 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2314 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2315 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2316 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2319 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2320 "k <= -1 + n and k >= 0 }";
2321 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2322 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2323 "k <= -1 + n and k >= 0; "
2324 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2325 "k <= -1 + n and k >= 0; "
2326 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2327 "k <= -1 + n and k >= 0 }";
2328 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2329 ctx->opt->schedule_outer_zero_distance = 1;
2330 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2332 ctx->opt->schedule_outer_zero_distance = 0;
2334 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
2335 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2336 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2337 "Stmt_for_body24[i0, i1, 1, 0]:"
2338 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2339 "Stmt_for_body7[i0, i1, i2]:"
2340 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2343 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
2344 "Stmt_for_body24[1, i1, i2, i3]:"
2345 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2347 "Stmt_for_body24[0, i1, i2, i3] -> "
2348 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2349 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2351 "Stmt_for_body24[0, i1, i2, i3] ->"
2352 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2353 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2354 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2355 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2356 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2357 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2358 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2359 "i1 <= 6 and i1 >= 0;"
2360 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2361 "Stmt_for_body7[i0, i1, i2] -> "
2362 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2363 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2364 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2365 "Stmt_for_body7[i0, i1, i2] -> "
2366 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2367 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2368 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2370 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2371 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2372 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2374 if (test_special_schedule(ctx, D, V, P, S) < 0)
2377 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2378 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2379 "j >= 1 and j <= 7;"
2380 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2381 "j >= 1 and j <= 8 }";
2383 S = "{ S_0[i, j] -> [i + j, j] }";
2384 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2385 if (test_special_schedule(ctx, D, V, P, S) < 0)
2387 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2389 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2390 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2391 "j >= 0 and j <= -1 + i }";
2392 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2393 "i <= -1 + N and j >= 0;"
2394 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2397 S = "{ S_0[i, j] -> [i, j] }";
2398 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2399 if (test_special_schedule(ctx, D, V, P, S) < 0)
2401 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2403 /* Test both algorithms on a case with only proximity dependences. */
2404 D = "{ S[i,j] : 0 <= i <= 10 }";
2406 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2407 S = "{ S[i, j] -> [j, i] }";
2408 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2409 if (test_special_schedule(ctx, D, V, P, S) < 0)
2411 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2412 return test_special_schedule(ctx, D, V, P, S);
2415 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2417 isl_union_map *umap;
2420 umap = isl_union_map_read_from_str(ctx, str);
2421 test = isl_union_map_plain_is_injective(umap);
2422 isl_union_map_free(umap);
2425 if (test == injective)
2428 isl_die(ctx, isl_error_unknown,
2429 "map not detected as injective", return -1);
2431 isl_die(ctx, isl_error_unknown,
2432 "map detected as injective", return -1);
2435 int test_injective(isl_ctx *ctx)
2439 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2441 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2443 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2445 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2447 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2449 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2451 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2453 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2456 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2457 if (test_plain_injective(ctx, str, 1))
2459 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2460 if (test_plain_injective(ctx, str, 0))
2466 int test_aff(isl_ctx *ctx)
2471 isl_local_space *ls;
2475 dim = isl_space_set_alloc(ctx, 0, 1);
2476 ls = isl_local_space_from_space(dim);
2477 aff = isl_aff_zero_on_domain(ls);
2479 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2480 aff = isl_aff_scale_down_ui(aff, 3);
2481 aff = isl_aff_floor(aff);
2482 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2483 aff = isl_aff_scale_down_ui(aff, 2);
2484 aff = isl_aff_floor(aff);
2485 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2488 set = isl_set_read_from_str(ctx, str);
2489 aff = isl_aff_gist(aff, set);
2491 aff = isl_aff_add_constant_si(aff, -16);
2492 zero = isl_aff_plain_is_zero(aff);
2498 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2503 int test_dim_max(isl_ctx *ctx)
2507 isl_set *set1, *set2;
2512 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2513 set = isl_set_read_from_str(ctx, str);
2514 pwaff = isl_set_dim_max(set, 0);
2515 set1 = isl_set_from_pw_aff(pwaff);
2516 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2517 set2 = isl_set_read_from_str(ctx, str);
2518 equal = isl_set_is_equal(set1, set2);
2524 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2526 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2527 set = isl_set_read_from_str(ctx, str);
2528 pwaff = isl_set_dim_max(set, 0);
2529 set1 = isl_set_from_pw_aff(pwaff);
2530 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2531 set2 = isl_set_read_from_str(ctx, str);
2532 equal = isl_set_is_equal(set1, set2);
2538 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2540 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2541 set = isl_set_read_from_str(ctx, str);
2542 pwaff = isl_set_dim_max(set, 0);
2543 set1 = isl_set_from_pw_aff(pwaff);
2544 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2545 set2 = isl_set_read_from_str(ctx, str);
2546 equal = isl_set_is_equal(set1, set2);
2552 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2554 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2555 "0 <= i < N and 0 <= j < M }";
2556 map = isl_map_read_from_str(ctx, str);
2557 set = isl_map_range(map);
2559 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
2560 set1 = isl_set_from_pw_aff(pwaff);
2561 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2562 set2 = isl_set_read_from_str(ctx, str);
2563 equal = isl_set_is_equal(set1, set2);
2567 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
2568 set1 = isl_set_from_pw_aff(pwaff);
2569 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2570 set2 = isl_set_read_from_str(ctx, str);
2571 if (equal >= 0 && equal)
2572 equal = isl_set_is_equal(set1, set2);
2581 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2586 int test_product(isl_ctx *ctx)
2590 isl_union_set *uset1, *uset2;
2594 set = isl_set_read_from_str(ctx, str);
2595 set = isl_set_product(set, isl_set_copy(set));
2596 ok = isl_set_is_wrapping(set);
2601 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2604 uset1 = isl_union_set_read_from_str(ctx, str);
2605 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
2606 str = "{ [[] -> []] }";
2607 uset2 = isl_union_set_read_from_str(ctx, str);
2608 ok = isl_union_set_is_equal(uset1, uset2);
2609 isl_union_set_free(uset1);
2610 isl_union_set_free(uset2);
2614 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2619 int test_equal(isl_ctx *ctx)
2622 isl_set *set, *set2;
2626 set = isl_set_read_from_str(ctx, str);
2628 set2 = isl_set_read_from_str(ctx, str);
2629 equal = isl_set_is_equal(set, set2);
2635 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2640 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
2641 enum isl_dim_type type, unsigned pos, int fixed)
2645 test = isl_map_plain_is_fixed(map, type, pos, NULL);
2652 isl_die(ctx, isl_error_unknown,
2653 "map not detected as fixed", return -1);
2655 isl_die(ctx, isl_error_unknown,
2656 "map detected as fixed", return -1);
2659 int test_fixed(isl_ctx *ctx)
2664 str = "{ [i] -> [i] }";
2665 map = isl_map_read_from_str(ctx, str);
2666 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
2668 str = "{ [i] -> [1] }";
2669 map = isl_map_read_from_str(ctx, str);
2670 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2672 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2673 map = isl_map_read_from_str(ctx, str);
2674 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2676 map = isl_map_read_from_str(ctx, str);
2677 map = isl_map_neg(map);
2678 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2684 int test_vertices(isl_ctx *ctx)
2687 isl_basic_set *bset;
2688 isl_vertices *vertices;
2690 str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2691 bset = isl_basic_set_read_from_str(ctx, str);
2692 vertices = isl_basic_set_compute_vertices(bset);
2693 isl_basic_set_free(bset);
2694 isl_vertices_free(vertices);
2698 str = "{ A[t, i] : t = 14 and i = 1 }";
2699 bset = isl_basic_set_read_from_str(ctx, str);
2700 vertices = isl_basic_set_compute_vertices(bset);
2701 isl_basic_set_free(bset);
2702 isl_vertices_free(vertices);
2709 int test_union_pw(isl_ctx *ctx)
2713 isl_union_set *uset;
2714 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
2716 str = "{ [x] -> x^2 }";
2717 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
2718 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
2719 uset = isl_union_pw_qpolynomial_domain(upwqp1);
2720 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
2721 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
2722 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
2723 isl_union_pw_qpolynomial_free(upwqp1);
2724 isl_union_pw_qpolynomial_free(upwqp2);
2728 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2733 int test_output(isl_ctx *ctx)
2741 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2742 pa = isl_pw_aff_read_from_str(ctx, str);
2744 p = isl_printer_to_str(ctx);
2745 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
2746 p = isl_printer_print_pw_aff(p, pa);
2747 s = isl_printer_get_str(p);
2748 isl_printer_free(p);
2749 isl_pw_aff_free(pa);
2750 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2755 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2760 int test_sample(isl_ctx *ctx)
2763 isl_basic_set *bset1, *bset2;
2766 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2767 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2768 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2769 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2770 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2771 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2772 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2773 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2774 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2775 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2776 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2777 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2778 "d - 1073741821e and "
2779 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2780 "3j >= 1 - a + b + 2e and "
2781 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2782 "3i <= 4 - a + 4b - e and "
2783 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2784 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2785 "c <= -1 + a and 3i >= -2 - a + 3e and "
2786 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2787 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2788 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2789 "1073741823e >= 1 + 1073741823b - d and "
2790 "3i >= 1073741823b + c - 1073741823e - f and "
2791 "3i >= 1 + 2b + e + 3g }";
2792 bset1 = isl_basic_set_read_from_str(ctx, str);
2793 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
2794 empty = isl_basic_set_is_empty(bset2);
2795 subset = isl_basic_set_is_subset(bset2, bset1);
2796 isl_basic_set_free(bset1);
2797 isl_basic_set_free(bset2);
2799 isl_die(ctx, isl_error_unknown, "point not found", return -1);
2801 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
2806 int test_fixed_power(isl_ctx *ctx)
2814 str = "{ [i] -> [i + 1] }";
2815 map = isl_map_read_from_str(ctx, str);
2816 isl_int_set_si(exp, 23);
2817 map = isl_map_fixed_power(map, exp);
2818 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
2829 struct isl_ctx *ctx;
2831 srcdir = getenv("srcdir");
2834 ctx = isl_ctx_alloc();
2835 if (test_fixed_power(ctx) < 0)
2837 if (test_sample(ctx) < 0)
2839 if (test_output(ctx) < 0)
2841 if (test_vertices(ctx) < 0)
2843 if (test_fixed(ctx) < 0)
2845 if (test_equal(ctx) < 0)
2847 if (test_product(ctx) < 0)
2849 if (test_dim_max(ctx) < 0)
2851 if (test_aff(ctx) < 0)
2853 if (test_injective(ctx) < 0)
2855 if (test_schedule(ctx) < 0)
2857 if (test_union_pw(ctx) < 0)
2859 test_factorize(ctx);
2864 test_split_periods(ctx);
2865 if (test_parse(ctx) < 0)
2869 if (test_sv(ctx) < 0)
2871 test_bijective(ctx);
2875 test_construction(ctx);
2878 test_application(ctx);
2879 if (test_affine_hull(ctx) < 0)
2881 test_convex_hull(ctx);
2883 if (test_coalesce(ctx) < 0)