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
27 #include <type_traits>
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
)
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
)
67 /* A description of the input and the output of a unary operation.
74 /* A description of the inputs and the output of a binary operation.
82 /* A description of the inputs and the output of a ternary operation.
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
))
132 ss
<< name
<< "(" << test
.arg
<< ") =\n"
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
))
158 ss
<< name
<< "(" << test
.arg1
<< ", " << test
.arg2
<< ") =\n"
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
))
185 ss
<< name
<< "(" << test
.arg1
<< ", " << test
.arg2
<< ", "
186 << test
.arg3
<< ") =\n"
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 static void test_conversion(isl::ctx ctx
)
223 C(&isl::set::as_pw_multi_aff
, {
224 { "[N=0:] -> { [] }",
225 "[N=0:] -> { [] }" },
228 C(&isl::multi_pw_aff::as_set
, {
229 { "[n] -> { [] : n >= 0 } ",
230 "[n] -> { [] : n >= 0 } " },
234 /* Perform some basic preimage tests.
236 static void test_preimage(isl::ctx ctx
)
238 C(arg
<isl::multi_aff
>(&isl::set::preimage
), {
239 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
240 "{ A[j,i] -> B[i,j] }",
241 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
242 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
243 "{ A[a,b] -> B[a/2,b/6] }",
244 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
245 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
246 "{ A[a,b] -> B[a/2,b/6] }",
247 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
248 "exists i,j : a = 2 i and b = 6 j }" },
249 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
250 "[n] -> { : 0 <= n <= 100 }" },
251 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
253 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
254 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
255 "{ A[a] -> B[([a/2])] }",
256 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
257 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
258 "{ A[a] -> B[a,a,a/3] }",
259 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
260 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
261 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
264 C(arg
<isl::pw_multi_aff
>(&isl::set::preimage
), {
265 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
266 "{ A[j,i] -> B[i,j] : false }",
267 "{ A[j,i] : false }" },
270 C(arg
<isl::multi_aff
>(&isl::union_map::preimage_domain
), {
271 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
272 "{ A[j,i] -> B[i,j] }",
273 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
274 { "{ B[i] -> C[i]; D[i] -> E[i] }",
275 "{ A[i] -> B[i + 1] }",
276 "{ A[i] -> C[i + 1] }" },
277 { "{ B[i] -> C[i]; B[i] -> E[i] }",
278 "{ A[i] -> B[i + 1] }",
279 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
280 { "{ B[i] -> C[([i/2])] }",
282 "{ A[i] -> C[i] }" },
283 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
284 "{ A[i] -> B[([i/5]), ([i/7])] }",
285 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
286 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
287 "[N] -> { A[] -> B[([N/5])] }",
288 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
289 { "{ B[i] -> C[i] : exists a : i = 5 a }",
291 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
292 { "{ B[i] -> C[i] : exists a : i = 2 a; "
293 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
295 "{ A[i] -> C[2i] }" },
296 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
297 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
300 C(arg
<isl::multi_aff
>(&isl::union_map::preimage_range
), {
301 { "[M] -> { A[a] -> B[a] }", "[M] -> { C[] -> B[floor(M/2)] }",
302 "[M] -> { A[floor(M/2)] -> C[] }" },
306 /* Perform some basic fixed power tests.
308 static void test_fixed_power(isl::ctx ctx
)
310 C(arg
<isl::val
>(&isl::map::fixed_power
), {
311 { "{ [i] -> [i + 1] }", "23",
312 "{ [i] -> [i + 23] }" },
313 { "{ [a = 0:1, b = 0:15, c = 0:1, d = 0:1, 0] -> [a, b, c, d, 1]; "
314 "[a = 0:1, b = 0:15, c = 0:1, 0, 1] -> [a, b, c, 1, 0]; "
315 "[a = 0:1, b = 0:15, 0, 1, 1] -> [a, b, 1, 0, 0]; "
316 "[a = 0:1, b = 0:14, 1, 1, 1] -> [a, 1 + b, 0, 0, 0]; "
317 "[0, 15, 1, 1, 1] -> [1, 0, 0, 0, 0] }",
319 "{ [0, b = 0:15, c = 0:1, d = 0:1, e = 0:1] -> [1, b, c, d, e] }" },
323 /* Perform some basic intersection tests.
325 static void test_intersect(isl::ctx ctx
)
327 C(&isl::union_map::intersect_domain_wrapped_domain
, {
328 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
330 "{ [A[0] -> B[y]] -> C[z] }" },
331 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
334 { "{ T[A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
336 "{ T[A[0] -> B[y]] -> C[z] }" },
339 C(&isl::union_map::intersect_range_wrapped_domain
, {
340 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
343 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
345 "{ C[z] -> [A[0] -> B[y]] }" },
346 { "{ C[z] -> T[A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
348 "{ C[z] -> T[A[0] -> B[y]] }" },
352 /* Perform some basic gist tests.
354 static void test_gist(isl::ctx ctx
)
356 C(arg
<isl::set
>(&isl::pw_aff::gist
), {
357 { "{ [x] -> [x] : x != 0 }", "{ [x] : x < -1 or x > 1 }",
361 C(&isl::pw_aff::gist_params
, {
362 { "[N] -> { D[x] -> [x] : N >= 0; D[x] -> [0] : N < 0 }",
363 "[N] -> { : N >= 0 }",
364 "[N] -> { D[x] -> [x] }" },
367 C(arg
<isl::set
>(&isl::multi_aff::gist
), {
368 { "{ A[i] -> B[i, i] }", "{ A[0] }",
369 "{ A[i] -> B[0, 0] }" },
370 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { A[0] : N = 5 }",
371 "[N] -> { A[i] -> B[0, 5] }" },
372 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
373 "[N] -> { B[6, 5] }" },
374 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
375 "[N] -> { A[i] -> B[] }" },
376 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
380 C(&isl::multi_aff::gist_params
, {
381 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { : N = 5 }",
382 "[N] -> { A[i] -> B[i, 5] }" },
383 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
384 "[N] -> { B[6, 5] }" },
385 { "[N] -> { A[i] -> B[] }", "[N] -> { : N = 5 }",
386 "[N] -> { A[i] -> B[] }" },
387 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
391 C(arg
<isl::set
>(&isl::multi_pw_aff::gist
), {
392 { "{ A[i] -> B[i, i] : i >= 0 }", "{ A[0] }",
393 "{ A[i] -> B[0, 0] }" },
394 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
395 "[N] -> { A[i] -> B[0, 5] }" },
396 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
397 "[N] -> { B[6, 5] }" },
398 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
399 "[N] -> { A[i] -> B[] }" },
400 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
402 { "{ A[i=0:10] -> B[i] }", "{ A[5] }",
403 "{ A[i] -> B[5] }" },
404 { "{ A[0:10] -> B[] }", "{ A[0:10] }",
406 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
407 "[N] -> { A[i] -> B[] }" },
408 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
410 { "[N] -> { B[] : N = 5 }", "[N] -> { : N >= 0 }",
411 "[N] -> { B[] : N = 5 }" },
414 C(&isl::multi_pw_aff::gist_params
, {
415 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { : N = 5 }",
416 "[N] -> { A[i] -> B[i, 5] }" },
417 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
418 "[N] -> { B[6, 5] }" },
419 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { : N = 5 }",
420 "[N] -> { A[i] -> B[] }" },
421 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
423 { "[N] -> { B[] : N >= 5 }", "[N] -> { : N >= 0 }",
424 "[N] -> { B[] : N >= 5 }" },
427 C(&isl::multi_union_pw_aff::gist
, {
428 { "C[{ B[i,i] -> [3i] }]", "{ B[i,i] }",
429 "C[{ B[i,j] -> [3i] }]" },
430 { "(C[] : { B[i,i] })", "{ B[i,i] }",
431 "(C[] : { B[i,j] })" },
432 { "[N] -> (C[] : { B[N,N] })", "[N] -> { B[N,N] }",
433 "[N] -> (C[] : { B[i,j] })" },
434 { "C[]", "{ B[i,i] }",
436 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "{ B[i,i] }",
437 "[N] -> (C[] : { B[i,j] : N >= 0 })" },
438 { "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
439 "[N] -> (C[] : { : N >= 0 })" },
440 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { B[i,i] : N >= 0 }",
444 C(&isl::multi_union_pw_aff::gist_params
, {
445 { "[N] -> C[{ B[i,i] -> [3i + N] }]", "[N] -> { : N = 1 }",
446 "[N] -> C[{ B[i,i] -> [3i + 1] }]" },
447 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
448 "[N] -> C[{ B[i,i] -> [3i] }]" },
449 { "[N] -> C[{ B[i,i] -> [3i] : N >= 0 }]", "[N] -> { : N >= 0 }",
450 "[N] -> C[{ B[i,i] -> [3i] }]" },
451 { "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]", "[N] -> { : N >= 0 }",
452 "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]" },
453 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "[N] -> { : N >= 0 }",
454 "[N] -> (C[] : { B[i,i] })" },
455 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { : N >= 0 }",
457 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
458 "[N] -> C[{ B[i,i] -> [3i] }]" },
462 /* Perform tests that project out parameters.
464 static void test_project(isl::ctx ctx
)
466 C(arg
<isl::id
>(&isl::union_map::project_out_param
), {
467 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "N",
468 "{ D[i] -> A[0:]; D[i] -> B[i] }" },
469 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "M",
470 "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }" },
473 C(arg
<isl::id_list
>(&isl::union_map::project_out_param
), {
474 { "[M, N, O] -> { D[i] -> A[j] : i <= j < M, N, O }", "(M, N)",
475 "[O] -> { D[i] -> A[j] : i <= j < O }" },
479 /* Perform some basic reverse tests.
481 static void test_reverse(isl::ctx ctx
)
483 C(&isl::aff::domain_reverse
, {
484 { "{ T[A[] -> B[*]] -> [0] }",
485 "{ [B[*] -> A[]] -> [0] }" },
486 { "{ T[A[] -> A[]] -> [0] }",
487 "{ T[A[] -> A[]] -> [0] }" },
488 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
489 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
492 C(&isl::multi_aff::domain_reverse
, {
493 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
494 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
495 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] }",
496 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] }" },
499 C(&isl::set::wrapped_reverse
, {
500 { "{ T[A[] -> B[*]] }",
501 "{ [B[*] -> A[]] }" },
502 { "{ T[A[] -> A[]] }",
503 "{ T[A[] -> A[]] }" },
504 { "{ [A[x] -> B[2x]] }",
505 "{ [B[y] -> A[x]] : y = 2x }" },
508 C(&isl::pw_aff::domain_reverse
, {
509 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
510 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
511 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] : x > y }",
512 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] : x > y }" },
513 { "{ [A[i] -> B[i + 1]] -> [i + 2] }",
514 "{ [B[i] -> A[i - 1]] -> [i + 1] }" },
517 C(&isl::pw_multi_aff::domain_reverse
, {
518 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }",
519 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }" },
520 { "{ [A[i] -> B[i + 1]] -> T[0, i + 2] }",
521 "{ [B[i] -> A[i - 1]] -> T[0, i + 1] }" },
524 C(&isl::multi_pw_aff::domain_reverse
, {
525 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }",
526 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }" },
529 C(&isl::map::domain_reverse
, {
530 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
531 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
532 { "{ N[B[] -> C[]] -> A[] }",
533 "{ [C[] -> B[]] -> A[] }" },
534 { "{ N[B[x] -> B[y]] -> A[] }",
535 "{ N[B[*] -> B[*]] -> A[] }" },
538 C(&isl::union_map::domain_reverse
, {
539 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
540 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
541 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
543 { "{ N[B[] -> C[]] -> A[] }",
544 "{ [C[] -> B[]] -> A[] }" },
545 { "{ N[B[x] -> B[y]] -> A[] }",
546 "{ N[B[*] -> B[*]] -> A[] }" },
549 C(&isl::union_map::range_reverse
, {
550 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
551 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
552 { "{ A[] -> N[B[] -> C[]] }",
553 "{ A[] -> [C[] -> B[]] }" },
554 { "{ A[] -> N[B[x] -> B[y]] }",
555 "{ A[] -> N[B[*] -> B[*]] }" },
559 /* Perform some basic scaling tests.
561 static void test_scale(isl::ctx ctx
)
563 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale
), {
564 { "{ A[a] -> B[a, a + 1, a - 1] : a >= 0 }", "{ B[2, 7, 0] }",
565 "{ A[a] -> B[2a, 7a + 7, 0] : a >= 0 }" },
567 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale
), {
568 { "{ A[a] -> B[1, a - 1] : a >= 0 }", "{ B[1/2, 7] }",
569 "{ A[a] -> B[1/2, 7a - 7] : a >= 0 }" },
572 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale_down
), {
573 { "{ A[a] -> B[a, a + 1] : a >= 0 }", "{ B[2, 7] }",
574 "{ A[a] -> B[a/2, (a + 1)/7] : a >= 0 }" },
576 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale_down
), {
577 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[2, 1/7] }",
578 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
582 /* Perform some basic isl::id_to_id tests.
584 static void test_id_to_id(isl::ctx ctx
)
586 C((arg
<isl::id
, isl::id
>(&isl::id_to_id::set
)), {
589 { "{ a: b }", "a", "b",
591 { "{ a: c }", "a", "b",
593 { "{ a: b }", "b", "a",
595 { "{ a: b }", "b", "a",
600 /* The list of tests to perform.
602 static std::vector
<std::pair
<const char *, void (*)(isl::ctx
)>> tests
=
604 { "space", &test_space
},
605 { "conversion", &test_conversion
},
606 { "preimage", &test_preimage
},
607 { "fixed power", &test_fixed_power
},
608 { "intersect", &test_intersect
},
609 { "gist", &test_gist
},
610 { "project out parameters", &test_project
},
611 { "reverse", &test_reverse
},
612 { "scale", &test_scale
},
613 { "id-to-id", &test_id_to_id
},
616 /* Perform some basic checks by means of the C++ bindings.
618 int main(int argc
, char **argv
)
620 int ret
= EXIT_SUCCESS
;
622 struct isl_options
*options
;
624 options
= isl_options_new_with_defaults();
626 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
627 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
630 for (const auto &f
: tests
) {
631 std::cout
<< f
.first
<< "\n";
634 } catch (const isl::exception
&e
) {
635 std::cerr
<< e
.what() << "\n";