isl_aff.c: pw_multi_aff_from_map_div: allow nested integer divisions
[isl.git] / isl_test2.cc
blobe0ea92781061003fb42d64245810a43eb85263ce
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 <iostream>
25 #include <sstream>
26 #include <string>
27 #include <type_traits>
28 #include <utility>
29 #include <vector>
31 #include <isl/cpp.h>
33 /* A binary isl function that appears in the C++ bindings
34 * as a unary method in a class T, taking an extra argument
35 * of type A1 and returning an object of type R.
37 template <typename A1, typename R, typename T>
38 using binary_fn = R (T::*)(A1) const;
40 /* A function for selecting an overload of a pointer to a unary C++ method
41 * based on the single argument type.
42 * The object type and the return type are meant to be deduced.
44 template <typename A1, typename R, typename T>
45 static binary_fn<A1, R, T> const arg(const binary_fn<A1, R, T> &fn)
47 return fn;
50 /* A ternary isl function that appears in the C++ bindings
51 * as a binary method in a class T, taking extra arguments
52 * of type A1 and A2 and returning an object of type R.
54 template <typename A1, typename A2, typename R, typename T>
55 using ternary_fn = R (T::*)(A1, A2) const;
57 /* A function for selecting an overload of a pointer to a binary C++ method
58 * based on the (first) argument type(s).
59 * The object type and the return type are meant to be deduced.
61 template <typename A1, typename A2, typename R, typename T>
62 static ternary_fn<A1, A2, R, T> const arg(const ternary_fn<A1, A2, R, T> &fn)
64 return fn;
67 /* A description of the input and the output of a unary operation.
69 struct unary {
70 const char *arg;
71 const char *res;
74 /* A description of the inputs and the output of a binary operation.
76 struct binary {
77 const char *arg1;
78 const char *arg2;
79 const char *res;
82 /* A description of the inputs and the output of a ternary operation.
84 struct ternary {
85 const char *arg1;
86 const char *arg2;
87 const char *arg3;
88 const char *res;
91 /* A template function for checking whether two objects
92 * of the same (isl) type are (obviously) equal.
93 * The spelling depends on the isl type and
94 * in particular on whether an equality method is available or
95 * whether only obvious equality can be tested.
97 template <typename T, typename std::decay<decltype(
98 std::declval<T>().is_equal(std::declval<T>()))>::type = true>
99 static bool is_equal(const T &a, const T &b)
101 return a.is_equal(b);
103 template <typename T, typename std::decay<decltype(
104 std::declval<T>().plain_is_equal(std::declval<T>()))>::type = true>
105 static bool is_equal(const T &a, const T &b)
107 return a.plain_is_equal(b);
110 /* A helper macro for throwing an isl::exception_invalid with message "msg".
112 #define THROW_INVALID(msg) \
113 isl::exception::throw_error(isl_error_invalid, msg, __FILE__, __LINE__)
115 /* Run a sequence of tests of method "fn" with stringification "name" and
116 * with input and output described by "test",
117 * throwing an exception when an unexpected result is produced.
119 template <typename R, typename T>
120 static void test(isl::ctx ctx, R (T::*fn)() const, const std::string &name,
121 const std::vector<unary> &tests)
123 for (const auto &test : tests) {
124 T obj(ctx, test.arg);
125 R expected(ctx, test.res);
126 const auto &res = (obj.*fn)();
127 std::ostringstream ss;
129 if (is_equal(expected, res))
130 continue;
132 ss << name << "(" << test.arg << ") =\n"
133 << res << "\n"
134 << "expecting:\n"
135 << expected;
136 THROW_INVALID(ss.str().c_str());
140 /* Run a sequence of tests of method "fn" with stringification "name" and
141 * with inputs and output described by "test",
142 * throwing an exception when an unexpected result is produced.
144 template <typename R, typename T, typename A1>
145 static void test(isl::ctx ctx, R (T::*fn)(A1) const, const std::string &name,
146 const std::vector<binary> &tests)
148 for (const auto &test : tests) {
149 T obj(ctx, test.arg1);
150 A1 arg1(ctx, test.arg2);
151 R expected(ctx, test.res);
152 const auto &res = (obj.*fn)(arg1);
153 std::ostringstream ss;
155 if (is_equal(expected, res))
156 continue;
158 ss << name << "(" << test.arg1 << ", " << test.arg2 << ") =\n"
159 << res << "\n"
160 << "expecting:\n"
161 << expected;
162 THROW_INVALID(ss.str().c_str());
166 /* Run a sequence of tests of method "fn" with stringification "name" and
167 * with inputs and output described by "test",
168 * throwing an exception when an unexpected result is produced.
170 template <typename R, typename T, typename A1, typename A2>
171 static void test(isl::ctx ctx, R (T::*fn)(A1, A2) const,
172 const std::string &name, const std::vector<ternary> &tests)
174 for (const auto &test : tests) {
175 T obj(ctx, test.arg1);
176 A1 arg1(ctx, test.arg2);
177 A2 arg2(ctx, test.arg3);
178 R expected(ctx, test.res);
179 const auto &res = (obj.*fn)(arg1, arg2);
180 std::ostringstream ss;
182 if (is_equal(expected, res))
183 continue;
185 ss << name << "(" << test.arg1 << ", " << test.arg2 << ", "
186 << test.arg3 << ") =\n"
187 << res << "\n"
188 << "expecting:\n"
189 << expected;
190 THROW_INVALID(ss.str().c_str());
194 /* A helper macro that calls test with as implicit initial argument "ctx" and
195 * as extra argument a stringification of "FN".
197 #define C(FN, ...) test(ctx, FN, #FN, __VA_ARGS__)
199 /* Perform some basic isl::space tests.
201 static void test_space(isl::ctx ctx)
203 C(&isl::space::domain, {
204 { "{ A[] -> B[] }", "{ A[] }" },
205 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ A[C[] -> D[]] }" },
208 C(&isl::space::range, {
209 { "{ A[] -> B[] }", "{ B[] }" },
210 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ B[E[] -> F[]] }" },
213 C(&isl::space::params, {
214 { "{ A[] -> B[] }", "{ : }" },
215 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ : }" },
219 /* Perform some basic conversion tests.
221 * In particular, check that a map with an output dimension
222 * that is equal to some integer division over a domain involving
223 * a local variable without a known integer division expression
224 * can be converted to a function expressed in the same way.
226 static void test_conversion(isl::ctx ctx)
228 C(&isl::set::as_pw_multi_aff, {
229 { "[N=0:] -> { [] }",
230 "[N=0:] -> { [] }" },
233 C(&isl::multi_pw_aff::as_set, {
234 { "[n] -> { [] : n >= 0 } ",
235 "[n] -> { [] : n >= 0 } " },
238 C(&isl::map::as_pw_multi_aff, {
239 { "{ [a] -> [a//2] : "
240 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
241 "{ [a] -> [a//2] : "
242 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }" },
246 /* Perform some basic preimage tests.
248 static void test_preimage(isl::ctx ctx)
250 C(arg<isl::multi_aff>(&isl::set::preimage), {
251 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
252 "{ A[j,i] -> B[i,j] }",
253 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
254 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
255 "{ A[a,b] -> B[a/2,b/6] }",
256 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
257 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
258 "{ A[a,b] -> B[a/2,b/6] }",
259 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
260 "exists i,j : a = 2 i and b = 6 j }" },
261 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
262 "[n] -> { : 0 <= n <= 100 }" },
263 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
264 "{ A[a] -> B[2a] }",
265 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
266 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
267 "{ A[a] -> B[([a/2])] }",
268 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
269 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
270 "{ A[a] -> B[a,a,a/3] }",
271 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
272 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
273 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
276 C(arg<isl::pw_multi_aff>(&isl::set::preimage), {
277 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
278 "{ A[j,i] -> B[i,j] : false }",
279 "{ A[j,i] : false }" },
282 C(arg<isl::multi_aff>(&isl::union_map::preimage_domain), {
283 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
284 "{ A[j,i] -> B[i,j] }",
285 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
286 { "{ B[i] -> C[i]; D[i] -> E[i] }",
287 "{ A[i] -> B[i + 1] }",
288 "{ A[i] -> C[i + 1] }" },
289 { "{ B[i] -> C[i]; B[i] -> E[i] }",
290 "{ A[i] -> B[i + 1] }",
291 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
292 { "{ B[i] -> C[([i/2])] }",
293 "{ A[i] -> B[2i] }",
294 "{ A[i] -> C[i] }" },
295 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
296 "{ A[i] -> B[([i/5]), ([i/7])] }",
297 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
298 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
299 "[N] -> { A[] -> B[([N/5])] }",
300 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
301 { "{ B[i] -> C[i] : exists a : i = 5 a }",
302 "{ A[i] -> B[2i] }",
303 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
304 { "{ B[i] -> C[i] : exists a : i = 2 a; "
305 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
306 "{ A[i] -> B[2i] }",
307 "{ A[i] -> C[2i] }" },
308 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
309 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
312 C(arg<isl::multi_aff>(&isl::union_map::preimage_range), {
313 { "[M] -> { A[a] -> B[a] }", "[M] -> { C[] -> B[floor(M/2)] }",
314 "[M] -> { A[floor(M/2)] -> C[] }" },
318 /* Perform some basic fixed power tests.
320 static void test_fixed_power(isl::ctx ctx)
322 C(arg<isl::val>(&isl::map::fixed_power), {
323 { "{ [i] -> [i + 1] }", "23",
324 "{ [i] -> [i + 23] }" },
325 { "{ [a = 0:1, b = 0:15, c = 0:1, d = 0:1, 0] -> [a, b, c, d, 1]; "
326 "[a = 0:1, b = 0:15, c = 0:1, 0, 1] -> [a, b, c, 1, 0]; "
327 "[a = 0:1, b = 0:15, 0, 1, 1] -> [a, b, 1, 0, 0]; "
328 "[a = 0:1, b = 0:14, 1, 1, 1] -> [a, 1 + b, 0, 0, 0]; "
329 "[0, 15, 1, 1, 1] -> [1, 0, 0, 0, 0] }",
330 "128",
331 "{ [0, b = 0:15, c = 0:1, d = 0:1, e = 0:1] -> [1, b, c, d, e] }" },
335 /* Perform some basic intersection tests.
337 static void test_intersect(isl::ctx ctx)
339 C(&isl::union_map::intersect_domain_wrapped_domain, {
340 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
341 "{ A[0] }",
342 "{ [A[0] -> B[y]] -> C[z] }" },
343 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
344 "{ A[0] }",
345 "{ }" },
346 { "{ T[A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
347 "{ A[0] }",
348 "{ T[A[0] -> B[y]] -> C[z] }" },
351 C(&isl::union_map::intersect_range_wrapped_domain, {
352 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
353 "{ A[0] }",
354 "{ }" },
355 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
356 "{ A[0] }",
357 "{ C[z] -> [A[0] -> B[y]] }" },
358 { "{ C[z] -> T[A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
359 "{ A[0] }",
360 "{ C[z] -> T[A[0] -> B[y]] }" },
364 /* Perform some basic gist tests.
366 static void test_gist(isl::ctx ctx)
368 C(arg<isl::set>(&isl::pw_aff::gist), {
369 { "{ [x] -> [x] : x != 0 }", "{ [x] : x < -1 or x > 1 }",
370 "{ [x] -> [x] }" },
373 C(&isl::pw_aff::gist_params, {
374 { "[N] -> { D[x] -> [x] : N >= 0; D[x] -> [0] : N < 0 }",
375 "[N] -> { : N >= 0 }",
376 "[N] -> { D[x] -> [x] }" },
379 C(arg<isl::set>(&isl::multi_aff::gist), {
380 { "{ A[i] -> B[i, i] }", "{ A[0] }",
381 "{ A[i] -> B[0, 0] }" },
382 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { A[0] : N = 5 }",
383 "[N] -> { A[i] -> B[0, 5] }" },
384 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
385 "[N] -> { B[6, 5] }" },
386 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
387 "[N] -> { A[i] -> B[] }" },
388 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
389 "[N] -> { B[] }" },
392 C(&isl::multi_aff::gist_params, {
393 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { : N = 5 }",
394 "[N] -> { A[i] -> B[i, 5] }" },
395 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
396 "[N] -> { B[6, 5] }" },
397 { "[N] -> { A[i] -> B[] }", "[N] -> { : N = 5 }",
398 "[N] -> { A[i] -> B[] }" },
399 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
400 "[N] -> { B[] }" },
403 C(arg<isl::set>(&isl::multi_pw_aff::gist), {
404 { "{ A[i] -> B[i, i] : i >= 0 }", "{ A[0] }",
405 "{ A[i] -> B[0, 0] }" },
406 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
407 "[N] -> { A[i] -> B[0, 5] }" },
408 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
409 "[N] -> { B[6, 5] }" },
410 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
411 "[N] -> { A[i] -> B[] }" },
412 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
413 "[N] -> { B[] }" },
414 { "{ A[i=0:10] -> B[i] }", "{ A[5] }",
415 "{ A[i] -> B[5] }" },
416 { "{ A[0:10] -> B[] }", "{ A[0:10] }",
417 "{ A[i] -> B[] }" },
418 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
419 "[N] -> { A[i] -> B[] }" },
420 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
421 "[N] -> { B[] }" },
422 { "[N] -> { B[] : N = 5 }", "[N] -> { : N >= 0 }",
423 "[N] -> { B[] : N = 5 }" },
426 C(&isl::multi_pw_aff::gist_params, {
427 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { : N = 5 }",
428 "[N] -> { A[i] -> B[i, 5] }" },
429 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
430 "[N] -> { B[6, 5] }" },
431 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { : N = 5 }",
432 "[N] -> { A[i] -> B[] }" },
433 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
434 "[N] -> { B[] }" },
435 { "[N] -> { B[] : N >= 5 }", "[N] -> { : N >= 0 }",
436 "[N] -> { B[] : N >= 5 }" },
439 C(&isl::multi_union_pw_aff::gist, {
440 { "C[{ B[i,i] -> [3i] }]", "{ B[i,i] }",
441 "C[{ B[i,j] -> [3i] }]" },
442 { "(C[] : { B[i,i] })", "{ B[i,i] }",
443 "(C[] : { B[i,j] })" },
444 { "[N] -> (C[] : { B[N,N] })", "[N] -> { B[N,N] }",
445 "[N] -> (C[] : { B[i,j] })" },
446 { "C[]", "{ B[i,i] }",
447 "C[]" },
448 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "{ B[i,i] }",
449 "[N] -> (C[] : { B[i,j] : N >= 0 })" },
450 { "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
451 "[N] -> (C[] : { : N >= 0 })" },
452 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { B[i,i] : N >= 0 }",
453 "[N] -> C[]" },
456 C(&isl::multi_union_pw_aff::gist_params, {
457 { "[N] -> C[{ B[i,i] -> [3i + N] }]", "[N] -> { : N = 1 }",
458 "[N] -> C[{ B[i,i] -> [3i + 1] }]" },
459 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
460 "[N] -> C[{ B[i,i] -> [3i] }]" },
461 { "[N] -> C[{ B[i,i] -> [3i] : N >= 0 }]", "[N] -> { : N >= 0 }",
462 "[N] -> C[{ B[i,i] -> [3i] }]" },
463 { "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]", "[N] -> { : N >= 0 }",
464 "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]" },
465 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "[N] -> { : N >= 0 }",
466 "[N] -> (C[] : { B[i,i] })" },
467 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { : N >= 0 }",
468 "[N] -> C[]" },
469 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
470 "[N] -> C[{ B[i,i] -> [3i] }]" },
474 /* Perform tests that project out parameters.
476 static void test_project(isl::ctx ctx)
478 C(arg<isl::id>(&isl::union_map::project_out_param), {
479 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "N",
480 "{ D[i] -> A[0:]; D[i] -> B[i] }" },
481 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "M",
482 "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }" },
485 C(arg<isl::id_list>(&isl::union_map::project_out_param), {
486 { "[M, N, O] -> { D[i] -> A[j] : i <= j < M, N, O }", "(M, N)",
487 "[O] -> { D[i] -> A[j] : i <= j < O }" },
491 /* Perform some basic reverse tests.
493 static void test_reverse(isl::ctx ctx)
495 C(&isl::aff::domain_reverse, {
496 { "{ T[A[] -> B[*]] -> [0] }",
497 "{ [B[*] -> A[]] -> [0] }" },
498 { "{ T[A[] -> A[]] -> [0] }",
499 "{ T[A[] -> A[]] -> [0] }" },
500 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
501 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
504 C(&isl::multi_aff::domain_reverse, {
505 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
506 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
507 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] }",
508 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] }" },
511 C(&isl::set::wrapped_reverse, {
512 { "{ T[A[] -> B[*]] }",
513 "{ [B[*] -> A[]] }" },
514 { "{ T[A[] -> A[]] }",
515 "{ T[A[] -> A[]] }" },
516 { "{ [A[x] -> B[2x]] }",
517 "{ [B[y] -> A[x]] : y = 2x }" },
520 C(&isl::pw_aff::domain_reverse, {
521 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
522 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
523 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] : x > y }",
524 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] : x > y }" },
525 { "{ [A[i] -> B[i + 1]] -> [i + 2] }",
526 "{ [B[i] -> A[i - 1]] -> [i + 1] }" },
529 C(&isl::pw_multi_aff::domain_reverse, {
530 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }",
531 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }" },
532 { "{ [A[i] -> B[i + 1]] -> T[0, i + 2] }",
533 "{ [B[i] -> A[i - 1]] -> T[0, i + 1] }" },
536 C(&isl::multi_pw_aff::domain_reverse, {
537 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }",
538 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }" },
541 C(&isl::map::domain_reverse, {
542 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
543 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
544 { "{ N[B[] -> C[]] -> A[] }",
545 "{ [C[] -> B[]] -> A[] }" },
546 { "{ N[B[x] -> B[y]] -> A[] }",
547 "{ N[B[*] -> B[*]] -> A[] }" },
550 C(&isl::union_map::domain_reverse, {
551 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
552 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
553 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
554 "{ }" },
555 { "{ N[B[] -> C[]] -> A[] }",
556 "{ [C[] -> B[]] -> A[] }" },
557 { "{ N[B[x] -> B[y]] -> A[] }",
558 "{ N[B[*] -> B[*]] -> A[] }" },
561 C(&isl::union_map::range_reverse, {
562 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
563 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
564 { "{ A[] -> N[B[] -> C[]] }",
565 "{ A[] -> [C[] -> B[]] }" },
566 { "{ A[] -> N[B[x] -> B[y]] }",
567 "{ A[] -> N[B[*] -> B[*]] }" },
571 /* Perform some basic scaling tests.
573 static void test_scale(isl::ctx ctx)
575 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale), {
576 { "{ A[a] -> B[a, a + 1, a - 1] : a >= 0 }", "{ B[2, 7, 0] }",
577 "{ A[a] -> B[2a, 7a + 7, 0] : a >= 0 }" },
579 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale), {
580 { "{ A[a] -> B[1, a - 1] : a >= 0 }", "{ B[1/2, 7] }",
581 "{ A[a] -> B[1/2, 7a - 7] : a >= 0 }" },
584 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale_down), {
585 { "{ A[a] -> B[a, a + 1] : a >= 0 }", "{ B[2, 7] }",
586 "{ A[a] -> B[a/2, (a + 1)/7] : a >= 0 }" },
588 C(arg<isl::multi_val>(&isl::pw_multi_aff::scale_down), {
589 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[2, 1/7] }",
590 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
594 /* Perform some basic isl::id_to_id tests.
596 static void test_id_to_id(isl::ctx ctx)
598 C((arg<isl::id, isl::id>(&isl::id_to_id::set)), {
599 { "{ }", "a", "b",
600 "{ a: b }" },
601 { "{ a: b }", "a", "b",
602 "{ a: b }" },
603 { "{ a: c }", "a", "b",
604 "{ a: b }" },
605 { "{ a: b }", "b", "a",
606 "{ a: b, b: a }" },
607 { "{ a: b }", "b", "a",
608 "{ b: a, a: b }" },
612 /* The list of tests to perform.
614 static std::vector<std::pair<const char *, void (*)(isl::ctx)>> tests =
616 { "space", &test_space },
617 { "conversion", &test_conversion },
618 { "preimage", &test_preimage },
619 { "fixed power", &test_fixed_power },
620 { "intersect", &test_intersect },
621 { "gist", &test_gist },
622 { "project out parameters", &test_project },
623 { "reverse", &test_reverse },
624 { "scale", &test_scale },
625 { "id-to-id", &test_id_to_id },
628 /* Perform some basic checks by means of the C++ bindings.
630 int main(int argc, char **argv)
632 int ret = EXIT_SUCCESS;
633 struct isl_ctx *ctx;
634 struct isl_options *options;
636 options = isl_options_new_with_defaults();
637 assert(options);
638 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
639 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
641 try {
642 for (const auto &f : tests) {
643 std::cout << f.first << "\n";
644 f.second(ctx);
646 } catch (const isl::exception &e) {
647 std::cerr << e.what() << "\n";
648 ret = EXIT_FAILURE;
651 isl_ctx_free(ctx);
652 return ret;