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>
26 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
29 char *pattern = "%s/test_inputs/%s.%s";
31 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
33 filename = isl_alloc_array(ctx, char, length);
38 sprintf(filename, pattern, srcdir, name, suffix);
43 void test_parse_map(isl_ctx *ctx, const char *str)
47 map = isl_map_read_from_str(ctx, str, -1);
52 void test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
56 map = isl_map_read_from_str(ctx, str, -1);
57 map2 = isl_map_read_from_str(ctx, str2, -1);
58 assert(map && map2 && isl_map_is_equal(map, map2));
63 void test_parse_pwqp(isl_ctx *ctx, const char *str)
65 isl_pw_qpolynomial *pwqp;
67 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
69 isl_pw_qpolynomial_free(pwqp);
72 void test_parse(struct isl_ctx *ctx)
75 const char *str, *str2;
77 str = "{ [i] -> [-i] }";
78 map = isl_map_read_from_str(ctx, str, -1);
82 str = "{ A[i] -> L[([i/3])] }";
83 map = isl_map_read_from_str(ctx, str, -1);
87 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
88 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
89 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
91 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
92 str2 = "{ [x, y] : 2y >= 6 - x }";
93 test_parse_map_equal(ctx, str, str2);
95 test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
96 "{ [x,y] : x <= y, 2*y + 3 }");
97 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
98 test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }", str);
100 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
101 map = isl_map_read_from_str(ctx, str, -1);
102 str = "{ [new, old] -> [o0, o1] : "
103 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
104 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
105 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
106 map2 = isl_map_read_from_str(ctx, str, -1);
107 assert(isl_map_is_equal(map, map2));
111 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
112 map = isl_map_read_from_str(ctx, str, -1);
113 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
114 map2 = isl_map_read_from_str(ctx, str, -1);
115 assert(isl_map_is_equal(map, map2));
119 str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
120 str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
121 test_parse_map_equal(ctx, str, str2);
123 str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
124 str2 = "{ [i,j] -> [min(i,j)] }";
125 test_parse_map_equal(ctx, str, str2);
127 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
128 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
131 void test_read(struct isl_ctx *ctx)
135 struct isl_basic_set *bset1, *bset2;
136 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
138 filename = get_filename(ctx, "set", "omega");
140 input = fopen(filename, "r");
143 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
144 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
146 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
148 isl_basic_set_free(bset1);
149 isl_basic_set_free(bset2);
155 void test_bounded(struct isl_ctx *ctx)
160 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }", -1);
161 bounded = isl_set_is_bounded(set);
165 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }", -1);
166 bounded = isl_set_is_bounded(set);
170 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }", -1);
171 bounded = isl_set_is_bounded(set);
176 /* Construct the basic set { [i] : 5 <= i <= N } */
177 void test_construction(struct isl_ctx *ctx)
181 struct isl_basic_set *bset;
182 struct isl_constraint *c;
186 dim = isl_dim_set_alloc(ctx, 1, 1);
187 bset = isl_basic_set_universe(dim);
189 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
190 isl_int_set_si(v, -1);
191 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
192 isl_int_set_si(v, 1);
193 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
194 bset = isl_basic_set_add_constraint(bset, c);
196 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
197 isl_int_set_si(v, 1);
198 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
199 isl_int_set_si(v, -5);
200 isl_constraint_set_constant(c, v);
201 bset = isl_basic_set_add_constraint(bset, c);
203 isl_basic_set_free(bset);
208 void test_dim(struct isl_ctx *ctx)
211 isl_map *map1, *map2;
213 map1 = isl_map_read_from_str(ctx,
214 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
215 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
216 map2 = isl_map_read_from_str(ctx,
217 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
218 assert(isl_map_is_equal(map1, map2));
221 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
222 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
223 assert(isl_map_is_equal(map1, map2));
228 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
229 map1 = isl_map_read_from_str(ctx, str, -1);
230 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
231 map2 = isl_map_read_from_str(ctx, str, -1);
232 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
233 assert(isl_map_is_equal(map1, map2));
239 void test_div(struct isl_ctx *ctx)
243 struct isl_basic_set *bset;
244 struct isl_constraint *c;
249 dim = isl_dim_set_alloc(ctx, 0, 3);
250 bset = isl_basic_set_universe(dim);
252 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
253 isl_int_set_si(v, -1);
254 isl_constraint_set_constant(c, v);
255 isl_int_set_si(v, 1);
256 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
257 isl_int_set_si(v, 3);
258 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
259 bset = isl_basic_set_add_constraint(bset, c);
261 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
262 isl_int_set_si(v, 1);
263 isl_constraint_set_constant(c, v);
264 isl_int_set_si(v, -1);
265 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
266 isl_int_set_si(v, 3);
267 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
268 bset = isl_basic_set_add_constraint(bset, c);
270 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
272 assert(bset && bset->n_div == 1);
273 isl_basic_set_free(bset);
276 dim = isl_dim_set_alloc(ctx, 0, 3);
277 bset = isl_basic_set_universe(dim);
279 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
280 isl_int_set_si(v, 1);
281 isl_constraint_set_constant(c, v);
282 isl_int_set_si(v, -1);
283 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
284 isl_int_set_si(v, 3);
285 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
286 bset = isl_basic_set_add_constraint(bset, c);
288 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
289 isl_int_set_si(v, -1);
290 isl_constraint_set_constant(c, v);
291 isl_int_set_si(v, 1);
292 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
293 isl_int_set_si(v, 3);
294 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
295 bset = isl_basic_set_add_constraint(bset, c);
297 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
299 assert(bset && bset->n_div == 1);
300 isl_basic_set_free(bset);
303 dim = isl_dim_set_alloc(ctx, 0, 3);
304 bset = isl_basic_set_universe(dim);
306 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
307 isl_int_set_si(v, 1);
308 isl_constraint_set_constant(c, v);
309 isl_int_set_si(v, -1);
310 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
311 isl_int_set_si(v, 3);
312 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
313 bset = isl_basic_set_add_constraint(bset, c);
315 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
316 isl_int_set_si(v, -3);
317 isl_constraint_set_constant(c, v);
318 isl_int_set_si(v, 1);
319 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
320 isl_int_set_si(v, 4);
321 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
322 bset = isl_basic_set_add_constraint(bset, c);
324 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
326 assert(bset && bset->n_div == 1);
327 isl_basic_set_free(bset);
330 dim = isl_dim_set_alloc(ctx, 0, 3);
331 bset = isl_basic_set_universe(dim);
333 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
334 isl_int_set_si(v, 2);
335 isl_constraint_set_constant(c, v);
336 isl_int_set_si(v, -1);
337 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
338 isl_int_set_si(v, 3);
339 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
340 bset = isl_basic_set_add_constraint(bset, c);
342 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
343 isl_int_set_si(v, -1);
344 isl_constraint_set_constant(c, v);
345 isl_int_set_si(v, 1);
346 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
347 isl_int_set_si(v, 6);
348 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
349 bset = isl_basic_set_add_constraint(bset, c);
351 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
353 assert(isl_basic_set_is_empty(bset));
354 isl_basic_set_free(bset);
357 dim = isl_dim_set_alloc(ctx, 0, 3);
358 bset = isl_basic_set_universe(dim);
360 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
361 isl_int_set_si(v, -1);
362 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
363 isl_int_set_si(v, 3);
364 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
365 bset = isl_basic_set_add_constraint(bset, c);
367 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
368 isl_int_set_si(v, 1);
369 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
370 isl_int_set_si(v, -3);
371 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
372 bset = isl_basic_set_add_constraint(bset, c);
374 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
376 assert(bset && bset->n_div == 0);
377 isl_basic_set_free(bset);
380 dim = isl_dim_set_alloc(ctx, 0, 3);
381 bset = isl_basic_set_universe(dim);
383 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
384 isl_int_set_si(v, -1);
385 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
386 isl_int_set_si(v, 6);
387 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
388 bset = isl_basic_set_add_constraint(bset, c);
390 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
391 isl_int_set_si(v, 1);
392 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
393 isl_int_set_si(v, -3);
394 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
395 bset = isl_basic_set_add_constraint(bset, c);
397 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
399 assert(bset && bset->n_div == 1);
400 isl_basic_set_free(bset);
403 /* This test is a bit tricky. We set up an equality
405 * Normalization of divs creates _two_ divs
408 * Afterwards e0 is removed again because it has coefficient -1
409 * and we end up with the original equality and div again.
410 * Perhaps we can avoid the introduction of this temporary div.
412 dim = isl_dim_set_alloc(ctx, 0, 4);
413 bset = isl_basic_set_universe(dim);
415 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
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 isl_int_set_si(v, -3);
421 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
422 isl_int_set_si(v, 6);
423 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
424 bset = isl_basic_set_add_constraint(bset, c);
426 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
428 /* Test disabled for now */
430 assert(bset && bset->n_div == 1);
432 isl_basic_set_free(bset);
435 dim = isl_dim_set_alloc(ctx, 0, 5);
436 bset = isl_basic_set_universe(dim);
438 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
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, 1, v);
443 isl_int_set_si(v, -3);
444 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
445 isl_int_set_si(v, 6);
446 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
447 bset = isl_basic_set_add_constraint(bset, c);
449 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
450 isl_int_set_si(v, -1);
451 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
452 isl_int_set_si(v, 1);
453 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
454 isl_int_set_si(v, 1);
455 isl_constraint_set_constant(c, v);
456 bset = isl_basic_set_add_constraint(bset, c);
458 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
460 /* Test disabled for now */
462 assert(bset && bset->n_div == 1);
464 isl_basic_set_free(bset);
467 dim = isl_dim_set_alloc(ctx, 0, 4);
468 bset = isl_basic_set_universe(dim);
470 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
471 isl_int_set_si(v, 1);
472 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
473 isl_int_set_si(v, -1);
474 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
475 isl_int_set_si(v, -2);
476 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
477 bset = isl_basic_set_add_constraint(bset, c);
479 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
480 isl_int_set_si(v, -1);
481 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
482 isl_int_set_si(v, 3);
483 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
484 isl_int_set_si(v, 2);
485 isl_constraint_set_constant(c, v);
486 bset = isl_basic_set_add_constraint(bset, c);
488 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
490 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
492 assert(!isl_basic_set_is_empty(bset));
494 isl_basic_set_free(bset);
497 dim = isl_dim_set_alloc(ctx, 0, 3);
498 bset = isl_basic_set_universe(dim);
500 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
501 isl_int_set_si(v, 1);
502 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
503 isl_int_set_si(v, -2);
504 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
505 bset = isl_basic_set_add_constraint(bset, c);
507 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
509 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
511 isl_basic_set_free(bset);
516 void test_application_case(struct isl_ctx *ctx, const char *name)
520 struct isl_basic_set *bset1, *bset2;
521 struct isl_basic_map *bmap;
523 filename = get_filename(ctx, name, "omega");
525 input = fopen(filename, "r");
528 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
529 bmap = isl_basic_map_read_from_file(ctx, input, 0);
531 bset1 = isl_basic_set_apply(bset1, bmap);
533 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
535 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
537 isl_basic_set_free(bset1);
538 isl_basic_set_free(bset2);
544 void test_application(struct isl_ctx *ctx)
546 test_application_case(ctx, "application");
547 test_application_case(ctx, "application2");
550 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
554 struct isl_basic_set *bset1, *bset2;
556 filename = get_filename(ctx, name, "polylib");
558 input = fopen(filename, "r");
561 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
562 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
564 bset1 = isl_basic_set_affine_hull(bset1);
566 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
568 isl_basic_set_free(bset1);
569 isl_basic_set_free(bset2);
575 void test_affine_hull(struct isl_ctx *ctx)
577 test_affine_hull_case(ctx, "affine2");
578 test_affine_hull_case(ctx, "affine");
579 test_affine_hull_case(ctx, "affine3");
582 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
586 struct isl_basic_set *bset1, *bset2;
589 filename = get_filename(ctx, name, "polylib");
591 input = fopen(filename, "r");
594 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
595 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
597 set = isl_basic_set_union(bset1, bset2);
598 bset1 = isl_set_convex_hull(set);
600 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
602 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
604 isl_basic_set_free(bset1);
605 isl_basic_set_free(bset2);
611 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
613 const char *str1, *str2;
614 isl_set *set1, *set2;
615 int orig_convex = ctx->opt->convex;
616 ctx->opt->convex = convex;
618 test_convex_hull_case(ctx, "convex0");
619 test_convex_hull_case(ctx, "convex1");
620 test_convex_hull_case(ctx, "convex2");
621 test_convex_hull_case(ctx, "convex3");
622 test_convex_hull_case(ctx, "convex4");
623 test_convex_hull_case(ctx, "convex5");
624 test_convex_hull_case(ctx, "convex6");
625 test_convex_hull_case(ctx, "convex7");
626 test_convex_hull_case(ctx, "convex8");
627 test_convex_hull_case(ctx, "convex9");
628 test_convex_hull_case(ctx, "convex10");
629 test_convex_hull_case(ctx, "convex11");
630 test_convex_hull_case(ctx, "convex12");
631 test_convex_hull_case(ctx, "convex13");
632 test_convex_hull_case(ctx, "convex14");
633 test_convex_hull_case(ctx, "convex15");
635 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
636 "(i0 = 1 and i1 = 0 and i2 = 1) or "
637 "(i0 = 0 and i1 = 0 and i2 = 0) }";
638 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
639 set1 = isl_set_read_from_str(ctx, str1, -1);
640 set2 = isl_set_read_from_str(ctx, str2, -1);
641 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
642 assert(isl_set_is_equal(set1, set2));
646 ctx->opt->convex = orig_convex;
649 void test_convex_hull(struct isl_ctx *ctx)
651 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
652 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
655 void test_gist_case(struct isl_ctx *ctx, const char *name)
659 struct isl_basic_set *bset1, *bset2;
661 filename = get_filename(ctx, name, "polylib");
663 input = fopen(filename, "r");
666 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
667 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
669 bset1 = isl_basic_set_gist(bset1, bset2);
671 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
673 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
675 isl_basic_set_free(bset1);
676 isl_basic_set_free(bset2);
682 void test_gist(struct isl_ctx *ctx)
685 isl_basic_set *bset1, *bset2;
687 test_gist_case(ctx, "gist1");
689 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
690 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
691 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
692 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
693 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
694 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
695 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
696 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
697 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
698 bset1 = isl_basic_set_read_from_str(ctx, str, -1);
699 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
700 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
701 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
702 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
703 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
704 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
705 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
706 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
707 bset2 = isl_basic_set_read_from_str(ctx, str, -1);
708 bset1 = isl_basic_set_gist(bset1, bset2);
709 assert(bset1 && bset1->n_div == 0);
710 isl_basic_set_free(bset1);
713 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
717 set = isl_set_read_from_str(ctx, str, -1);
718 set = isl_set_coalesce(set);
719 set2 = isl_set_read_from_str(ctx, str, -1);
720 assert(isl_set_is_equal(set, set2));
722 assert(set && set->n == 1);
727 void test_coalesce(struct isl_ctx *ctx)
730 struct isl_set *set, *set2;
731 struct isl_map *map, *map2;
733 set = isl_set_read_from_str(ctx,
734 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
735 "y >= x & x >= 2 & 5 >= y }", -1);
736 set = isl_set_coalesce(set);
737 assert(set && set->n == 1);
740 set = isl_set_read_from_str(ctx,
741 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
742 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
743 set = isl_set_coalesce(set);
744 assert(set && set->n == 1);
747 set = isl_set_read_from_str(ctx,
748 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
749 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
750 set = isl_set_coalesce(set);
751 assert(set && set->n == 2);
754 set = isl_set_read_from_str(ctx,
755 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
756 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
757 set = isl_set_coalesce(set);
758 assert(set && set->n == 1);
761 set = isl_set_read_from_str(ctx,
762 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
763 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
764 set = isl_set_coalesce(set);
765 assert(set && set->n == 2);
768 set = isl_set_read_from_str(ctx,
769 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
770 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
771 set = isl_set_coalesce(set);
772 assert(set && set->n == 2);
775 set = isl_set_read_from_str(ctx,
776 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
777 "y >= 0 & x = 6 & y <= 6}", -1);
778 set = isl_set_coalesce(set);
779 assert(set && set->n == 1);
782 set = isl_set_read_from_str(ctx,
783 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
784 "y >= 0 & x = 7 & y <= 6}", -1);
785 set = isl_set_coalesce(set);
786 assert(set && set->n == 2);
789 set = isl_set_read_from_str(ctx,
790 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
791 "y >= 0 & x = 6 & y <= 5}", -1);
792 set = isl_set_coalesce(set);
793 assert(set && set->n == 1);
794 set2 = isl_set_read_from_str(ctx,
795 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
796 "y >= 0 & x = 6 & y <= 5}", -1);
797 assert(isl_set_is_equal(set, set2));
801 set = isl_set_read_from_str(ctx,
802 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
803 "y >= 0 & x = 6 & y <= 7}", -1);
804 set = isl_set_coalesce(set);
805 assert(set && set->n == 2);
808 set = isl_set_read_from_str(ctx,
809 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
810 set = isl_set_coalesce(set);
811 assert(set && set->n == 1);
812 set2 = isl_set_read_from_str(ctx,
813 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
814 assert(isl_set_is_equal(set, set2));
818 set = isl_set_read_from_str(ctx,
819 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
820 set = isl_set_coalesce(set);
821 set2 = isl_set_read_from_str(ctx,
822 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
823 assert(isl_set_is_equal(set, set2));
827 set = isl_set_read_from_str(ctx,
828 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
829 "2 <= i and i <= n }", -1);
830 set = isl_set_coalesce(set);
831 assert(set && set->n == 1);
832 set2 = isl_set_read_from_str(ctx,
833 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
834 "2 <= i and i <= n }", -1);
835 assert(isl_set_is_equal(set, set2));
839 map = isl_map_read_from_str(ctx,
840 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
841 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
842 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
843 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
844 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
845 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
846 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
847 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
848 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
849 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
850 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
851 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
852 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
853 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
854 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
855 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
856 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
857 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
858 map = isl_map_coalesce(map);
859 map2 = isl_map_read_from_str(ctx,
860 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
861 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
862 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
863 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
864 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
865 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
866 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
867 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
868 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
869 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
870 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
871 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
872 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
873 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
874 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
875 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
876 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
877 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
878 assert(isl_map_is_equal(map, map2));
882 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
883 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
884 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
885 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
886 map = isl_map_read_from_str(ctx, str, -1);
887 map = isl_map_coalesce(map);
888 map2 = isl_map_read_from_str(ctx, str, -1);
889 assert(isl_map_is_equal(map, map2));
893 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
894 "[o0, o1, o2, o3, o4, o5, o6] : "
895 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
896 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
897 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
898 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
899 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
900 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
901 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
902 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
903 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
904 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
905 "o6 >= i3 + i6 - o3 and M >= 0 and "
906 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
907 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
908 map = isl_map_read_from_str(ctx, str, -1);
909 map = isl_map_coalesce(map);
910 map2 = isl_map_read_from_str(ctx, str, -1);
911 assert(isl_map_is_equal(map, map2));
915 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
916 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
917 "(o0 = 0 and M >= 2 and N >= 3) or "
918 "(M = 0 and o0 = 0 and N >= 3) }";
919 map = isl_map_read_from_str(ctx, str, -1);
920 map = isl_map_coalesce(map);
921 map2 = isl_map_read_from_str(ctx, str, -1);
922 assert(isl_map_is_equal(map, map2));
926 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
927 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
928 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
929 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
930 map = isl_map_read_from_str(ctx, str, -1);
931 map = isl_map_coalesce(map);
932 map2 = isl_map_read_from_str(ctx, str, -1);
933 assert(isl_map_is_equal(map, map2));
937 test_coalesce_set(ctx,
938 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
939 "(i1 = M and M >= 1) }", 0);
940 test_coalesce_set(ctx,
941 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
942 test_coalesce_set(ctx,
943 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
944 "(y = 3 and x = 1) }", 1);
945 test_coalesce_set(ctx,
946 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
947 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
948 "i1 <= M and i3 <= M and i4 <= M) or "
949 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
950 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
951 "i4 <= -1 + M) }", 1);
952 test_coalesce_set(ctx,
953 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
954 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
955 test_coalesce_set(ctx,
956 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
957 "-x - y + 1 >= 0 and -3 <= z <= 3;"
958 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
959 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
960 test_coalesce_set(ctx,
961 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
962 test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
963 test_coalesce_set(ctx,
964 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
965 test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
966 test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
967 test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
968 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
969 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
970 test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
971 test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
974 void test_closure(struct isl_ctx *ctx)
982 /* COCOA example 1 */
983 map = isl_map_read_from_str(ctx,
984 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
985 "1 <= i and i < n and 1 <= j and j < n or "
986 "i2 = i + 1 and j2 = j - 1 and "
987 "1 <= i and i < n and 2 <= j and j <= n }", -1);
988 map = isl_map_power(map, &exact);
992 /* COCOA example 1 */
993 map = isl_map_read_from_str(ctx,
994 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
995 "1 <= i and i < n and 1 <= j and j < n or "
996 "i2 = i + 1 and j2 = j - 1 and "
997 "1 <= i and i < n and 2 <= j and j <= n }", -1);
998 map = isl_map_transitive_closure(map, &exact);
1000 map2 = isl_map_read_from_str(ctx,
1001 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1002 "1 <= i and i < n and 1 <= j and j <= n and "
1003 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1004 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1005 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
1006 assert(isl_map_is_equal(map, map2));
1010 map = isl_map_read_from_str(ctx,
1011 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1012 " 0 <= y and y <= n }", -1);
1013 map = isl_map_transitive_closure(map, &exact);
1014 map2 = isl_map_read_from_str(ctx,
1015 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1016 " 0 <= y and y <= n }", -1);
1017 assert(isl_map_is_equal(map, map2));
1021 /* COCOA example 2 */
1022 map = isl_map_read_from_str(ctx,
1023 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1024 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1025 "i2 = i + 2 and j2 = j - 2 and "
1026 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
1027 map = isl_map_transitive_closure(map, &exact);
1029 map2 = isl_map_read_from_str(ctx,
1030 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1031 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1032 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1033 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1034 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1035 assert(isl_map_is_equal(map, map2));
1039 /* COCOA Fig.2 left */
1040 map = isl_map_read_from_str(ctx,
1041 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1042 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1044 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1045 "j <= 2 i - 3 and j <= n - 2 or "
1046 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1047 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1048 map = isl_map_transitive_closure(map, &exact);
1052 /* COCOA Fig.2 right */
1053 map = isl_map_read_from_str(ctx,
1054 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1055 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1057 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1058 "j <= 2 i - 4 and j <= n - 3 or "
1059 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1060 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1061 map = isl_map_power(map, &exact);
1065 /* COCOA Fig.2 right */
1066 map = isl_map_read_from_str(ctx,
1067 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1068 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1070 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1071 "j <= 2 i - 4 and j <= n - 3 or "
1072 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1073 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1074 map = isl_map_transitive_closure(map, &exact);
1076 map2 = isl_map_read_from_str(ctx,
1077 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1078 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1079 "j <= n and 3 + i + 2 j <= 3 n and "
1080 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1081 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1082 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1083 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1084 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1085 assert(isl_map_is_equal(map, map2));
1089 /* COCOA Fig.1 right */
1090 dom = isl_set_read_from_str(ctx,
1091 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1092 "2 x - 3 y + 3 >= 0 }", -1);
1093 right = isl_map_read_from_str(ctx,
1094 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1095 up = isl_map_read_from_str(ctx,
1096 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1097 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1098 right = isl_map_intersect_range(right, isl_set_copy(dom));
1099 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1100 up = isl_map_intersect_range(up, dom);
1101 map = isl_map_union(up, right);
1102 map = isl_map_transitive_closure(map, &exact);
1104 map2 = isl_map_read_from_str(ctx,
1105 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1106 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1107 assert(isl_map_is_equal(map, map2));
1111 /* COCOA Theorem 1 counter example */
1112 map = isl_map_read_from_str(ctx,
1113 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1114 "i2 = 1 and j2 = j or "
1115 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1116 map = isl_map_transitive_closure(map, &exact);
1120 map = isl_map_read_from_str(ctx,
1121 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1122 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1123 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1124 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1125 map = isl_map_transitive_closure(map, &exact);
1129 /* Kelly et al 1996, fig 12 */
1130 map = isl_map_read_from_str(ctx,
1131 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1132 "1 <= i,j,j+1 <= n or "
1133 "j = n and j2 = 1 and i2 = i + 1 and "
1134 "1 <= i,i+1 <= n }", -1);
1135 map = isl_map_transitive_closure(map, &exact);
1137 map2 = isl_map_read_from_str(ctx,
1138 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1139 "1 <= i <= n and i = i2 or "
1140 "1 <= i < i2 <= n and 1 <= j <= n and "
1141 "1 <= j2 <= n }", -1);
1142 assert(isl_map_is_equal(map, map2));
1146 /* Omega's closure4 */
1147 map = isl_map_read_from_str(ctx,
1148 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1149 "1 <= x,y <= 10 or "
1150 "x2 = x + 1 and y2 = y and "
1151 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1152 map = isl_map_transitive_closure(map, &exact);
1156 map = isl_map_read_from_str(ctx,
1157 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1158 map = isl_map_transitive_closure(map, &exact);
1160 map2 = isl_map_read_from_str(ctx,
1161 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1162 assert(isl_map_is_equal(map, map2));
1166 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1167 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1168 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1169 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1170 map = isl_map_read_from_str(ctx, str, -1);
1171 map = isl_map_transitive_closure(map, &exact);
1173 map2 = isl_map_read_from_str(ctx, str, -1);
1174 assert(isl_map_is_equal(map, map2));
1178 str = "{[0] -> [1]; [2] -> [3]}";
1179 map = isl_map_read_from_str(ctx, str, -1);
1180 map = isl_map_transitive_closure(map, &exact);
1182 map2 = isl_map_read_from_str(ctx, str, -1);
1183 assert(isl_map_is_equal(map, map2));
1187 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1188 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1189 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1190 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1191 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1192 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1193 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1194 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1195 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1196 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1197 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1198 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1199 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1200 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1201 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1202 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1203 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1204 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1205 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1206 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1207 map = isl_map_read_from_str(ctx, str, -1);
1208 map = isl_map_transitive_closure(map, NULL);
1213 void test_lex(struct isl_ctx *ctx)
1218 dim = isl_dim_alloc(ctx, 0, 0, 0);
1219 map = isl_map_lex_le(dim);
1220 assert(!isl_map_is_empty(map));
1224 static int consume_lexmin(__isl_take isl_basic_set *dom,
1225 __isl_take isl_aff_list *list, void *user)
1228 isl_basic_map *bmap;
1229 isl_map **map = user;
1231 dim = isl_basic_set_get_dim(dom);
1232 bmap = isl_basic_map_from_aff_list(dim, list);
1233 bmap = isl_basic_map_intersect_domain(bmap, dom);
1235 *map = isl_map_union(*map, isl_map_from_basic_map(bmap));
1240 void test_lexmin(struct isl_ctx *ctx)
1243 isl_basic_map *bmap;
1244 isl_map *map, *map2;
1248 str = "[p0, p1] -> { [] -> [] : "
1249 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1250 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1251 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1252 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1253 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1254 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1255 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1256 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1257 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1258 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1259 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1260 map = isl_map_read_from_str(ctx, str, -1);
1261 map = isl_map_lexmin(map);
1264 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1265 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1266 set = isl_set_read_from_str(ctx, str, -1);
1267 set = isl_set_lexmax(set);
1268 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1269 set2 = isl_set_read_from_str(ctx, str, -1);
1270 set = isl_set_intersect(set, set2);
1271 assert(!isl_set_is_empty(set));
1274 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1275 map = isl_map_read_from_str(ctx, str, -1);
1276 map = isl_map_lexmin(map);
1277 str = "{ [x] -> [5] : 6 <= x <= 8; "
1278 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1279 map2 = isl_map_read_from_str(ctx, str, -1);
1280 assert(isl_map_is_equal(map, map2));
1284 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1285 map = isl_map_read_from_str(ctx, str, -1);
1286 map2 = isl_map_copy(map);
1287 map = isl_map_lexmin(map);
1288 assert(isl_map_is_equal(map, map2));
1292 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1293 map = isl_map_read_from_str(ctx, str, -1);
1294 map = isl_map_lexmin(map);
1295 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1296 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1297 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1298 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1299 map2 = isl_map_read_from_str(ctx, str, -1);
1300 assert(isl_map_is_equal(map, map2));
1304 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1305 " 8i' <= i and 8i' >= -7 + i }";
1306 bmap = isl_basic_map_read_from_str(ctx, str, -1);
1307 map2 = isl_map_empty(isl_basic_map_get_dim(bmap));
1308 isl_basic_map_foreach_lexmin(bmap, &consume_lexmin, &map2);
1309 map = isl_map_from_basic_map(bmap);
1310 assert(isl_map_is_equal(map, map2));
1320 static int collect_must_may(__isl_take isl_map *dep, int must,
1321 void *dep_user, void *user)
1323 struct must_may *mm = (struct must_may *)user;
1326 mm->must = isl_map_union(mm->must, dep);
1328 mm->may = isl_map_union(mm->may, dep);
1333 static int common_space(void *first, void *second)
1335 int depth = *(int *)first;
1339 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1347 map2 = isl_map_read_from_str(map->ctx, str, -1);
1348 equal = isl_map_is_equal(map, map2);
1354 void test_dep(struct isl_ctx *ctx)
1359 isl_access_info *ai;
1366 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1367 map = isl_map_read_from_str(ctx, str, -1);
1368 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1370 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1371 map = isl_map_read_from_str(ctx, str, -1);
1372 ai = isl_access_info_add_source(ai, map, 1, &depth);
1374 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1375 map = isl_map_read_from_str(ctx, str, -1);
1376 ai = isl_access_info_add_source(ai, map, 1, &depth);
1378 flow = isl_access_info_compute_flow(ai);
1379 dim = isl_dim_alloc(ctx, 0, 3, 3);
1380 mm.must = isl_map_empty(isl_dim_copy(dim));
1381 mm.may = isl_map_empty(dim);
1383 isl_flow_foreach(flow, collect_must_may, &mm);
1385 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1386 " [1,10,0] -> [2,5,0] }";
1387 assert(map_is_equal(mm.must, str));
1388 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1389 assert(map_is_equal(mm.may, str));
1391 isl_map_free(mm.must);
1392 isl_map_free(mm.may);
1393 isl_flow_free(flow);
1396 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1397 map = isl_map_read_from_str(ctx, str, -1);
1398 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1400 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1401 map = isl_map_read_from_str(ctx, str, -1);
1402 ai = isl_access_info_add_source(ai, map, 1, &depth);
1404 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1405 map = isl_map_read_from_str(ctx, str, -1);
1406 ai = isl_access_info_add_source(ai, map, 0, &depth);
1408 flow = isl_access_info_compute_flow(ai);
1409 dim = isl_dim_alloc(ctx, 0, 3, 3);
1410 mm.must = isl_map_empty(isl_dim_copy(dim));
1411 mm.may = isl_map_empty(dim);
1413 isl_flow_foreach(flow, collect_must_may, &mm);
1415 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1416 assert(map_is_equal(mm.must, str));
1417 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1418 assert(map_is_equal(mm.may, str));
1420 isl_map_free(mm.must);
1421 isl_map_free(mm.may);
1422 isl_flow_free(flow);
1425 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1426 map = isl_map_read_from_str(ctx, str, -1);
1427 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1429 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1430 map = isl_map_read_from_str(ctx, str, -1);
1431 ai = isl_access_info_add_source(ai, map, 0, &depth);
1433 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1434 map = isl_map_read_from_str(ctx, str, -1);
1435 ai = isl_access_info_add_source(ai, map, 0, &depth);
1437 flow = isl_access_info_compute_flow(ai);
1438 dim = isl_dim_alloc(ctx, 0, 3, 3);
1439 mm.must = isl_map_empty(isl_dim_copy(dim));
1440 mm.may = isl_map_empty(dim);
1442 isl_flow_foreach(flow, collect_must_may, &mm);
1444 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1445 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1446 assert(map_is_equal(mm.may, str));
1447 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1448 assert(map_is_equal(mm.must, str));
1450 isl_map_free(mm.must);
1451 isl_map_free(mm.may);
1452 isl_flow_free(flow);
1455 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1456 map = isl_map_read_from_str(ctx, str, -1);
1457 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1459 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1460 map = isl_map_read_from_str(ctx, str, -1);
1461 ai = isl_access_info_add_source(ai, map, 0, &depth);
1463 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1464 map = isl_map_read_from_str(ctx, str, -1);
1465 ai = isl_access_info_add_source(ai, map, 0, &depth);
1467 flow = isl_access_info_compute_flow(ai);
1468 dim = isl_dim_alloc(ctx, 0, 3, 3);
1469 mm.must = isl_map_empty(isl_dim_copy(dim));
1470 mm.may = isl_map_empty(dim);
1472 isl_flow_foreach(flow, collect_must_may, &mm);
1474 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1475 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1476 assert(map_is_equal(mm.may, str));
1477 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1478 assert(map_is_equal(mm.must, str));
1480 isl_map_free(mm.must);
1481 isl_map_free(mm.may);
1482 isl_flow_free(flow);
1485 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1486 map = isl_map_read_from_str(ctx, str, -1);
1487 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1489 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1490 map = isl_map_read_from_str(ctx, str, -1);
1491 ai = isl_access_info_add_source(ai, map, 0, &depth);
1493 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1494 map = isl_map_read_from_str(ctx, str, -1);
1495 ai = isl_access_info_add_source(ai, map, 0, &depth);
1497 flow = isl_access_info_compute_flow(ai);
1498 dim = isl_dim_alloc(ctx, 0, 3, 3);
1499 mm.must = isl_map_empty(isl_dim_copy(dim));
1500 mm.may = isl_map_empty(dim);
1502 isl_flow_foreach(flow, collect_must_may, &mm);
1504 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1505 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1506 assert(map_is_equal(mm.may, str));
1507 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1508 assert(map_is_equal(mm.must, str));
1510 isl_map_free(mm.must);
1511 isl_map_free(mm.may);
1512 isl_flow_free(flow);
1517 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1518 map = isl_map_read_from_str(ctx, str, -1);
1519 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1521 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1522 map = isl_map_read_from_str(ctx, str, -1);
1523 ai = isl_access_info_add_source(ai, map, 1, &depth);
1525 flow = isl_access_info_compute_flow(ai);
1526 dim = isl_dim_alloc(ctx, 0, 5, 5);
1527 mm.must = isl_map_empty(isl_dim_copy(dim));
1528 mm.may = isl_map_empty(dim);
1530 isl_flow_foreach(flow, collect_must_may, &mm);
1532 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1533 assert(map_is_equal(mm.must, str));
1534 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1535 assert(map_is_equal(mm.may, str));
1537 isl_map_free(mm.must);
1538 isl_map_free(mm.may);
1539 isl_flow_free(flow);
1542 int test_sv(isl_ctx *ctx)
1546 isl_union_map *umap;
1549 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1550 map = isl_map_read_from_str(ctx, str, -1);
1551 sv = isl_map_is_single_valued(map);
1556 isl_die(ctx, isl_error_internal,
1557 "map not detected as single valued", return -1);
1559 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1560 map = isl_map_read_from_str(ctx, str, -1);
1561 sv = isl_map_is_single_valued(map);
1566 isl_die(ctx, isl_error_internal,
1567 "map detected as single valued", return -1);
1569 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1570 umap = isl_union_map_read_from_str(ctx, str);
1571 sv = isl_union_map_is_single_valued(umap);
1572 isl_union_map_free(umap);
1576 isl_die(ctx, isl_error_internal,
1577 "map not detected as single valued", return -1);
1579 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1580 umap = isl_union_map_read_from_str(ctx, str);
1581 sv = isl_union_map_is_single_valued(umap);
1582 isl_union_map_free(umap);
1586 isl_die(ctx, isl_error_internal,
1587 "map detected as single valued", return -1);
1592 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1596 map = isl_map_read_from_str(ctx, str, -1);
1598 assert(isl_map_is_bijective(map));
1600 assert(!isl_map_is_bijective(map));
1604 void test_bijective(struct isl_ctx *ctx)
1606 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1607 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1608 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1609 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1610 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1611 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1612 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1613 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1614 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1615 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1616 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1617 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1618 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1621 void test_pwqp(struct isl_ctx *ctx)
1625 isl_pw_qpolynomial *pwqp1, *pwqp2;
1627 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1628 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1630 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1633 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1634 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1636 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1638 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1640 isl_pw_qpolynomial_free(pwqp1);
1642 str = "{ [i] -> i }";
1643 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1644 str = "{ [k] : exists a : k = 2a }";
1645 set = isl_set_read_from_str(ctx, str, 0);
1646 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1647 str = "{ [i] -> i }";
1648 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1650 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1652 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1654 isl_pw_qpolynomial_free(pwqp1);
1656 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1657 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1659 set = isl_set_read_from_str(ctx, str, 0);
1660 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1661 str = "{ [i] -> 16 }";
1662 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1664 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1666 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1668 isl_pw_qpolynomial_free(pwqp1);
1670 str = "{ [i] -> ([(i)/2]) }";
1671 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1672 str = "{ [k] : exists a : k = 2a+1 }";
1673 set = isl_set_read_from_str(ctx, str, 0);
1674 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1675 str = "{ [i] -> -1/2 + 1/2 * i }";
1676 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1678 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1680 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1682 isl_pw_qpolynomial_free(pwqp1);
1684 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1685 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1686 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1687 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1689 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1691 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1693 isl_pw_qpolynomial_free(pwqp1);
1695 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1696 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1697 str = "{ [x] -> x }";
1698 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1700 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1702 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1704 isl_pw_qpolynomial_free(pwqp1);
1706 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1707 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1708 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1709 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
1710 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1711 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1712 isl_pw_qpolynomial_free(pwqp1);
1715 void test_split_periods(isl_ctx *ctx)
1718 isl_pw_qpolynomial *pwqp;
1720 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1721 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1722 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1723 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1725 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1728 isl_pw_qpolynomial_free(pwqp);
1731 void test_union(isl_ctx *ctx)
1734 isl_union_set *uset1, *uset2;
1735 isl_union_map *umap1, *umap2;
1737 str = "{ [i] : 0 <= i <= 1 }";
1738 uset1 = isl_union_set_read_from_str(ctx, str);
1739 str = "{ [1] -> [0] }";
1740 umap1 = isl_union_map_read_from_str(ctx, str);
1742 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1743 assert(isl_union_map_is_equal(umap1, umap2));
1745 isl_union_map_free(umap1);
1746 isl_union_map_free(umap2);
1748 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1749 umap1 = isl_union_map_read_from_str(ctx, str);
1750 str = "{ A[i]; B[i] }";
1751 uset1 = isl_union_set_read_from_str(ctx, str);
1753 uset2 = isl_union_map_domain(umap1);
1755 assert(isl_union_set_is_equal(uset1, uset2));
1757 isl_union_set_free(uset1);
1758 isl_union_set_free(uset2);
1761 void test_bound(isl_ctx *ctx)
1764 isl_pw_qpolynomial *pwqp;
1765 isl_pw_qpolynomial_fold *pwf;
1767 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1768 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1769 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1770 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
1771 isl_pw_qpolynomial_fold_free(pwf);
1773 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1774 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1775 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1776 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 1);
1777 isl_pw_qpolynomial_fold_free(pwf);
1780 void test_lift(isl_ctx *ctx)
1783 isl_basic_map *bmap;
1784 isl_basic_set *bset;
1786 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1787 bset = isl_basic_set_read_from_str(ctx, str, 0);
1788 bset = isl_basic_set_lift(bset);
1789 bmap = isl_basic_map_from_range(bset);
1790 bset = isl_basic_map_domain(bmap);
1791 isl_basic_set_free(bset);
1794 void test_subset(isl_ctx *ctx)
1797 isl_set *set1, *set2;
1799 str = "{ [112, 0] }";
1800 set1 = isl_set_read_from_str(ctx, str, 0);
1801 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1802 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1803 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1804 set2 = isl_set_read_from_str(ctx, str, 0);
1805 assert(isl_set_is_subset(set1, set2));
1810 void test_factorize(isl_ctx *ctx)
1813 isl_basic_set *bset;
1816 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1817 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1818 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1819 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1820 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1821 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1822 "3i5 >= -2i0 - i2 + 3i4 }";
1823 bset = isl_basic_set_read_from_str(ctx, str, 0);
1824 f = isl_basic_set_factorizer(bset);
1826 isl_basic_set_free(bset);
1827 isl_factorizer_free(f);
1829 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1830 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1831 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1832 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1833 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1834 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1835 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1836 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1837 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1838 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1839 bset = isl_basic_set_read_from_str(ctx, str, 0);
1840 f = isl_basic_set_factorizer(bset);
1842 isl_basic_set_free(bset);
1843 isl_factorizer_free(f);
1846 static int check_injective(__isl_take isl_map *map, void *user)
1848 int *injective = user;
1850 *injective = isl_map_is_injective(map);
1853 if (*injective < 0 || !*injective)
1859 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
1860 const char *r, const char *s, int tilable, int parallel)
1864 isl_union_map *W, *R, *S;
1865 isl_union_map *empty;
1866 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
1867 isl_union_map *validity, *proximity;
1868 isl_union_map *schedule;
1869 isl_union_map *test;
1870 isl_union_set *delta;
1871 isl_union_set *domain;
1875 isl_schedule *sched;
1876 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
1878 D = isl_union_set_read_from_str(ctx, d);
1879 W = isl_union_map_read_from_str(ctx, w);
1880 R = isl_union_map_read_from_str(ctx, r);
1881 S = isl_union_map_read_from_str(ctx, s);
1883 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
1884 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
1886 empty = isl_union_map_empty(isl_union_map_get_dim(S));
1887 isl_union_map_compute_flow(isl_union_map_copy(R),
1888 isl_union_map_copy(W), empty,
1889 isl_union_map_copy(S),
1890 &dep_raw, NULL, NULL, NULL);
1891 isl_union_map_compute_flow(isl_union_map_copy(W),
1892 isl_union_map_copy(W),
1893 isl_union_map_copy(R),
1894 isl_union_map_copy(S),
1895 &dep_waw, &dep_war, NULL, NULL);
1897 dep = isl_union_map_union(dep_waw, dep_war);
1898 dep = isl_union_map_union(dep, dep_raw);
1899 validity = isl_union_map_copy(dep);
1900 proximity = isl_union_map_copy(dep);
1902 sched = isl_union_set_compute_schedule(isl_union_set_copy(D),
1903 validity, proximity);
1904 schedule = isl_schedule_get_map(sched);
1905 isl_schedule_free(sched);
1906 isl_union_map_free(W);
1907 isl_union_map_free(R);
1908 isl_union_map_free(S);
1911 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
1913 domain = isl_union_map_domain(isl_union_map_copy(schedule));
1914 is_complete = isl_union_set_is_subset(D, domain);
1915 isl_union_set_free(D);
1916 isl_union_set_free(domain);
1918 test = isl_union_map_reverse(isl_union_map_copy(schedule));
1919 test = isl_union_map_apply_range(test, dep);
1920 test = isl_union_map_apply_range(test, schedule);
1922 delta = isl_union_map_deltas(test);
1923 if (isl_union_set_n_set(delta) == 0) {
1927 isl_union_set_free(delta);
1929 delta_set = isl_set_from_union_set(delta);
1931 slice = isl_set_universe(isl_set_get_dim(delta_set));
1932 for (i = 0; i < tilable; ++i)
1933 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
1934 is_tilable = isl_set_is_subset(delta_set, slice);
1935 isl_set_free(slice);
1937 slice = isl_set_universe(isl_set_get_dim(delta_set));
1938 for (i = 0; i < parallel; ++i)
1939 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
1940 is_parallel = isl_set_is_subset(delta_set, slice);
1941 isl_set_free(slice);
1943 origin = isl_set_universe(isl_set_get_dim(delta_set));
1944 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
1945 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
1947 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
1948 delta_set = isl_set_lexmin(delta_set);
1950 is_nonneg = isl_set_is_equal(delta_set, origin);
1952 isl_set_free(origin);
1953 isl_set_free(delta_set);
1956 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
1957 is_injection < 0 || is_complete < 0)
1960 isl_die(ctx, isl_error_unknown,
1961 "generated schedule incomplete", return -1);
1963 isl_die(ctx, isl_error_unknown,
1964 "generated schedule not injective on each statement",
1967 isl_die(ctx, isl_error_unknown,
1968 "negative dependences in generated schedule",
1971 isl_die(ctx, isl_error_unknown,
1972 "generated schedule not as tilable as expected",
1975 isl_die(ctx, isl_error_unknown,
1976 "generated schedule not as parallel as expected",
1982 int test_special_schedule(isl_ctx *ctx)
1986 isl_union_map *empty;
1988 isl_union_map *sched1, *sched2;
1989 isl_schedule *schedule;
1992 str = "{ S[i,j] : 0 <= i <= 10 }";
1993 dom = isl_union_set_read_from_str(ctx, str);
1994 str = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
1995 dep = isl_union_map_read_from_str(ctx, str);
1996 empty = isl_union_map_read_from_str(ctx, "{}");
1997 schedule = isl_union_set_compute_schedule(dom, empty, dep);
1998 sched1 = isl_schedule_get_map(schedule);
1999 isl_schedule_free(schedule);
2001 str = "{ S[i, j] -> [j, i] }";
2002 sched2 = isl_union_map_read_from_str(ctx, str);
2004 equal = isl_union_map_is_equal(sched1, sched2);
2005 isl_union_map_free(sched1);
2006 isl_union_map_free(sched2);
2011 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2017 int test_schedule(isl_ctx *ctx)
2019 const char *D, *W, *R, *S;
2022 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2023 W = "{ S1[t,i] -> a[t,i] }";
2024 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2025 "S1[t,i] -> a[t-1,i+1] }";
2026 S = "{ S1[t,i] -> [t,i] }";
2027 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2030 /* Fig. 5 of CC2008 */
2031 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2033 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2034 "j >= 2 and j <= -1 + N }";
2035 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2036 "j >= 2 and j <= -1 + N; "
2037 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2038 "j >= 2 and j <= -1 + N }";
2039 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2040 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2043 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2044 W = "{ S1[i] -> a[i] }";
2045 R = "{ S2[i] -> a[i+1] }";
2046 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2047 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2050 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2051 W = "{ S1[i] -> a[i] }";
2052 R = "{ S2[i] -> a[9-i] }";
2053 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2054 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2057 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2058 W = "{ S1[i] -> a[i] }";
2059 R = "[N] -> { S2[i] -> a[N-1-i] }";
2060 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2061 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2064 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2065 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2066 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2067 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2068 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2071 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2072 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2073 R = "{ S2[i,j] -> a[i-1,j] }";
2074 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2075 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2078 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2079 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2080 R = "{ S2[i,j] -> a[i,j-1] }";
2081 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2082 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2085 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2086 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2087 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2088 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2089 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2090 "S_0[] -> [0, 0, 0] }";
2091 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2093 ctx->opt->schedule_parametric = 0;
2094 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2096 ctx->opt->schedule_parametric = 1;
2098 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2099 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2100 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2101 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2102 "S4[i] -> a[i,N] }";
2103 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2104 "S4[i] -> [4,i,0] }";
2105 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2108 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2109 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2111 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2113 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2115 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2116 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2119 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2120 " S_2[t] : t >= 0 and t <= -1 + N; "
2121 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2123 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2124 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2125 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2126 "i >= 0 and i <= -1 + N }";
2127 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2128 "i >= 0 and i <= -1 + N; "
2129 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2130 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2131 " S_0[t] -> [0, t, 0] }";
2133 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2135 ctx->opt->schedule_parametric = 0;
2136 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2138 ctx->opt->schedule_parametric = 1;
2140 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2141 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2142 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2145 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2146 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2147 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2148 "j >= 0 and j <= -1 + N; "
2149 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2150 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2151 "j >= 0 and j <= -1 + N; "
2152 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2153 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2154 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2157 D = "{ S_0[i] : i >= 0 }";
2158 W = "{ S_0[i] -> a[i] : i >= 0 }";
2159 R = "{ S_0[i] -> a[0] : i >= 0 }";
2160 S = "{ S_0[i] -> [0, i, 0] }";
2161 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2164 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2165 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2166 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2167 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2168 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2171 return test_special_schedule(ctx);
2174 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
2176 isl_union_map *umap;
2179 umap = isl_union_map_read_from_str(ctx, str);
2180 test = isl_union_map_plain_is_injective(umap);
2181 isl_union_map_free(umap);
2184 if (test == injective)
2187 isl_die(ctx, isl_error_unknown,
2188 "map not detected as injective", return -1);
2190 isl_die(ctx, isl_error_unknown,
2191 "map detected as injective", return -1);
2194 int test_injective(isl_ctx *ctx)
2198 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2200 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
2202 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
2204 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
2206 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2208 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2210 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2212 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2215 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2216 if (test_plain_injective(ctx, str, 1))
2218 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2219 if (test_plain_injective(ctx, str, 0))
2225 int test_aff(isl_ctx *ctx)
2230 isl_local_space *ls;
2234 dim = isl_dim_set_alloc(ctx, 0, 1);
2235 ls = isl_local_space_from_dim(dim);
2236 aff = isl_aff_zero(ls);
2238 aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
2239 aff = isl_aff_scale_down_ui(aff, 3);
2240 aff = isl_aff_floor(aff);
2241 aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
2242 aff = isl_aff_scale_down_ui(aff, 2);
2243 aff = isl_aff_floor(aff);
2244 aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
2247 set = isl_set_read_from_str(ctx, str, 0);
2248 aff = isl_aff_gist(aff, set);
2250 aff = isl_aff_add_constant_si(aff, -16);
2251 zero = isl_aff_plain_is_zero(aff);
2257 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2262 int test_dim_max(isl_ctx *ctx)
2266 isl_map *map, *map2;
2270 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
2271 set = isl_set_read_from_str(ctx, str, -1);
2272 pwaff = isl_set_dim_max(set, 0);
2273 map = isl_map_from_pw_aff(pwaff);
2274 str = "[N] -> { [] -> [10] : N >= 10; [] -> [N] : N <= 9 and N >= 0 }";
2275 map2 = isl_map_read_from_str(ctx, str, -1);
2276 equal = isl_map_is_equal(map, map2);
2282 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2284 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2285 set = isl_set_read_from_str(ctx, str, -1);
2286 pwaff = isl_set_dim_max(set, 0);
2287 map = isl_map_from_pw_aff(pwaff);
2288 str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
2289 map2 = isl_map_read_from_str(ctx, str, -1);
2290 equal = isl_map_is_equal(map, map2);
2296 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2298 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2299 set = isl_set_read_from_str(ctx, str, -1);
2300 pwaff = isl_set_dim_max(set, 0);
2301 map = isl_map_from_pw_aff(pwaff);
2302 str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
2303 map2 = isl_map_read_from_str(ctx, str, -1);
2304 equal = isl_map_is_equal(map, map2);
2310 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2312 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2313 "0 <= i < N and 0 <= j < M }";
2314 map = isl_map_read_from_str(ctx, str, -1);
2315 set = isl_map_range(map);
2317 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
2318 map = isl_map_from_pw_aff(pwaff);
2319 str = "[N,M] -> { [] -> [([(N-1)/16])] : M,N > 0 }";
2320 map2 = isl_map_read_from_str(ctx, str, -1);
2321 equal = isl_map_is_equal(map, map2);
2325 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
2326 map = isl_map_from_pw_aff(pwaff);
2327 str = "[N,M] -> { [] -> [t] : t = min(M-1,15) and M,N > 0 }";
2328 map2 = isl_map_read_from_str(ctx, str, -1);
2329 if (equal >= 0 && equal)
2330 equal = isl_map_is_equal(map, map2);
2339 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2346 struct isl_ctx *ctx;
2348 srcdir = getenv("srcdir");
2351 ctx = isl_ctx_alloc();
2352 if (test_dim_max(ctx) < 0)
2354 if (test_aff(ctx) < 0)
2356 if (test_injective(ctx) < 0)
2358 if (test_schedule(ctx) < 0)
2360 test_factorize(ctx);
2365 test_split_periods(ctx);
2369 if (test_sv(ctx) < 0)
2371 test_bijective(ctx);
2375 test_construction(ctx);
2378 test_application(ctx);
2379 test_affine_hull(ctx);
2380 test_convex_hull(ctx);