isl_tab_pip.c: align_context_divs: use isl_basic_set_dim
[isl.git] / isl_test2.cc
blob001b6128dc7c24978a3134d38161c2c8cb11452f
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
6 * Copyright 2021-2022 Cerebras Systems
8 * Use of this software is governed by the MIT license
10 * Written by Sven Verdoolaege, K.U.Leuven, Departement
11 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
12 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
13 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
14 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
15 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
16 * B.P. 105 - 78153 Le Chesnay, France
17 * and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
20 #include <assert.h>
21 #include <stdlib.h>
23 #include <functional>
24 #include <ios>
25 #include <iostream>
26 #include <sstream>
27 #include <string>
28 #include <type_traits>
29 #include <utility>
30 #include <vector>
32 #include <isl/cpp.h>
34 /* A binary isl function that appears in the C++ bindings
35 * as a unary method in a class T, taking an extra argument
36 * of type A1 and returning an object of type R.
38 template <typename A1, typename R, typename T>
39 using binary_fn = R (T::*)(A1) const;
41 /* A function for selecting an overload of a pointer to a unary C++ method
42 * based on the single argument type.
43 * The object type and the return type are meant to be deduced.
45 template <typename A1, typename R, typename T>
46 static binary_fn<A1, R, T> const arg(const binary_fn<A1, R, T> &fn)
48 return fn;
51 /* A ternary isl function that appears in the C++ bindings
52 * as a binary method in a class T, taking extra arguments
53 * of type A1 and A2 and returning an object of type R.
55 template <typename A1, typename A2, typename R, typename T>
56 using ternary_fn = R (T::*)(A1, A2) const;
58 /* A function for selecting an overload of a pointer to a binary C++ method
59 * based on the (first) argument type(s).
60 * The object type and the return type are meant to be deduced.
62 template <typename A1, typename A2, typename R, typename T>
63 static ternary_fn<A1, A2, R, T> const arg(const ternary_fn<A1, A2, R, T> &fn)
65 return fn;
68 /* A description of the input and the output of a unary property.
70 struct unary_prop {
71 const char *arg;
72 bool res;
75 /* A description of the input and the output of a unary operation.
77 struct unary {
78 const char *arg;
79 const char *res;
82 /* A description of the inputs and the output of a binary operation.
84 struct binary {
85 const char *arg1;
86 const char *arg2;
87 const char *res;
90 /* A description of the inputs and the output of a ternary operation.
92 struct ternary {
93 const char *arg1;
94 const char *arg2;
95 const char *arg3;
96 const char *res;
99 /* A template function for checking whether two objects
100 * of the same (isl) type are (obviously) equal.
101 * The spelling depends on the isl type and
102 * in particular on whether an equality method is available or
103 * whether only obvious equality can be tested.
105 template <typename T, typename std::decay<decltype(
106 std::declval<T>().is_equal(std::declval<T>()))>::type = true>
107 static bool is_equal(const T &a, const T &b)
109 return a.is_equal(b);
111 template <typename T, typename std::decay<decltype(
112 std::declval<T>().plain_is_equal(std::declval<T>()))>::type = true>
113 static bool is_equal(const T &a, const T &b)
115 return a.plain_is_equal(b);
118 /* A helper macro for throwing an isl::exception_invalid with message "msg".
120 #define THROW_INVALID(msg) \
121 isl::exception::throw_error(isl_error_invalid, msg, __FILE__, __LINE__)
123 /* Run a sequence of tests of function "fn" with stringification "name" and
124 * with input and output described by "tests",
125 * throwing an exception when an unexpected result is produced.
127 template <typename T>
128 static void test(isl::ctx ctx, bool fn(const T &), const std::string &name,
129 const std::vector<unary_prop> &tests)
131 for (const auto &test : tests) {
132 T obj(ctx, test.arg);
133 bool res = fn(obj);
134 std::ostringstream ss;
136 if (test.res == res)
137 continue;
139 ss << name << "(" << test.arg << ") = "
140 << std::boolalpha << res << "\n"
141 << "expecting: "
142 << test.res;
143 THROW_INVALID(ss.str().c_str());
147 /* Run a sequence of tests of method "fn" with stringification "name" and
148 * with input and output described by "test",
149 * throwing an exception when an unexpected result is produced.
151 template <typename R, typename T>
152 static void test(isl::ctx ctx, R (T::*fn)() const, const std::string &name,
153 const std::vector<unary> &tests)
155 for (const auto &test : tests) {
156 T obj(ctx, test.arg);
157 R expected(ctx, test.res);
158 const auto &res = (obj.*fn)();
159 std::ostringstream ss;
161 if (is_equal(expected, res))
162 continue;
164 ss << name << "(" << test.arg << ") =\n"
165 << res << "\n"
166 << "expecting:\n"
167 << expected;
168 THROW_INVALID(ss.str().c_str());
172 /* Run a sequence of tests of method "fn" with stringification "name" and
173 * with inputs and output described by "test",
174 * throwing an exception when an unexpected result is produced.
176 template <typename R, typename T, typename A1>
177 static void test(isl::ctx ctx, R (T::*fn)(A1) const, const std::string &name,
178 const std::vector<binary> &tests)
180 for (const auto &test : tests) {
181 T obj(ctx, test.arg1);
182 A1 arg1(ctx, test.arg2);
183 R expected(ctx, test.res);
184 const auto &res = (obj.*fn)(arg1);
185 std::ostringstream ss;
187 if (is_equal(expected, res))
188 continue;
190 ss << name << "(" << test.arg1 << ", " << test.arg2 << ") =\n"
191 << res << "\n"
192 << "expecting:\n"
193 << expected;
194 THROW_INVALID(ss.str().c_str());
198 /* Run a sequence of tests of method "fn" with stringification "name" and
199 * with inputs and output described by "test",
200 * throwing an exception when an unexpected result is produced.
202 template <typename R, typename T, typename A1, typename A2>
203 static void test(isl::ctx ctx, R (T::*fn)(A1, A2) const,
204 const std::string &name, const std::vector<ternary> &tests)
206 for (const auto &test : tests) {
207 T obj(ctx, test.arg1);
208 A1 arg1(ctx, test.arg2);
209 A2 arg2(ctx, test.arg3);
210 R expected(ctx, test.res);
211 const auto &res = (obj.*fn)(arg1, arg2);
212 std::ostringstream ss;
214 if (is_equal(expected, res))
215 continue;
217 ss << name << "(" << test.arg1 << ", " << test.arg2 << ", "
218 << test.arg3 << ") =\n"
219 << res << "\n"
220 << "expecting:\n"
221 << expected;
222 THROW_INVALID(ss.str().c_str());
226 /* A helper macro that calls test with as implicit initial argument "ctx" and
227 * as extra argument a stringification of "FN".
229 #define C(FN, ...) test(ctx, FN, #FN, __VA_ARGS__)
231 /* Perform some basic isl::space tests.
233 static void test_space(isl::ctx ctx)
235 C(&isl::space::domain, {
236 { "{ A[] -> B[] }", "{ A[] }" },
237 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ A[C[] -> D[]] }" },
240 C(&isl::space::range, {
241 { "{ A[] -> B[] }", "{ B[] }" },
242 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ B[E[] -> F[]] }" },
245 C(&isl::space::params, {
246 { "{ A[] -> B[] }", "{ : }" },
247 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ : }" },
251 /* Does the conversion of "obj" to an isl_pw_multi_aff
252 * result in an expression defined over a single cell?
254 template <typename T>
255 static bool has_single_cell_pma(const T &obj)
257 const auto &fn = obj.as_pw_multi_aff();
258 const auto &domain = fn.domain();
259 return fn.gist(domain).isa_multi_aff();
262 /* Perform some basic conversion tests.
264 * In particular, check that a map with an output dimension
265 * that is equal to some integer division over a domain involving
266 * a local variable without a known integer division expression or
267 * to some linear combination of integer divisions
268 * can be converted to a function expressed in the same way.
270 * Also, check that a nested modulo expression can be extracted
271 * from a set or binary relation representation, or at least
272 * that a conversion to a function does not result in multiple cells.
274 static void test_conversion(isl::ctx ctx)
276 C(&isl::set::as_pw_multi_aff, {
277 { "[N=0:] -> { [] }",
278 "[N=0:] -> { [] }" },
281 C(&isl::multi_pw_aff::as_set, {
282 { "[n] -> { [] : n >= 0 } ",
283 "[n] -> { [] : n >= 0 } " },
286 C(&isl::map::as_pw_multi_aff, {
287 { "{ [a] -> [a//2] : "
288 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
289 "{ [a] -> [a//2] : "
290 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }" },
291 { "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }",
292 "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }" },
295 C(&has_single_cell_pma<isl::set>, {
296 { "[s=0:23] -> { A[(s//4)%3, s%4, s//12] }", true },
299 C(&has_single_cell_pma<isl::map>, {
300 { "{ [a] -> [a//2] : "
301 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
302 true },
303 { "{ [s=0:23, t] -> B[((s+1+2t)//4)%3, 2+(s+1+2t)%4, (s+1+2t)//12] }",
304 true },
305 { "{ [a=0:31] -> [b=0:3, c] : 4c = 28 - a + b }", true },
309 /* Perform some basic preimage tests.
311 static void test_preimage(isl::ctx ctx)
313 C(arg<isl::multi_aff>(&isl::set::preimage), {
314 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
315 "{ A[j,i] -> B[i,j] }",
316 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
317 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
318 "{ A[a,b] -> B[a/2,b/6] }",
319 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
320 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
321 "{ A[a,b] -> B[a/2,b/6] }",
322 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
323 "exists i,j : a = 2 i and b = 6 j }" },
324 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
325 "[n] -> { : 0 <= n <= 100 }" },
326 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
327 "{ A[a] -> B[2a] }",
328 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
329 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
330 "{ A[a] -> B[([a/2])] }",
331 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
332 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
333 "{ A[a] -> B[a,a,a/3] }",
334 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
335 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
336 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
339 C(arg<isl::pw_multi_aff>(&isl::set::preimage), {
340 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
341 "{ A[j,i] -> B[i,j] : false }",
342 "{ A[j,i] : false }" },
345 C(arg<isl::multi_aff>(&isl::union_map::preimage_domain), {
346 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
347 "{ A[j,i] -> B[i,j] }",
348 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
349 { "{ B[i] -> C[i]; D[i] -> E[i] }",
350 "{ A[i] -> B[i + 1] }",
351 "{ A[i] -> C[i + 1] }" },
352 { "{ B[i] -> C[i]; B[i] -> E[i] }",
353 "{ A[i] -> B[i + 1] }",
354 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
355 { "{ B[i] -> C[([i/2])] }",
356 "{ A[i] -> B[2i] }",
357 "{ A[i] -> C[i] }" },
358 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
359 "{ A[i] -> B[([i/5]), ([i/7])] }",
360 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
361 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
362 "[N] -> { A[] -> B[([N/5])] }",
363 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
364 { "{ B[i] -> C[i] : exists a : i = 5 a }",
365 "{ A[i] -> B[2i] }",
366 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
367 { "{ B[i] -> C[i] : exists a : i = 2 a; "
368 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
369 "{ A[i] -> B[2i] }",
370 "{ A[i] -> C[2i] }" },
371 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
372 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
375 C(arg<isl::multi_aff>(&isl::union_map::preimage_range), {
376 { "[M] -> { A[a] -> B[a] }", "[M] -> { C[] -> B[floor(M/2)] }",
377 "[M] -> { A[floor(M/2)] -> C[] }" },
381 /* Perform some basic fixed power tests.
383 static void test_fixed_power(isl::ctx ctx)
385 C(arg<isl::val>(&isl::map::fixed_power), {
386 { "{ [i] -> [i + 1] }", "23",
387 "{ [i] -> [i + 23] }" },
388 { "{ [a = 0:1, b = 0:15, c = 0:1, d = 0:1, 0] -> [a, b, c, d, 1]; "
389 "[a = 0:1, b = 0:15, c = 0:1, 0, 1] -> [a, b, c, 1, 0]; "
390 "[a = 0:1, b = 0:15, 0, 1, 1] -> [a, b, 1, 0, 0]; "
391 "[a = 0:1, b = 0:14, 1, 1, 1] -> [a, 1 + b, 0, 0, 0]; "
392 "[0, 15, 1, 1, 1] -> [1, 0, 0, 0, 0] }",
393 "128",
394 "{ [0, b = 0:15, c = 0:1, d = 0:1, e = 0:1] -> [1, b, c, d, e] }" },
398 /* Perform some basic intersection tests.
400 static void test_intersect(isl::ctx ctx)
402 C(arg<isl::basic_set>(&isl::basic_map::intersect_params), {
403 { "[n] -> { A[x] -> B[y] }", "[n] -> { : n >= 0 }",
404 "[n] -> { A[x] -> B[y] : n >= 0 }" },
407 C(&isl::union_map::intersect_domain_wrapped_domain, {
408 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
409 "{ A[0] }",
410 "{ [A[0] -> B[y]] -> C[z] }" },
411 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
412 "{ A[0] }",
413 "{ }" },
414 { "{ T[A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
415 "{ A[0] }",
416 "{ T[A[0] -> B[y]] -> C[z] }" },
419 C(&isl::union_map::intersect_range_wrapped_domain, {
420 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
421 "{ A[0] }",
422 "{ }" },
423 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
424 "{ A[0] }",
425 "{ C[z] -> [A[0] -> B[y]] }" },
426 { "{ C[z] -> T[A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
427 "{ A[0] }",
428 "{ C[z] -> T[A[0] -> B[y]] }" },
432 /* Perform some basic gist tests.
434 static void test_gist(isl::ctx ctx)
436 C(arg<isl::set>(&isl::pw_aff::gist), {
437 { "{ [x] -> [x] : x != 0 }", "{ [x] : x < -1 or x > 1 }",
438 "{ [x] -> [x] }" },
441 C(&isl::pw_aff::gist_params, {
442 { "[N] -> { D[x] -> [x] : N >= 0; D[x] -> [0] : N < 0 }",
443 "[N] -> { : N >= 0 }",
444 "[N] -> { D[x] -> [x] }" },
447 C(arg<isl::set>(&isl::multi_aff::gist), {
448 { "{ A[i] -> B[i, i] }", "{ A[0] }",
449 "{ A[i] -> B[0, 0] }" },
450 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { A[0] : N = 5 }",
451 "[N] -> { A[i] -> B[0, 5] }" },
452 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
453 "[N] -> { B[6, 5] }" },
454 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
455 "[N] -> { A[i] -> B[] }" },
456 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
457 "[N] -> { B[] }" },
460 C(&isl::multi_aff::gist_params, {
461 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { : N = 5 }",
462 "[N] -> { A[i] -> B[i, 5] }" },
463 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
464 "[N] -> { B[6, 5] }" },
465 { "[N] -> { A[i] -> B[] }", "[N] -> { : N = 5 }",
466 "[N] -> { A[i] -> B[] }" },
467 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
468 "[N] -> { B[] }" },
471 C(arg<isl::set>(&isl::multi_pw_aff::gist), {
472 { "{ A[i] -> B[i, i] : i >= 0 }", "{ A[0] }",
473 "{ A[i] -> B[0, 0] }" },
474 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
475 "[N] -> { A[i] -> B[0, 5] }" },
476 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
477 "[N] -> { B[6, 5] }" },
478 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
479 "[N] -> { A[i] -> B[] }" },
480 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
481 "[N] -> { B[] }" },
482 { "{ A[i=0:10] -> B[i] }", "{ A[5] }",
483 "{ A[i] -> B[5] }" },
484 { "{ A[0:10] -> B[] }", "{ A[0:10] }",
485 "{ A[i] -> B[] }" },
486 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
487 "[N] -> { A[i] -> B[] }" },
488 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
489 "[N] -> { B[] }" },
490 { "[N] -> { B[] : N = 5 }", "[N] -> { : N >= 0 }",
491 "[N] -> { B[] : N = 5 }" },
494 C(&isl::multi_pw_aff::gist_params, {
495 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { : N = 5 }",
496 "[N] -> { A[i] -> B[i, 5] }" },
497 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
498 "[N] -> { B[6, 5] }" },
499 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { : N = 5 }",
500 "[N] -> { A[i] -> B[] }" },
501 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
502 "[N] -> { B[] }" },
503 { "[N] -> { B[] : N >= 5 }", "[N] -> { : N >= 0 }",
504 "[N] -> { B[] : N >= 5 }" },
507 C(&isl::multi_union_pw_aff::gist, {
508 { "C[{ B[i,i] -> [3i] }]", "{ B[i,i] }",
509 "C[{ B[i,j] -> [3i] }]" },
510 { "(C[] : { B[i,i] })", "{ B[i,i] }",
511 "(C[] : { B[i,j] })" },
512 { "[N] -> (C[] : { B[N,N] })", "[N] -> { B[N,N] }",
513 "[N] -> (C[] : { B[i,j] })" },
514 { "C[]", "{ B[i,i] }",
515 "C[]" },
516 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "{ B[i,i] }",
517 "[N] -> (C[] : { B[i,j] : N >= 0 })" },
518 { "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
519 "[N] -> (C[] : { : N >= 0 })" },
520 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { B[i,i] : N >= 0 }",
521 "[N] -> C[]" },
524 C(&isl::multi_union_pw_aff::gist_params, {
525 { "[N] -> C[{ B[i,i] -> [3i + N] }]", "[N] -> { : N = 1 }",
526 "[N] -> C[{ B[i,i] -> [3i + 1] }]" },
527 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
528 "[N] -> C[{ B[i,i] -> [3i] }]" },
529 { "[N] -> C[{ B[i,i] -> [3i] : N >= 0 }]", "[N] -> { : N >= 0 }",
530 "[N] -> C[{ B[i,i] -> [3i] }]" },
531 { "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]", "[N] -> { : N >= 0 }",
532 "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]" },
533 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "[N] -> { : N >= 0 }",
534 "[N] -> (C[] : { B[i,i] })" },
535 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { : N >= 0 }",
536 "[N] -> C[]" },
537 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
538 "[N] -> C[{ B[i,i] -> [3i] }]" },
542 /* Perform tests that project out parameters.
544 static void test_project(isl::ctx ctx)
546 C(arg<isl::id>(&isl::union_map::project_out_param), {
547 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "N",
548 "{ D[i] -> A[0:]; D[i] -> B[i] }" },
549 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "M",
550 "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }" },
553 C(arg<isl::id_list>(&isl::union_map::project_out_param), {
554 { "[M, N, O] -> { D[i] -> A[j] : i <= j < M, N, O }", "(M, N)",
555 "[O] -> { D[i] -> A[j] : i <= j < O }" },
559 /* Perform some basic reverse tests.
561 static void test_reverse(isl::ctx ctx)
563 C(&isl::aff::domain_reverse, {
564 { "{ T[A[] -> B[*]] -> [0] }",
565 "{ [B[*] -> A[]] -> [0] }" },
566 { "{ T[A[] -> A[]] -> [0] }",
567 "{ T[A[] -> A[]] -> [0] }" },
568 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
569 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
572 C(&isl::multi_aff::domain_reverse, {
573 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
574 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
575 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] }",
576 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] }" },
579 C(&isl::set::wrapped_reverse, {
580 { "{ T[A[] -> B[*]] }",
581 "{ [B[*] -> A[]] }" },
582 { "{ T[A[] -> A[]] }",
583 "{ T[A[] -> A[]] }" },
584 { "{ [A[x] -> B[2x]] }",
585 "{ [B[y] -> A[x]] : y = 2x }" },
588 C(&isl::pw_aff::domain_reverse, {
589 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
590 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
591 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] : x > y }",
592 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] : x > y }" },
593 { "{ [A[i] -> B[i + 1]] -> [i + 2] }",
594 "{ [B[i] -> A[i - 1]] -> [i + 1] }" },
597 C(&isl::pw_multi_aff::domain_reverse, {
598 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }",
599 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }" },
600 { "{ [A[i] -> B[i + 1]] -> T[0, i + 2] }",
601 "{ [B[i] -> A[i - 1]] -> T[0, i + 1] }" },
604 C(&isl::multi_pw_aff::domain_reverse, {
605 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }",
606 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }" },
609 C(&isl::map::domain_reverse, {
610 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
611 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
612 { "{ N[B[] -> C[]] -> A[] }",
613 "{ [C[] -> B[]] -> A[] }" },
614 { "{ N[B[x] -> B[y]] -> A[] }",
615 "{ N[B[*] -> B[*]] -> A[] }" },
618 C(&isl::union_map::domain_reverse, {
619 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
620 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
621 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
622 "{ }" },
623 { "{ N[B[] -> C[]] -> A[] }",
624 "{ [C[] -> B[]] -> A[] }" },
625 { "{ N[B[x] -> B[y]] -> A[] }",
626 "{ N[B[*] -> B[*]] -> A[] }" },
629 C(&isl::union_map::range_reverse, {
630 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
631 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
632 { "{ A[] -> N[B[] -> C[]] }",
633 "{ A[] -> [C[] -> B[]] }" },
634 { "{ A[] -> N[B[x] -> B[y]] }",
635 "{ A[] -> N[B[*] -> B[*]] }" },
639 /* Perform some basic scaling tests.
641 static void test_scale(isl::ctx ctx)
643 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale), {
644 { "{ A[a] -> B[a, a + 1, a - 1] : a >= 0 }", "{ B[2, 7, 0] }",
645 "{ A[a] -> B[2a, 7a + 7, 0] : a >= 0 }" },
647 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale), {
648 { "{ A[a] -> B[1, a - 1] : a >= 0 }", "{ B[1/2, 7] }",
649 "{ A[a] -> B[1/2, 7a - 7] : a >= 0 }" },
652 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale_down), {
653 { "{ A[a] -> B[a, a + 1] : a >= 0 }", "{ B[2, 7] }",
654 "{ A[a] -> B[a/2, (a + 1)/7] : a >= 0 }" },
656 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale_down), {
657 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[2, 1/7] }",
658 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
662 /* Perform some basic isl::id_to_id tests.
664 static void test_id_to_id(isl::ctx ctx)
666 C((arg<isl::id, isl::id>(&isl::id_to_id::set)), {
667 { "{ }", "a", "b",
668 "{ a: b }" },
669 { "{ a: b }", "a", "b",
670 "{ a: b }" },
671 { "{ a: c }", "a", "b",
672 "{ a: b }" },
673 { "{ a: b }", "b", "a",
674 "{ a: b, b: a }" },
675 { "{ a: b }", "b", "a",
676 "{ b: a, a: b }" },
680 /* The list of tests to perform.
682 static std::vector<std::pair<const char *, void (*)(isl::ctx)>> tests =
684 { "space", &test_space },
685 { "conversion", &test_conversion },
686 { "preimage", &test_preimage },
687 { "fixed power", &test_fixed_power },
688 { "intersect", &test_intersect },
689 { "gist", &test_gist },
690 { "project out parameters", &test_project },
691 { "reverse", &test_reverse },
692 { "scale", &test_scale },
693 { "id-to-id", &test_id_to_id },
696 /* Perform some basic checks by means of the C++ bindings.
698 int main(int argc, char **argv)
700 int ret = EXIT_SUCCESS;
701 struct isl_ctx *ctx;
702 struct isl_options *options;
704 options = isl_options_new_with_defaults();
705 assert(options);
706 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
707 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
709 try {
710 for (const auto &f : tests) {
711 std::cout << f.first << "\n";
712 f.second(ctx);
714 } catch (const isl::exception &e) {
715 std::cerr << e.what() << "\n";
716 ret = EXIT_FAILURE;
719 isl_ctx_free(ctx);
720 return ret;