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]) }");
196 void test_read(struct isl_ctx *ctx)
200 struct isl_basic_set *bset1, *bset2;
201 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
203 filename = get_filename(ctx, "set", "omega");
205 input = fopen(filename, "r");
208 bset1 = isl_basic_set_read_from_file(ctx, input);
209 bset2 = isl_basic_set_read_from_str(ctx, str);
211 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
213 isl_basic_set_free(bset1);
214 isl_basic_set_free(bset2);
220 void test_bounded(struct isl_ctx *ctx)
225 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
226 bounded = isl_set_is_bounded(set);
230 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
231 bounded = isl_set_is_bounded(set);
235 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
236 bounded = isl_set_is_bounded(set);
241 /* Construct the basic set { [i] : 5 <= i <= N } */
242 void test_construction(struct isl_ctx *ctx)
247 struct isl_basic_set *bset;
248 struct isl_constraint *c;
252 dim = isl_space_set_alloc(ctx, 1, 1);
253 bset = isl_basic_set_universe(isl_space_copy(dim));
254 ls = isl_local_space_from_space(dim);
256 c = isl_inequality_alloc(isl_local_space_copy(ls));
257 isl_int_set_si(v, -1);
258 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
259 isl_int_set_si(v, 1);
260 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
261 bset = isl_basic_set_add_constraint(bset, c);
263 c = isl_inequality_alloc(isl_local_space_copy(ls));
264 isl_int_set_si(v, 1);
265 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
266 isl_int_set_si(v, -5);
267 isl_constraint_set_constant(c, v);
268 bset = isl_basic_set_add_constraint(bset, c);
270 isl_local_space_free(ls);
271 isl_basic_set_free(bset);
276 void test_dim(struct isl_ctx *ctx)
279 isl_map *map1, *map2;
281 map1 = isl_map_read_from_str(ctx,
282 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
283 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
284 map2 = isl_map_read_from_str(ctx,
285 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
286 assert(isl_map_is_equal(map1, map2));
289 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
290 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
291 assert(isl_map_is_equal(map1, map2));
296 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
297 map1 = isl_map_read_from_str(ctx, str);
298 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
299 map2 = isl_map_read_from_str(ctx, str);
300 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
301 assert(isl_map_is_equal(map1, map2));
307 void test_div(struct isl_ctx *ctx)
312 struct isl_basic_set *bset;
313 struct isl_constraint *c;
318 dim = isl_space_set_alloc(ctx, 0, 3);
319 bset = isl_basic_set_universe(isl_space_copy(dim));
320 ls = isl_local_space_from_space(dim);
322 c = isl_equality_alloc(isl_local_space_copy(ls));
323 isl_int_set_si(v, -1);
324 isl_constraint_set_constant(c, v);
325 isl_int_set_si(v, 1);
326 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
327 isl_int_set_si(v, 3);
328 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
329 bset = isl_basic_set_add_constraint(bset, c);
331 c = isl_equality_alloc(isl_local_space_copy(ls));
332 isl_int_set_si(v, 1);
333 isl_constraint_set_constant(c, v);
334 isl_int_set_si(v, -1);
335 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
336 isl_int_set_si(v, 3);
337 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
338 bset = isl_basic_set_add_constraint(bset, c);
340 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
342 assert(bset && bset->n_div == 1);
343 isl_local_space_free(ls);
344 isl_basic_set_free(bset);
347 dim = isl_space_set_alloc(ctx, 0, 3);
348 bset = isl_basic_set_universe(isl_space_copy(dim));
349 ls = isl_local_space_from_space(dim);
351 c = isl_equality_alloc(isl_local_space_copy(ls));
352 isl_int_set_si(v, 1);
353 isl_constraint_set_constant(c, v);
354 isl_int_set_si(v, -1);
355 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
356 isl_int_set_si(v, 3);
357 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
358 bset = isl_basic_set_add_constraint(bset, c);
360 c = isl_equality_alloc(isl_local_space_copy(ls));
361 isl_int_set_si(v, -1);
362 isl_constraint_set_constant(c, v);
363 isl_int_set_si(v, 1);
364 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
365 isl_int_set_si(v, 3);
366 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
367 bset = isl_basic_set_add_constraint(bset, c);
369 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
371 assert(bset && bset->n_div == 1);
372 isl_local_space_free(ls);
373 isl_basic_set_free(bset);
376 dim = isl_space_set_alloc(ctx, 0, 3);
377 bset = isl_basic_set_universe(isl_space_copy(dim));
378 ls = isl_local_space_from_space(dim);
380 c = isl_equality_alloc(isl_local_space_copy(ls));
381 isl_int_set_si(v, 1);
382 isl_constraint_set_constant(c, v);
383 isl_int_set_si(v, -1);
384 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
385 isl_int_set_si(v, 3);
386 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
387 bset = isl_basic_set_add_constraint(bset, c);
389 c = isl_equality_alloc(isl_local_space_copy(ls));
390 isl_int_set_si(v, -3);
391 isl_constraint_set_constant(c, v);
392 isl_int_set_si(v, 1);
393 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
394 isl_int_set_si(v, 4);
395 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
396 bset = isl_basic_set_add_constraint(bset, c);
398 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
400 assert(bset && bset->n_div == 1);
401 isl_local_space_free(ls);
402 isl_basic_set_free(bset);
405 dim = isl_space_set_alloc(ctx, 0, 3);
406 bset = isl_basic_set_universe(isl_space_copy(dim));
407 ls = isl_local_space_from_space(dim);
409 c = isl_equality_alloc(isl_local_space_copy(ls));
410 isl_int_set_si(v, 2);
411 isl_constraint_set_constant(c, v);
412 isl_int_set_si(v, -1);
413 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
414 isl_int_set_si(v, 3);
415 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
416 bset = isl_basic_set_add_constraint(bset, c);
418 c = isl_equality_alloc(isl_local_space_copy(ls));
419 isl_int_set_si(v, -1);
420 isl_constraint_set_constant(c, v);
421 isl_int_set_si(v, 1);
422 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
423 isl_int_set_si(v, 6);
424 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
425 bset = isl_basic_set_add_constraint(bset, c);
427 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
429 assert(isl_basic_set_is_empty(bset));
430 isl_local_space_free(ls);
431 isl_basic_set_free(bset);
434 dim = isl_space_set_alloc(ctx, 0, 3);
435 bset = isl_basic_set_universe(isl_space_copy(dim));
436 ls = isl_local_space_from_space(dim);
438 c = isl_equality_alloc(isl_local_space_copy(ls));
439 isl_int_set_si(v, -1);
440 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
441 isl_int_set_si(v, 3);
442 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
443 bset = isl_basic_set_add_constraint(bset, c);
445 c = isl_equality_alloc(isl_local_space_copy(ls));
446 isl_int_set_si(v, 1);
447 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
448 isl_int_set_si(v, -3);
449 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
450 bset = isl_basic_set_add_constraint(bset, c);
452 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
454 assert(bset && bset->n_div == 0);
455 isl_basic_set_free(bset);
456 isl_local_space_free(ls);
459 dim = isl_space_set_alloc(ctx, 0, 3);
460 bset = isl_basic_set_universe(isl_space_copy(dim));
461 ls = isl_local_space_from_space(dim);
463 c = isl_equality_alloc(isl_local_space_copy(ls));
464 isl_int_set_si(v, -1);
465 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
466 isl_int_set_si(v, 6);
467 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
468 bset = isl_basic_set_add_constraint(bset, c);
470 c = isl_equality_alloc(isl_local_space_copy(ls));
471 isl_int_set_si(v, 1);
472 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
473 isl_int_set_si(v, -3);
474 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
475 bset = isl_basic_set_add_constraint(bset, c);
477 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
479 assert(bset && bset->n_div == 1);
480 isl_basic_set_free(bset);
481 isl_local_space_free(ls);
484 /* This test is a bit tricky. We set up an equality
486 * Normalization of divs creates _two_ divs
489 * Afterwards e0 is removed again because it has coefficient -1
490 * and we end up with the original equality and div again.
491 * Perhaps we can avoid the introduction of this temporary div.
493 dim = isl_space_set_alloc(ctx, 0, 4);
494 bset = isl_basic_set_universe(isl_space_copy(dim));
495 ls = isl_local_space_from_space(dim);
497 c = isl_equality_alloc(isl_local_space_copy(ls));
498 isl_int_set_si(v, -1);
499 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
500 isl_int_set_si(v, -3);
501 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
502 isl_int_set_si(v, -3);
503 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
504 isl_int_set_si(v, 6);
505 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
506 bset = isl_basic_set_add_constraint(bset, c);
508 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
510 /* Test disabled for now */
512 assert(bset && bset->n_div == 1);
514 isl_local_space_free(ls);
515 isl_basic_set_free(bset);
518 dim = isl_space_set_alloc(ctx, 0, 5);
519 bset = isl_basic_set_universe(isl_space_copy(dim));
520 ls = isl_local_space_from_space(dim);
522 c = isl_equality_alloc(isl_local_space_copy(ls));
523 isl_int_set_si(v, -1);
524 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
525 isl_int_set_si(v, -3);
526 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
527 isl_int_set_si(v, -3);
528 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
529 isl_int_set_si(v, 6);
530 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
531 bset = isl_basic_set_add_constraint(bset, c);
533 c = isl_equality_alloc(isl_local_space_copy(ls));
534 isl_int_set_si(v, -1);
535 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
536 isl_int_set_si(v, 1);
537 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
538 isl_int_set_si(v, 1);
539 isl_constraint_set_constant(c, v);
540 bset = isl_basic_set_add_constraint(bset, c);
542 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
544 /* Test disabled for now */
546 assert(bset && bset->n_div == 1);
548 isl_local_space_free(ls);
549 isl_basic_set_free(bset);
552 dim = isl_space_set_alloc(ctx, 0, 4);
553 bset = isl_basic_set_universe(isl_space_copy(dim));
554 ls = isl_local_space_from_space(dim);
556 c = isl_equality_alloc(isl_local_space_copy(ls));
557 isl_int_set_si(v, 1);
558 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
559 isl_int_set_si(v, -1);
560 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
561 isl_int_set_si(v, -2);
562 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
563 bset = isl_basic_set_add_constraint(bset, c);
565 c = isl_equality_alloc(isl_local_space_copy(ls));
566 isl_int_set_si(v, -1);
567 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
568 isl_int_set_si(v, 3);
569 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
570 isl_int_set_si(v, 2);
571 isl_constraint_set_constant(c, v);
572 bset = isl_basic_set_add_constraint(bset, c);
574 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
576 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
578 assert(!isl_basic_set_is_empty(bset));
580 isl_local_space_free(ls);
581 isl_basic_set_free(bset);
584 dim = isl_space_set_alloc(ctx, 0, 3);
585 bset = isl_basic_set_universe(isl_space_copy(dim));
586 ls = isl_local_space_from_space(dim);
588 c = isl_equality_alloc(isl_local_space_copy(ls));
589 isl_int_set_si(v, 1);
590 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
591 isl_int_set_si(v, -2);
592 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
593 bset = isl_basic_set_add_constraint(bset, c);
595 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
597 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
599 isl_local_space_free(ls);
600 isl_basic_set_free(bset);
605 void test_application_case(struct isl_ctx *ctx, const char *name)
609 struct isl_basic_set *bset1, *bset2;
610 struct isl_basic_map *bmap;
612 filename = get_filename(ctx, name, "omega");
614 input = fopen(filename, "r");
617 bset1 = isl_basic_set_read_from_file(ctx, input);
618 bmap = isl_basic_map_read_from_file(ctx, input);
620 bset1 = isl_basic_set_apply(bset1, bmap);
622 bset2 = isl_basic_set_read_from_file(ctx, input);
624 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
626 isl_basic_set_free(bset1);
627 isl_basic_set_free(bset2);
633 void test_application(struct isl_ctx *ctx)
635 test_application_case(ctx, "application");
636 test_application_case(ctx, "application2");
639 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
643 struct isl_basic_set *bset1, *bset2;
645 filename = get_filename(ctx, name, "polylib");
647 input = fopen(filename, "r");
650 bset1 = isl_basic_set_read_from_file(ctx, input);
651 bset2 = isl_basic_set_read_from_file(ctx, input);
653 bset1 = isl_basic_set_affine_hull(bset1);
655 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
657 isl_basic_set_free(bset1);
658 isl_basic_set_free(bset2);
664 int test_affine_hull(struct isl_ctx *ctx)
671 test_affine_hull_case(ctx, "affine2");
672 test_affine_hull_case(ctx, "affine");
673 test_affine_hull_case(ctx, "affine3");
675 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
676 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
677 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
678 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
679 set = isl_set_read_from_str(ctx, str);
680 bset = isl_set_affine_hull(set);
681 n = isl_basic_set_dim(bset, isl_dim_div);
682 isl_basic_set_free(bset);
684 isl_die(ctx, isl_error_unknown, "not expecting any divs",
690 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
694 struct isl_basic_set *bset1, *bset2;
697 filename = get_filename(ctx, name, "polylib");
699 input = fopen(filename, "r");
702 bset1 = isl_basic_set_read_from_file(ctx, input);
703 bset2 = isl_basic_set_read_from_file(ctx, input);
705 set = isl_basic_set_union(bset1, bset2);
706 bset1 = isl_set_convex_hull(set);
708 bset2 = isl_basic_set_read_from_file(ctx, input);
710 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
712 isl_basic_set_free(bset1);
713 isl_basic_set_free(bset2);
719 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
721 const char *str1, *str2;
722 isl_set *set1, *set2;
723 int orig_convex = ctx->opt->convex;
724 ctx->opt->convex = convex;
726 test_convex_hull_case(ctx, "convex0");
727 test_convex_hull_case(ctx, "convex1");
728 test_convex_hull_case(ctx, "convex2");
729 test_convex_hull_case(ctx, "convex3");
730 test_convex_hull_case(ctx, "convex4");
731 test_convex_hull_case(ctx, "convex5");
732 test_convex_hull_case(ctx, "convex6");
733 test_convex_hull_case(ctx, "convex7");
734 test_convex_hull_case(ctx, "convex8");
735 test_convex_hull_case(ctx, "convex9");
736 test_convex_hull_case(ctx, "convex10");
737 test_convex_hull_case(ctx, "convex11");
738 test_convex_hull_case(ctx, "convex12");
739 test_convex_hull_case(ctx, "convex13");
740 test_convex_hull_case(ctx, "convex14");
741 test_convex_hull_case(ctx, "convex15");
743 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
744 "(i0 = 1 and i1 = 0 and i2 = 1) or "
745 "(i0 = 0 and i1 = 0 and i2 = 0) }";
746 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
747 set1 = isl_set_read_from_str(ctx, str1);
748 set2 = isl_set_read_from_str(ctx, str2);
749 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
750 assert(isl_set_is_equal(set1, set2));
754 ctx->opt->convex = orig_convex;
757 void test_convex_hull(struct isl_ctx *ctx)
759 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
760 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
763 void test_gist_case(struct isl_ctx *ctx, const char *name)
767 struct isl_basic_set *bset1, *bset2;
769 filename = get_filename(ctx, name, "polylib");
771 input = fopen(filename, "r");
774 bset1 = isl_basic_set_read_from_file(ctx, input);
775 bset2 = isl_basic_set_read_from_file(ctx, input);
777 bset1 = isl_basic_set_gist(bset1, bset2);
779 bset2 = isl_basic_set_read_from_file(ctx, input);
781 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
783 isl_basic_set_free(bset1);
784 isl_basic_set_free(bset2);
790 void test_gist(struct isl_ctx *ctx)
793 isl_basic_set *bset1, *bset2;
795 test_gist_case(ctx, "gist1");
797 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
798 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
799 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
800 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
801 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
802 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
803 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
804 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
805 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
806 bset1 = isl_basic_set_read_from_str(ctx, str);
807 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
808 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
809 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
810 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
811 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
812 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
813 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
814 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
815 bset2 = isl_basic_set_read_from_str(ctx, str);
816 bset1 = isl_basic_set_gist(bset1, bset2);
817 assert(bset1 && bset1->n_div == 0);
818 isl_basic_set_free(bset1);
821 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
827 set = isl_set_read_from_str(ctx, str);
828 set = isl_set_coalesce(set);
829 set2 = isl_set_read_from_str(ctx, str);
830 equal = isl_set_is_equal(set, set2);
831 one = set && set->n == 1;
838 isl_die(ctx, isl_error_unknown,
839 "coalesced set not equal to input", return -1);
840 if (check_one && !one)
841 isl_die(ctx, isl_error_unknown,
842 "coalesced set should not be a union", return -1);
847 int test_coalesce(struct isl_ctx *ctx)
850 struct isl_set *set, *set2;
851 struct isl_map *map, *map2;
853 set = isl_set_read_from_str(ctx,
854 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
855 "y >= x & x >= 2 & 5 >= y }");
856 set = isl_set_coalesce(set);
857 assert(set && set->n == 1);
860 set = isl_set_read_from_str(ctx,
861 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
862 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
863 set = isl_set_coalesce(set);
864 assert(set && set->n == 1);
867 set = isl_set_read_from_str(ctx,
868 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
869 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
870 set = isl_set_coalesce(set);
871 assert(set && set->n == 2);
874 set = isl_set_read_from_str(ctx,
875 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
876 "y >= 0 & x >= 6 & x <= 10 & y <= x}");
877 set = isl_set_coalesce(set);
878 assert(set && set->n == 1);
881 set = isl_set_read_from_str(ctx,
882 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
883 "y >= 0 & x >= 7 & x <= 10 & y <= x}");
884 set = isl_set_coalesce(set);
885 assert(set && set->n == 2);
888 set = isl_set_read_from_str(ctx,
889 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
890 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}");
891 set = isl_set_coalesce(set);
892 assert(set && set->n == 2);
895 set = isl_set_read_from_str(ctx,
896 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
897 "y >= 0 & x = 6 & y <= 6}");
898 set = isl_set_coalesce(set);
899 assert(set && set->n == 1);
902 set = isl_set_read_from_str(ctx,
903 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
904 "y >= 0 & x = 7 & y <= 6}");
905 set = isl_set_coalesce(set);
906 assert(set && set->n == 2);
909 set = isl_set_read_from_str(ctx,
910 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
911 "y >= 0 & x = 6 & y <= 5}");
912 set = isl_set_coalesce(set);
913 assert(set && set->n == 1);
914 set2 = isl_set_read_from_str(ctx,
915 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
916 "y >= 0 & x = 6 & y <= 5}");
917 assert(isl_set_is_equal(set, set2));
921 set = isl_set_read_from_str(ctx,
922 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
923 "y >= 0 & x = 6 & y <= 7}");
924 set = isl_set_coalesce(set);
925 assert(set && set->n == 2);
928 set = isl_set_read_from_str(ctx,
929 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
930 set = isl_set_coalesce(set);
931 assert(set && set->n == 1);
932 set2 = isl_set_read_from_str(ctx,
933 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
934 assert(isl_set_is_equal(set, set2));
938 set = isl_set_read_from_str(ctx,
939 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
940 set = isl_set_coalesce(set);
941 set2 = isl_set_read_from_str(ctx,
942 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
943 assert(isl_set_is_equal(set, set2));
947 set = isl_set_read_from_str(ctx,
948 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
949 "2 <= i and i <= n }");
950 set = isl_set_coalesce(set);
951 assert(set && set->n == 1);
952 set2 = isl_set_read_from_str(ctx,
953 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
954 "2 <= i and i <= n }");
955 assert(isl_set_is_equal(set, set2));
959 map = isl_map_read_from_str(ctx,
960 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
961 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
962 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
963 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
964 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
965 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
966 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
967 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
968 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
969 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
970 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
971 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
972 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
973 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
974 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
975 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
976 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
977 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
978 map = isl_map_coalesce(map);
979 map2 = isl_map_read_from_str(ctx,
980 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
981 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
982 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
983 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
984 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
985 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
986 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
987 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
988 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
989 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
990 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
991 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
992 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
993 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
994 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
995 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
996 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
997 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
998 assert(isl_map_is_equal(map, map2));
1002 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1003 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1004 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1005 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
1006 map = isl_map_read_from_str(ctx, str);
1007 map = isl_map_coalesce(map);
1008 map2 = isl_map_read_from_str(ctx, str);
1009 assert(isl_map_is_equal(map, map2));
1013 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
1014 "[o0, o1, o2, o3, o4, o5, o6] : "
1015 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1016 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1017 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1018 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1019 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1020 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1021 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1022 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1023 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1024 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1025 "o6 >= i3 + i6 - o3 and M >= 0 and "
1026 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1027 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
1028 map = isl_map_read_from_str(ctx, str);
1029 map = isl_map_coalesce(map);
1030 map2 = isl_map_read_from_str(ctx, str);
1031 assert(isl_map_is_equal(map, map2));
1035 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1036 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1037 "(o0 = 0 and M >= 2 and N >= 3) or "
1038 "(M = 0 and o0 = 0 and N >= 3) }";
1039 map = isl_map_read_from_str(ctx, str);
1040 map = isl_map_coalesce(map);
1041 map2 = isl_map_read_from_str(ctx, str);
1042 assert(isl_map_is_equal(map, map2));
1046 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1047 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1048 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1049 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1050 map = isl_map_read_from_str(ctx, str);
1051 map = isl_map_coalesce(map);
1052 map2 = isl_map_read_from_str(ctx, str);
1053 assert(isl_map_is_equal(map, map2));
1057 test_coalesce_set(ctx,
1058 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1059 "(i1 = M and M >= 1) }", 0);
1060 test_coalesce_set(ctx,
1061 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1062 test_coalesce_set(ctx,
1063 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1064 "(y = 3 and x = 1) }", 1);
1065 test_coalesce_set(ctx,
1066 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1067 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1068 "i1 <= M and i3 <= M and i4 <= M) or "
1069 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1070 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1071 "i4 <= -1 + M) }", 1);
1072 test_coalesce_set(ctx,
1073 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1074 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1075 test_coalesce_set(ctx,
1076 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1077 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1078 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1079 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
1080 if (test_coalesce_set(ctx,
1081 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1083 if (test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
1085 if (test_coalesce_set(ctx,
1086 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1088 if (test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
1090 if (test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
1092 if (test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
1094 if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
1096 if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
1098 if (test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1100 if (test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1102 if (test_coalesce_set(ctx, "{ [a, b] : exists e : 2e = a and "
1103 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
1108 void test_closure(struct isl_ctx *ctx)
1112 isl_map *up, *right;
1113 isl_map *map, *map2;
1116 /* COCOA example 1 */
1117 map = isl_map_read_from_str(ctx,
1118 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1119 "1 <= i and i < n and 1 <= j and j < n or "
1120 "i2 = i + 1 and j2 = j - 1 and "
1121 "1 <= i and i < n and 2 <= j and j <= n }");
1122 map = isl_map_power(map, &exact);
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_transitive_closure(map, &exact);
1134 map2 = isl_map_read_from_str(ctx,
1135 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1136 "1 <= i and i < n and 1 <= j and j <= n and "
1137 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1138 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1139 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1140 assert(isl_map_is_equal(map, map2));
1144 map = isl_map_read_from_str(ctx,
1145 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1146 " 0 <= y and y <= n }");
1147 map = isl_map_transitive_closure(map, &exact);
1148 map2 = isl_map_read_from_str(ctx,
1149 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1150 " 0 <= y and y <= n }");
1151 assert(isl_map_is_equal(map, map2));
1155 /* COCOA example 2 */
1156 map = isl_map_read_from_str(ctx,
1157 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1158 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1159 "i2 = i + 2 and j2 = j - 2 and "
1160 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1161 map = isl_map_transitive_closure(map, &exact);
1163 map2 = isl_map_read_from_str(ctx,
1164 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1165 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1166 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1167 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1168 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1169 assert(isl_map_is_equal(map, map2));
1173 /* COCOA Fig.2 left */
1174 map = isl_map_read_from_str(ctx,
1175 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1176 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1178 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1179 "j <= 2 i - 3 and j <= n - 2 or "
1180 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1181 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1182 map = isl_map_transitive_closure(map, &exact);
1186 /* COCOA Fig.2 right */
1187 map = isl_map_read_from_str(ctx,
1188 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1189 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1191 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1192 "j <= 2 i - 4 and j <= n - 3 or "
1193 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1194 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1195 map = isl_map_power(map, &exact);
1199 /* COCOA Fig.2 right */
1200 map = isl_map_read_from_str(ctx,
1201 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1202 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1204 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1205 "j <= 2 i - 4 and j <= n - 3 or "
1206 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1207 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1208 map = isl_map_transitive_closure(map, &exact);
1210 map2 = isl_map_read_from_str(ctx,
1211 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1212 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1213 "j <= n and 3 + i + 2 j <= 3 n and "
1214 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1215 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1216 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1217 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1218 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1219 assert(isl_map_is_equal(map, map2));
1223 /* COCOA Fig.1 right */
1224 dom = isl_set_read_from_str(ctx,
1225 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1226 "2 x - 3 y + 3 >= 0 }");
1227 right = isl_map_read_from_str(ctx,
1228 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1229 up = isl_map_read_from_str(ctx,
1230 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1231 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1232 right = isl_map_intersect_range(right, isl_set_copy(dom));
1233 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1234 up = isl_map_intersect_range(up, dom);
1235 map = isl_map_union(up, right);
1236 map = isl_map_transitive_closure(map, &exact);
1238 map2 = isl_map_read_from_str(ctx,
1239 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1240 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1241 assert(isl_map_is_equal(map, map2));
1245 /* COCOA Theorem 1 counter example */
1246 map = isl_map_read_from_str(ctx,
1247 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1248 "i2 = 1 and j2 = j or "
1249 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1250 map = isl_map_transitive_closure(map, &exact);
1254 map = isl_map_read_from_str(ctx,
1255 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1256 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1257 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1258 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1259 map = isl_map_transitive_closure(map, &exact);
1263 /* Kelly et al 1996, fig 12 */
1264 map = isl_map_read_from_str(ctx,
1265 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1266 "1 <= i,j,j+1 <= n or "
1267 "j = n and j2 = 1 and i2 = i + 1 and "
1268 "1 <= i,i+1 <= n }");
1269 map = isl_map_transitive_closure(map, &exact);
1271 map2 = isl_map_read_from_str(ctx,
1272 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1273 "1 <= i <= n and i = i2 or "
1274 "1 <= i < i2 <= n and 1 <= j <= n and "
1276 assert(isl_map_is_equal(map, map2));
1280 /* Omega's closure4 */
1281 map = isl_map_read_from_str(ctx,
1282 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1283 "1 <= x,y <= 10 or "
1284 "x2 = x + 1 and y2 = y and "
1285 "1 <= x <= 20 && 5 <= y <= 15 }");
1286 map = isl_map_transitive_closure(map, &exact);
1290 map = isl_map_read_from_str(ctx,
1291 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1292 map = isl_map_transitive_closure(map, &exact);
1294 map2 = isl_map_read_from_str(ctx,
1295 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1296 assert(isl_map_is_equal(map, map2));
1300 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1301 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1302 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1303 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1304 map = isl_map_read_from_str(ctx, str);
1305 map = isl_map_transitive_closure(map, &exact);
1307 map2 = isl_map_read_from_str(ctx, str);
1308 assert(isl_map_is_equal(map, map2));
1312 str = "{[0] -> [1]; [2] -> [3]}";
1313 map = isl_map_read_from_str(ctx, str);
1314 map = isl_map_transitive_closure(map, &exact);
1316 map2 = isl_map_read_from_str(ctx, str);
1317 assert(isl_map_is_equal(map, map2));
1321 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1322 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1323 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1324 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1325 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1326 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1327 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1328 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1329 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1330 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1331 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1332 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1333 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 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, 2]] -> "
1337 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1338 "exists (e0 = [(3 - n)/3]: i5 >= 1 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 map = isl_map_read_from_str(ctx, str);
1342 map = isl_map_transitive_closure(map, NULL);
1347 void test_lex(struct isl_ctx *ctx)
1352 dim = isl_space_set_alloc(ctx, 0, 0);
1353 map = isl_map_lex_le(dim);
1354 assert(!isl_map_is_empty(map));
1358 void test_lexmin(struct isl_ctx *ctx)
1361 isl_basic_map *bmap;
1362 isl_map *map, *map2;
1365 isl_pw_multi_aff *pma;
1367 str = "[p0, p1] -> { [] -> [] : "
1368 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1369 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1370 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1371 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1372 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1373 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1374 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1375 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1376 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1377 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1378 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1379 map = isl_map_read_from_str(ctx, str);
1380 map = isl_map_lexmin(map);
1383 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1384 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1385 set = isl_set_read_from_str(ctx, str);
1386 set = isl_set_lexmax(set);
1387 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1388 set2 = isl_set_read_from_str(ctx, str);
1389 set = isl_set_intersect(set, set2);
1390 assert(!isl_set_is_empty(set));
1393 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1394 map = isl_map_read_from_str(ctx, str);
1395 map = isl_map_lexmin(map);
1396 str = "{ [x] -> [5] : 6 <= x <= 8; "
1397 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1398 map2 = isl_map_read_from_str(ctx, str);
1399 assert(isl_map_is_equal(map, map2));
1403 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1404 map = isl_map_read_from_str(ctx, str);
1405 map2 = isl_map_copy(map);
1406 map = isl_map_lexmin(map);
1407 assert(isl_map_is_equal(map, map2));
1411 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1412 map = isl_map_read_from_str(ctx, str);
1413 map = isl_map_lexmin(map);
1414 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1415 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1416 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1417 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1418 map2 = isl_map_read_from_str(ctx, str);
1419 assert(isl_map_is_equal(map, map2));
1423 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1424 " 8i' <= i and 8i' >= -7 + i }";
1425 bmap = isl_basic_map_read_from_str(ctx, str);
1426 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1427 map2 = isl_map_from_pw_multi_aff(pma);
1428 map = isl_map_from_basic_map(bmap);
1429 assert(isl_map_is_equal(map, map2));
1433 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1434 map = isl_map_read_from_str(ctx, str);
1435 map = isl_map_lexmin(map);
1436 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1437 map2 = isl_map_read_from_str(ctx, str);
1438 assert(isl_map_is_equal(map, map2));
1448 static int collect_must_may(__isl_take isl_map *dep, int must,
1449 void *dep_user, void *user)
1451 struct must_may *mm = (struct must_may *)user;
1454 mm->must = isl_map_union(mm->must, dep);
1456 mm->may = isl_map_union(mm->may, dep);
1461 static int common_space(void *first, void *second)
1463 int depth = *(int *)first;
1467 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1475 map2 = isl_map_read_from_str(map->ctx, str);
1476 equal = isl_map_is_equal(map, map2);
1482 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1486 equal = map_is_equal(map, str);
1490 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1491 "result not as expected", return -1);
1495 void test_dep(struct isl_ctx *ctx)
1500 isl_access_info *ai;
1507 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1508 map = isl_map_read_from_str(ctx, str);
1509 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1511 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1512 map = isl_map_read_from_str(ctx, str);
1513 ai = isl_access_info_add_source(ai, map, 1, &depth);
1515 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1516 map = isl_map_read_from_str(ctx, str);
1517 ai = isl_access_info_add_source(ai, map, 1, &depth);
1519 flow = isl_access_info_compute_flow(ai);
1520 dim = isl_space_alloc(ctx, 0, 3, 3);
1521 mm.must = isl_map_empty(isl_space_copy(dim));
1522 mm.may = isl_map_empty(dim);
1524 isl_flow_foreach(flow, collect_must_may, &mm);
1526 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1527 " [1,10,0] -> [2,5,0] }";
1528 assert(map_is_equal(mm.must, str));
1529 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1530 assert(map_is_equal(mm.may, str));
1532 isl_map_free(mm.must);
1533 isl_map_free(mm.may);
1534 isl_flow_free(flow);
1537 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1538 map = isl_map_read_from_str(ctx, str);
1539 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1541 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1542 map = isl_map_read_from_str(ctx, str);
1543 ai = isl_access_info_add_source(ai, map, 1, &depth);
1545 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1546 map = isl_map_read_from_str(ctx, str);
1547 ai = isl_access_info_add_source(ai, map, 0, &depth);
1549 flow = isl_access_info_compute_flow(ai);
1550 dim = isl_space_alloc(ctx, 0, 3, 3);
1551 mm.must = isl_map_empty(isl_space_copy(dim));
1552 mm.may = isl_map_empty(dim);
1554 isl_flow_foreach(flow, collect_must_may, &mm);
1556 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1557 assert(map_is_equal(mm.must, str));
1558 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1559 assert(map_is_equal(mm.may, str));
1561 isl_map_free(mm.must);
1562 isl_map_free(mm.may);
1563 isl_flow_free(flow);
1566 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1567 map = isl_map_read_from_str(ctx, str);
1568 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1570 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1571 map = isl_map_read_from_str(ctx, str);
1572 ai = isl_access_info_add_source(ai, map, 0, &depth);
1574 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1575 map = isl_map_read_from_str(ctx, str);
1576 ai = isl_access_info_add_source(ai, map, 0, &depth);
1578 flow = isl_access_info_compute_flow(ai);
1579 dim = isl_space_alloc(ctx, 0, 3, 3);
1580 mm.must = isl_map_empty(isl_space_copy(dim));
1581 mm.may = isl_map_empty(dim);
1583 isl_flow_foreach(flow, collect_must_may, &mm);
1585 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1586 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1587 assert(map_is_equal(mm.may, str));
1588 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1589 assert(map_is_equal(mm.must, str));
1591 isl_map_free(mm.must);
1592 isl_map_free(mm.may);
1593 isl_flow_free(flow);
1596 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1597 map = isl_map_read_from_str(ctx, str);
1598 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1600 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1601 map = isl_map_read_from_str(ctx, str);
1602 ai = isl_access_info_add_source(ai, map, 0, &depth);
1604 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1605 map = isl_map_read_from_str(ctx, str);
1606 ai = isl_access_info_add_source(ai, map, 0, &depth);
1608 flow = isl_access_info_compute_flow(ai);
1609 dim = isl_space_alloc(ctx, 0, 3, 3);
1610 mm.must = isl_map_empty(isl_space_copy(dim));
1611 mm.may = isl_map_empty(dim);
1613 isl_flow_foreach(flow, collect_must_may, &mm);
1615 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1616 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1617 assert(map_is_equal(mm.may, str));
1618 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1619 assert(map_is_equal(mm.must, str));
1621 isl_map_free(mm.must);
1622 isl_map_free(mm.may);
1623 isl_flow_free(flow);
1626 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1627 map = isl_map_read_from_str(ctx, str);
1628 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1630 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1631 map = isl_map_read_from_str(ctx, str);
1632 ai = isl_access_info_add_source(ai, map, 0, &depth);
1634 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1635 map = isl_map_read_from_str(ctx, str);
1636 ai = isl_access_info_add_source(ai, map, 0, &depth);
1638 flow = isl_access_info_compute_flow(ai);
1639 dim = isl_space_alloc(ctx, 0, 3, 3);
1640 mm.must = isl_map_empty(isl_space_copy(dim));
1641 mm.may = isl_map_empty(dim);
1643 isl_flow_foreach(flow, collect_must_may, &mm);
1645 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1646 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1647 assert(map_is_equal(mm.may, str));
1648 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1649 assert(map_is_equal(mm.must, str));
1651 isl_map_free(mm.must);
1652 isl_map_free(mm.may);
1653 isl_flow_free(flow);
1658 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1659 map = isl_map_read_from_str(ctx, str);
1660 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1662 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1663 map = isl_map_read_from_str(ctx, str);
1664 ai = isl_access_info_add_source(ai, map, 1, &depth);
1666 flow = isl_access_info_compute_flow(ai);
1667 dim = isl_space_alloc(ctx, 0, 5, 5);
1668 mm.must = isl_map_empty(isl_space_copy(dim));
1669 mm.may = isl_map_empty(dim);
1671 isl_flow_foreach(flow, collect_must_may, &mm);
1673 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1674 assert(map_is_equal(mm.must, str));
1675 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1676 assert(map_is_equal(mm.may, str));
1678 isl_map_free(mm.must);
1679 isl_map_free(mm.may);
1680 isl_flow_free(flow);
1683 int test_sv(isl_ctx *ctx)
1687 isl_union_map *umap;
1690 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1691 map = isl_map_read_from_str(ctx, str);
1692 sv = isl_map_is_single_valued(map);
1697 isl_die(ctx, isl_error_internal,
1698 "map not detected as single valued", return -1);
1700 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
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 detected as single valued", return -1);
1710 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1711 umap = isl_union_map_read_from_str(ctx, str);
1712 sv = isl_union_map_is_single_valued(umap);
1713 isl_union_map_free(umap);
1717 isl_die(ctx, isl_error_internal,
1718 "map not detected as single valued", return -1);
1720 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[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 detected as single valued", return -1);
1733 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1737 map = isl_map_read_from_str(ctx, str);
1739 assert(isl_map_is_bijective(map));
1741 assert(!isl_map_is_bijective(map));
1745 void test_bijective(struct isl_ctx *ctx)
1747 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1748 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1749 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1750 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1751 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1752 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1753 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1754 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1755 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1756 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1757 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1758 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1759 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1762 void test_pwqp(struct isl_ctx *ctx)
1766 isl_pw_qpolynomial *pwqp1, *pwqp2;
1768 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1769 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1771 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1774 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1775 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1777 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1779 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1781 isl_pw_qpolynomial_free(pwqp1);
1783 str = "{ [i] -> i }";
1784 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1785 str = "{ [k] : exists a : k = 2a }";
1786 set = isl_set_read_from_str(ctx, str);
1787 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1788 str = "{ [i] -> i }";
1789 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1791 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1793 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1795 isl_pw_qpolynomial_free(pwqp1);
1797 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1798 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1800 set = isl_set_read_from_str(ctx, str);
1801 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1802 str = "{ [i] -> 16 }";
1803 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1805 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1807 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1809 isl_pw_qpolynomial_free(pwqp1);
1811 str = "{ [i] -> ([(i)/2]) }";
1812 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1813 str = "{ [k] : exists a : k = 2a+1 }";
1814 set = isl_set_read_from_str(ctx, str);
1815 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1816 str = "{ [i] -> -1/2 + 1/2 * i }";
1817 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1819 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1821 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1823 isl_pw_qpolynomial_free(pwqp1);
1825 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1826 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1827 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1828 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1830 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1832 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1834 isl_pw_qpolynomial_free(pwqp1);
1836 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1837 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1838 str = "{ [x] -> x }";
1839 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1841 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1843 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1845 isl_pw_qpolynomial_free(pwqp1);
1847 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1848 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1849 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1850 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
1851 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1852 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1853 isl_pw_qpolynomial_free(pwqp1);
1856 void test_split_periods(isl_ctx *ctx)
1859 isl_pw_qpolynomial *pwqp;
1861 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1862 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1863 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1864 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1866 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1869 isl_pw_qpolynomial_free(pwqp);
1872 void test_union(isl_ctx *ctx)
1875 isl_union_set *uset1, *uset2;
1876 isl_union_map *umap1, *umap2;
1878 str = "{ [i] : 0 <= i <= 1 }";
1879 uset1 = isl_union_set_read_from_str(ctx, str);
1880 str = "{ [1] -> [0] }";
1881 umap1 = isl_union_map_read_from_str(ctx, str);
1883 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1884 assert(isl_union_map_is_equal(umap1, umap2));
1886 isl_union_map_free(umap1);
1887 isl_union_map_free(umap2);
1889 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1890 umap1 = isl_union_map_read_from_str(ctx, str);
1891 str = "{ A[i]; B[i] }";
1892 uset1 = isl_union_set_read_from_str(ctx, str);
1894 uset2 = isl_union_map_domain(umap1);
1896 assert(isl_union_set_is_equal(uset1, uset2));
1898 isl_union_set_free(uset1);
1899 isl_union_set_free(uset2);
1902 void test_bound(isl_ctx *ctx)
1905 isl_pw_qpolynomial *pwqp;
1906 isl_pw_qpolynomial_fold *pwf;
1908 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1909 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1910 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1911 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
1912 isl_pw_qpolynomial_fold_free(pwf);
1914 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1915 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1916 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1917 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
1918 isl_pw_qpolynomial_fold_free(pwf);
1921 void test_lift(isl_ctx *ctx)
1924 isl_basic_map *bmap;
1925 isl_basic_set *bset;
1927 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1928 bset = isl_basic_set_read_from_str(ctx, str);
1929 bset = isl_basic_set_lift(bset);
1930 bmap = isl_basic_map_from_range(bset);
1931 bset = isl_basic_map_domain(bmap);
1932 isl_basic_set_free(bset);
1935 void test_subset(isl_ctx *ctx)
1938 isl_set *set1, *set2;
1940 str = "{ [112, 0] }";
1941 set1 = isl_set_read_from_str(ctx, str);
1942 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1943 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1944 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1945 set2 = isl_set_read_from_str(ctx, str);
1946 assert(isl_set_is_subset(set1, set2));
1951 void test_factorize(isl_ctx *ctx)
1954 isl_basic_set *bset;
1957 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1958 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1959 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1960 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1961 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1962 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1963 "3i5 >= -2i0 - i2 + 3i4 }";
1964 bset = isl_basic_set_read_from_str(ctx, str);
1965 f = isl_basic_set_factorizer(bset);
1967 isl_basic_set_free(bset);
1968 isl_factorizer_free(f);
1970 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1971 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1972 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1973 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1974 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1975 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1976 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1977 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1978 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1979 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1980 bset = isl_basic_set_read_from_str(ctx, str);
1981 f = isl_basic_set_factorizer(bset);
1983 isl_basic_set_free(bset);
1984 isl_factorizer_free(f);
1987 static int check_injective(__isl_take isl_map *map, void *user)
1989 int *injective = user;
1991 *injective = isl_map_is_injective(map);
1994 if (*injective < 0 || !*injective)
2000 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2001 const char *r, const char *s, int tilable, int parallel)
2005 isl_union_map *W, *R, *S;
2006 isl_union_map *empty;
2007 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2008 isl_union_map *validity, *proximity;
2009 isl_union_map *schedule;
2010 isl_union_map *test;
2011 isl_union_set *delta;
2012 isl_union_set *domain;
2016 isl_schedule *sched;
2017 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2019 D = isl_union_set_read_from_str(ctx, d);
2020 W = isl_union_map_read_from_str(ctx, w);
2021 R = isl_union_map_read_from_str(ctx, r);
2022 S = isl_union_map_read_from_str(ctx, s);
2024 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2025 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2027 empty = isl_union_map_empty(isl_union_map_get_space(S));
2028 isl_union_map_compute_flow(isl_union_map_copy(R),
2029 isl_union_map_copy(W), empty,
2030 isl_union_map_copy(S),
2031 &dep_raw, NULL, NULL, NULL);
2032 isl_union_map_compute_flow(isl_union_map_copy(W),
2033 isl_union_map_copy(W),
2034 isl_union_map_copy(R),
2035 isl_union_map_copy(S),
2036 &dep_waw, &dep_war, NULL, NULL);
2038 dep = isl_union_map_union(dep_waw, dep_war);
2039 dep = isl_union_map_union(dep, dep_raw);
2040 validity = isl_union_map_copy(dep);
2041 proximity = isl_union_map_copy(dep);
2043 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
2044 validity, proximity);
2045 schedule = isl_schedule_get_map(sched);
2046 isl_schedule_free(sched);
2047 isl_union_map_free(W);
2048 isl_union_map_free(R);
2049 isl_union_map_free(S);
2052 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2054 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2055 is_complete = isl_union_set_is_subset(D, domain);
2056 isl_union_set_free(D);
2057 isl_union_set_free(domain);
2059 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2060 test = isl_union_map_apply_range(test, dep);
2061 test = isl_union_map_apply_range(test, schedule);
2063 delta = isl_union_map_deltas(test);
2064 if (isl_union_set_n_set(delta) == 0) {
2068 isl_union_set_free(delta);
2070 delta_set = isl_set_from_union_set(delta);
2072 slice = isl_set_universe(isl_set_get_space(delta_set));
2073 for (i = 0; i < tilable; ++i)
2074 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2075 is_tilable = isl_set_is_subset(delta_set, slice);
2076 isl_set_free(slice);
2078 slice = isl_set_universe(isl_set_get_space(delta_set));
2079 for (i = 0; i < parallel; ++i)
2080 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2081 is_parallel = isl_set_is_subset(delta_set, slice);
2082 isl_set_free(slice);
2084 origin = isl_set_universe(isl_set_get_space(delta_set));
2085 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2086 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2088 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2089 delta_set = isl_set_lexmin(delta_set);
2091 is_nonneg = isl_set_is_equal(delta_set, origin);
2093 isl_set_free(origin);
2094 isl_set_free(delta_set);
2097 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2098 is_injection < 0 || is_complete < 0)
2101 isl_die(ctx, isl_error_unknown,
2102 "generated schedule incomplete", return -1);
2104 isl_die(ctx, isl_error_unknown,
2105 "generated schedule not injective on each statement",
2108 isl_die(ctx, isl_error_unknown,
2109 "negative dependences in generated schedule",
2112 isl_die(ctx, isl_error_unknown,
2113 "generated schedule not as tilable as expected",
2116 isl_die(ctx, isl_error_unknown,
2117 "generated schedule not as parallel as expected",
2123 int test_special_schedule(isl_ctx *ctx, const char *domain,
2124 const char *validity, const char *proximity, const char *expected_sched)
2128 isl_union_map *prox;
2129 isl_union_map *sched1, *sched2;
2130 isl_schedule *schedule;
2133 dom = isl_union_set_read_from_str(ctx, domain);
2134 dep = isl_union_map_read_from_str(ctx, validity);
2135 prox = isl_union_map_read_from_str(ctx, proximity);
2136 schedule = isl_union_set_compute_schedule(dom, dep, prox);
2137 sched1 = isl_schedule_get_map(schedule);
2138 isl_schedule_free(schedule);
2140 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2142 equal = isl_union_map_is_equal(sched1, sched2);
2143 isl_union_map_free(sched1);
2144 isl_union_map_free(sched2);
2149 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2155 int test_schedule(isl_ctx *ctx)
2157 const char *D, *W, *R, *V, *P, *S;
2160 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2161 W = "{ S1[t,i] -> a[t,i] }";
2162 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2163 "S1[t,i] -> a[t-1,i+1] }";
2164 S = "{ S1[t,i] -> [t,i] }";
2165 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2168 /* Fig. 5 of CC2008 */
2169 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2171 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2172 "j >= 2 and j <= -1 + N }";
2173 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2174 "j >= 2 and j <= -1 + N; "
2175 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2176 "j >= 2 and j <= -1 + N }";
2177 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2178 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2181 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2182 W = "{ S1[i] -> a[i] }";
2183 R = "{ S2[i] -> a[i+1] }";
2184 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2185 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2188 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2189 W = "{ S1[i] -> a[i] }";
2190 R = "{ S2[i] -> a[9-i] }";
2191 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2192 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2195 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2196 W = "{ S1[i] -> a[i] }";
2197 R = "[N] -> { S2[i] -> a[N-1-i] }";
2198 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2199 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2202 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2203 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2204 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2205 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2206 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2209 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2210 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2211 R = "{ S2[i,j] -> a[i-1,j] }";
2212 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2213 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2216 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2217 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2218 R = "{ S2[i,j] -> a[i,j-1] }";
2219 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2220 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2223 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2224 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2225 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2226 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2227 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2228 "S_0[] -> [0, 0, 0] }";
2229 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2231 ctx->opt->schedule_parametric = 0;
2232 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2234 ctx->opt->schedule_parametric = 1;
2236 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2237 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2238 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2239 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2240 "S4[i] -> a[i,N] }";
2241 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2242 "S4[i] -> [4,i,0] }";
2243 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2246 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2247 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2249 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2251 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2253 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2254 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2257 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2258 " S_2[t] : t >= 0 and t <= -1 + N; "
2259 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2261 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2262 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2263 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2264 "i >= 0 and i <= -1 + N }";
2265 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2266 "i >= 0 and i <= -1 + N; "
2267 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2268 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2269 " S_0[t] -> [0, t, 0] }";
2271 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2273 ctx->opt->schedule_parametric = 0;
2274 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2276 ctx->opt->schedule_parametric = 1;
2278 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2279 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2280 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2283 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2284 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2285 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2286 "j >= 0 and j <= -1 + N; "
2287 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2288 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2289 "j >= 0 and j <= -1 + N; "
2290 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2291 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2292 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2295 D = "{ S_0[i] : i >= 0 }";
2296 W = "{ S_0[i] -> a[i] : i >= 0 }";
2297 R = "{ S_0[i] -> a[0] : i >= 0 }";
2298 S = "{ S_0[i] -> [0, i, 0] }";
2299 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2302 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2303 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2304 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2305 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2306 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2309 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2310 "k <= -1 + n and k >= 0 }";
2311 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2312 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2313 "k <= -1 + n and k >= 0; "
2314 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2315 "k <= -1 + n and k >= 0; "
2316 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2317 "k <= -1 + n and k >= 0 }";
2318 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2319 ctx->opt->schedule_outer_zero_distance = 1;
2320 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2322 ctx->opt->schedule_outer_zero_distance = 0;
2324 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
2325 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2326 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2327 "Stmt_for_body24[i0, i1, 1, 0]:"
2328 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2329 "Stmt_for_body7[i0, i1, i2]:"
2330 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2333 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
2334 "Stmt_for_body24[1, i1, i2, i3]:"
2335 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2337 "Stmt_for_body24[0, i1, i2, i3] -> "
2338 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2339 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2341 "Stmt_for_body24[0, i1, i2, i3] ->"
2342 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2343 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2344 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2345 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2346 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2347 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2348 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2349 "i1 <= 6 and i1 >= 0;"
2350 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2351 "Stmt_for_body7[i0, i1, i2] -> "
2352 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2353 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2354 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2355 "Stmt_for_body7[i0, i1, i2] -> "
2356 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2357 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2358 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2360 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2361 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2362 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2364 if (test_special_schedule(ctx, D, V, P, S) < 0)
2367 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2368 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2369 "j >= 1 and j <= 7;"
2370 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2371 "j >= 1 and j <= 8 }";
2373 S = "{ S_0[i, j] -> [i + j, j] }";
2374 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2375 if (test_special_schedule(ctx, D, V, P, S) < 0)
2377 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2379 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2380 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2381 "j >= 0 and j <= -1 + i }";
2382 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2383 "i <= -1 + N and j >= 0;"
2384 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2387 S = "{ S_0[i, j] -> [i, j] }";
2388 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
2389 if (test_special_schedule(ctx, D, V, P, S) < 0)
2391 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
2393 /* Test both algorithms on a case with only proximity dependences. */
2394 D = "{ S[i,j] : 0 <= i <= 10 }";
2396 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2397 S = "{ S[i, j] -> [j, i] }";
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;
2402 return test_special_schedule(ctx, D, V, P, S);
2405 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2407 isl_union_map *umap;
2410 umap = isl_union_map_read_from_str(ctx, str);
2411 test = isl_union_map_plain_is_injective(umap);
2412 isl_union_map_free(umap);
2415 if (test == injective)
2418 isl_die(ctx, isl_error_unknown,
2419 "map not detected as injective", return -1);
2421 isl_die(ctx, isl_error_unknown,
2422 "map detected as injective", return -1);
2425 int test_injective(isl_ctx *ctx)
2429 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2431 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2433 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2435 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2437 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2439 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2441 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2443 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2446 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2447 if (test_plain_injective(ctx, str, 1))
2449 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2450 if (test_plain_injective(ctx, str, 0))
2456 int test_aff(isl_ctx *ctx)
2461 isl_local_space *ls;
2465 dim = isl_space_set_alloc(ctx, 0, 1);
2466 ls = isl_local_space_from_space(dim);
2467 aff = isl_aff_zero_on_domain(ls);
2469 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2470 aff = isl_aff_scale_down_ui(aff, 3);
2471 aff = isl_aff_floor(aff);
2472 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2473 aff = isl_aff_scale_down_ui(aff, 2);
2474 aff = isl_aff_floor(aff);
2475 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
2478 set = isl_set_read_from_str(ctx, str);
2479 aff = isl_aff_gist(aff, set);
2481 aff = isl_aff_add_constant_si(aff, -16);
2482 zero = isl_aff_plain_is_zero(aff);
2488 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2493 int test_dim_max(isl_ctx *ctx)
2497 isl_set *set1, *set2;
2502 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2503 set = isl_set_read_from_str(ctx, str);
2504 pwaff = isl_set_dim_max(set, 0);
2505 set1 = isl_set_from_pw_aff(pwaff);
2506 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2507 set2 = isl_set_read_from_str(ctx, str);
2508 equal = isl_set_is_equal(set1, set2);
2514 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2516 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2517 set = isl_set_read_from_str(ctx, str);
2518 pwaff = isl_set_dim_max(set, 0);
2519 set1 = isl_set_from_pw_aff(pwaff);
2520 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2521 set2 = isl_set_read_from_str(ctx, str);
2522 equal = isl_set_is_equal(set1, set2);
2528 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2530 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2531 set = isl_set_read_from_str(ctx, str);
2532 pwaff = isl_set_dim_max(set, 0);
2533 set1 = isl_set_from_pw_aff(pwaff);
2534 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2535 set2 = isl_set_read_from_str(ctx, str);
2536 equal = isl_set_is_equal(set1, set2);
2542 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2544 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2545 "0 <= i < N and 0 <= j < M }";
2546 map = isl_map_read_from_str(ctx, str);
2547 set = isl_map_range(map);
2549 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
2550 set1 = isl_set_from_pw_aff(pwaff);
2551 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2552 set2 = isl_set_read_from_str(ctx, str);
2553 equal = isl_set_is_equal(set1, set2);
2557 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
2558 set1 = isl_set_from_pw_aff(pwaff);
2559 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2560 set2 = isl_set_read_from_str(ctx, str);
2561 if (equal >= 0 && equal)
2562 equal = isl_set_is_equal(set1, set2);
2571 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2576 int test_product(isl_ctx *ctx)
2580 isl_union_set *uset1, *uset2;
2584 set = isl_set_read_from_str(ctx, str);
2585 set = isl_set_product(set, isl_set_copy(set));
2586 ok = isl_set_is_wrapping(set);
2591 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2594 uset1 = isl_union_set_read_from_str(ctx, str);
2595 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
2596 str = "{ [[] -> []] }";
2597 uset2 = isl_union_set_read_from_str(ctx, str);
2598 ok = isl_union_set_is_equal(uset1, uset2);
2599 isl_union_set_free(uset1);
2600 isl_union_set_free(uset2);
2604 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2609 int test_equal(isl_ctx *ctx)
2612 isl_set *set, *set2;
2616 set = isl_set_read_from_str(ctx, str);
2618 set2 = isl_set_read_from_str(ctx, str);
2619 equal = isl_set_is_equal(set, set2);
2625 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2630 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
2631 enum isl_dim_type type, unsigned pos, int fixed)
2635 test = isl_map_plain_is_fixed(map, type, pos, NULL);
2642 isl_die(ctx, isl_error_unknown,
2643 "map not detected as fixed", return -1);
2645 isl_die(ctx, isl_error_unknown,
2646 "map detected as fixed", return -1);
2649 int test_fixed(isl_ctx *ctx)
2654 str = "{ [i] -> [i] }";
2655 map = isl_map_read_from_str(ctx, str);
2656 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
2658 str = "{ [i] -> [1] }";
2659 map = isl_map_read_from_str(ctx, str);
2660 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2662 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2663 map = isl_map_read_from_str(ctx, str);
2664 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2666 map = isl_map_read_from_str(ctx, str);
2667 map = isl_map_neg(map);
2668 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
2674 int test_vertices(isl_ctx *ctx)
2677 isl_basic_set *bset;
2678 isl_vertices *vertices;
2680 str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2681 bset = isl_basic_set_read_from_str(ctx, str);
2682 vertices = isl_basic_set_compute_vertices(bset);
2683 isl_basic_set_free(bset);
2684 isl_vertices_free(vertices);
2688 str = "{ A[t, i] : t = 14 and i = 1 }";
2689 bset = isl_basic_set_read_from_str(ctx, str);
2690 vertices = isl_basic_set_compute_vertices(bset);
2691 isl_basic_set_free(bset);
2692 isl_vertices_free(vertices);
2699 int test_union_pw(isl_ctx *ctx)
2703 isl_union_set *uset;
2704 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
2706 str = "{ [x] -> x^2 }";
2707 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
2708 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
2709 uset = isl_union_pw_qpolynomial_domain(upwqp1);
2710 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
2711 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
2712 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
2713 isl_union_pw_qpolynomial_free(upwqp1);
2714 isl_union_pw_qpolynomial_free(upwqp2);
2718 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2723 int test_output(isl_ctx *ctx)
2731 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2732 pa = isl_pw_aff_read_from_str(ctx, str);
2734 p = isl_printer_to_str(ctx);
2735 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
2736 p = isl_printer_print_pw_aff(p, pa);
2737 s = isl_printer_get_str(p);
2738 isl_printer_free(p);
2739 isl_pw_aff_free(pa);
2740 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2745 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2750 int test_sample(isl_ctx *ctx)
2753 isl_basic_set *bset1, *bset2;
2756 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2757 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2758 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2759 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2760 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2761 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2762 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2763 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2764 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2765 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2766 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2767 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2768 "d - 1073741821e and "
2769 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2770 "3j >= 1 - a + b + 2e and "
2771 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2772 "3i <= 4 - a + 4b - e and "
2773 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2774 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2775 "c <= -1 + a and 3i >= -2 - a + 3e and "
2776 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2777 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2778 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2779 "1073741823e >= 1 + 1073741823b - d and "
2780 "3i >= 1073741823b + c - 1073741823e - f and "
2781 "3i >= 1 + 2b + e + 3g }";
2782 bset1 = isl_basic_set_read_from_str(ctx, str);
2783 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
2784 empty = isl_basic_set_is_empty(bset2);
2785 subset = isl_basic_set_is_subset(bset2, bset1);
2786 isl_basic_set_free(bset1);
2787 isl_basic_set_free(bset2);
2789 isl_die(ctx, isl_error_unknown, "point not found", return -1);
2791 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
2796 int test_fixed_power(isl_ctx *ctx)
2804 str = "{ [i] -> [i + 1] }";
2805 map = isl_map_read_from_str(ctx, str);
2806 isl_int_set_si(exp, 23);
2807 map = isl_map_fixed_power(map, exp);
2808 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
2819 struct isl_ctx *ctx;
2821 srcdir = getenv("srcdir");
2824 ctx = isl_ctx_alloc();
2825 if (test_fixed_power(ctx) < 0)
2827 if (test_sample(ctx) < 0)
2829 if (test_output(ctx) < 0)
2831 if (test_vertices(ctx) < 0)
2833 if (test_fixed(ctx) < 0)
2835 if (test_equal(ctx) < 0)
2837 if (test_product(ctx) < 0)
2839 if (test_dim_max(ctx) < 0)
2841 if (test_aff(ctx) < 0)
2843 if (test_injective(ctx) < 0)
2845 if (test_schedule(ctx) < 0)
2847 if (test_union_pw(ctx) < 0)
2849 test_factorize(ctx);
2854 test_split_periods(ctx);
2855 if (test_parse(ctx) < 0)
2859 if (test_sv(ctx) < 0)
2861 test_bijective(ctx);
2865 test_construction(ctx);
2868 test_application(ctx);
2869 if (test_affine_hull(ctx) < 0)
2871 test_convex_hull(ctx);
2873 if (test_coalesce(ctx) < 0)