14 /* A binary isl function that appears in the C++ bindings
15 * as a unary method in a class T, taking an extra argument
16 * of type A1 and returning an object of type R.
18 template <typename A1
, typename R
, typename T
>
19 using binary_fn
= R (T::*)(A1
) const;
21 /* A function for selecting an overload of a pointer to a unary C++ method
22 * based on the single argument type.
23 * The object type and the return type are meant to be deduced.
25 template <typename A1
, typename R
, typename T
>
26 static binary_fn
<A1
, R
, T
> const arg(const binary_fn
<A1
, R
, T
> &fn
)
31 /* A description of the input and the output of a unary operation.
38 /* A description of the inputs and the output of a binary operation.
46 /* A template function for checking whether two objects
47 * of the same (isl) type are (obviously) equal.
48 * The spelling depends on the isl type and
49 * in particular on whether an equality method is available or
50 * whether only obvious equality can be tested.
52 template <typename T
, typename
std::decay
<decltype(
53 std::declval
<T
>().is_equal(std::declval
<T
>()))>::type
= true>
54 static bool is_equal(const T
&a
, const T
&b
)
58 template <typename T
, typename
std::decay
<decltype(
59 std::declval
<T
>().plain_is_equal(std::declval
<T
>()))>::type
= true>
60 static bool is_equal(const T
&a
, const T
&b
)
62 return a
.plain_is_equal(b
);
65 /* A helper macro for throwing an isl::exception_invalid with message "msg".
67 #define THROW_INVALID(msg) \
68 isl::exception::throw_error(isl_error_invalid, msg, __FILE__, __LINE__)
70 /* Run a sequence of tests of method "fn" with stringification "name" and
71 * with input and output described by "test",
72 * throwing an exception when an unexpected result is produced.
74 template <typename R
, typename T
>
75 static void test(isl::ctx ctx
, R (T::*fn
)() const, const std::string
&name
,
76 const std::vector
<unary
> &tests
)
78 for (const auto &test
: tests
) {
80 R
expected(ctx
, test
.res
);
81 const auto &res
= (obj
.*fn
)();
82 std::ostringstream ss
;
84 if (is_equal(expected
, res
))
87 ss
<< name
<< "(" << test
.arg
<< ") =\n"
91 THROW_INVALID(ss
.str().c_str());
95 /* Run a sequence of tests of method "fn" with stringification "name" and
96 * with inputs and output described by "test",
97 * throwing an exception when an unexpected result is produced.
99 template <typename R
, typename T
, typename A1
>
100 static void test(isl::ctx ctx
, R (T::*fn
)(A1
) const, const std::string
&name
,
101 const std::vector
<binary
> &tests
)
103 for (const auto &test
: tests
) {
104 T
obj(ctx
, test
.arg1
);
105 A1
arg1(ctx
, test
.arg2
);
106 R
expected(ctx
, test
.res
);
107 const auto &res
= (obj
.*fn
)(arg1
);
108 std::ostringstream ss
;
110 if (is_equal(expected
, res
))
113 ss
<< name
<< "(" << test
.arg1
<< ", " << test
.arg2
<< ") =\n"
117 THROW_INVALID(ss
.str().c_str());
121 /* A helper macro that calls test with as implicit initial argument "ctx" and
122 * as extra argument a stringification of "FN".
124 #define C(FN, ...) test(ctx, FN, #FN, __VA_ARGS__)
126 /* Perform some basic isl::space tests.
128 static void test_space(isl::ctx ctx
)
130 C(&isl::space::domain
, {
131 { "{ A[] -> B[] }", "{ A[] }" },
132 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ A[C[] -> D[]] }" },
135 C(&isl::space::range
, {
136 { "{ A[] -> B[] }", "{ B[] }" },
137 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ B[E[] -> F[]] }" },
140 C(&isl::space::params
, {
141 { "{ A[] -> B[] }", "{ : }" },
142 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ : }" },
146 /* Perform some basic preimage tests.
148 static void test_preimage(isl::ctx ctx
)
150 C(arg
<isl::multi_aff
>(&isl::set::preimage
), {
151 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
152 "{ A[j,i] -> B[i,j] }",
153 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
154 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
155 "{ A[a,b] -> B[a/2,b/6] }",
156 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
157 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
158 "{ A[a,b] -> B[a/2,b/6] }",
159 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
160 "exists i,j : a = 2 i and b = 6 j }" },
161 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
162 "[n] -> { : 0 <= n <= 100 }" },
163 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
165 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
166 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
167 "{ A[a] -> B[([a/2])] }",
168 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
169 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
170 "{ A[a] -> B[a,a,a/3] }",
171 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
172 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
173 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
176 C(arg
<isl::multi_aff
>(&isl::union_map::preimage_domain
), {
177 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
178 "{ A[j,i] -> B[i,j] }",
179 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
180 { "{ B[i] -> C[i]; D[i] -> E[i] }",
181 "{ A[i] -> B[i + 1] }",
182 "{ A[i] -> C[i + 1] }" },
183 { "{ B[i] -> C[i]; B[i] -> E[i] }",
184 "{ A[i] -> B[i + 1] }",
185 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
186 { "{ B[i] -> C[([i/2])] }",
188 "{ A[i] -> C[i] }" },
189 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
190 "{ A[i] -> B[([i/5]), ([i/7])] }",
191 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
192 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
193 "[N] -> { A[] -> B[([N/5])] }",
194 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
195 { "{ B[i] -> C[i] : exists a : i = 5 a }",
197 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
198 { "{ B[i] -> C[i] : exists a : i = 2 a; "
199 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
201 "{ A[i] -> C[2i] }" },
202 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
203 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
206 C(arg
<isl::multi_aff
>(&isl::union_map::preimage_range
), {
207 { "[M] -> { A[a] -> B[a] }", "[M] -> { C[] -> B[floor(M/2)] }",
208 "[M] -> { A[floor(M/2)] -> C[] }" },
212 /* Perform some basic intersection tests.
214 static void test_intersect(isl::ctx ctx
)
216 C(&isl::union_map::intersect_domain_wrapped_domain
, {
217 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
219 "{ [A[0] -> B[y]] -> C[z] }" },
220 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
225 C(&isl::union_map::intersect_range_wrapped_domain
, {
226 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
229 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
231 "{ C[z] -> [A[0] -> B[y]] }" },
235 /* Perform some basic gist tests.
237 static void test_gist(isl::ctx ctx
)
239 C(&isl::pw_aff::gist_params
, {
240 { "[N] -> { D[x] -> [x] : N >= 0; D[x] -> [0] : N < 0 }",
241 "[N] -> { : N >= 0 }",
242 "[N] -> { D[x] -> [x] }" },
246 /* Perform some basic scaling tests.
248 static void test_scale(isl::ctx ctx
)
250 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale
), {
251 { "{ A[a] -> B[a, a + 1, a - 1] : a >= 0 }", "{ B[2, 7, 0] }",
252 "{ A[a] -> B[2a, 7a + 7, 0] : a >= 0 }" },
254 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale
), {
255 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[1/2, 7] }",
256 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
259 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale_down
), {
260 { "{ A[a] -> B[a, a + 1] : a >= 0 }", "{ B[2, 7] }",
261 "{ A[a] -> B[a/2, (a + 1)/7] : a >= 0 }" },
263 C(arg
<isl::multi_val
>(&isl::pw_multi_aff::scale_down
), {
264 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[2, 1/7] }",
265 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
269 /* The list of tests to perform.
271 static std::vector
<std::pair
<const char *, void (*)(isl::ctx
)>> tests
=
273 { "space", &test_space
},
274 { "preimage", &test_preimage
},
275 { "intersect", &test_intersect
},
276 { "gist", &test_gist
},
277 { "scale", &test_scale
},
280 /* Perform some basic checks by means of the C++ bindings.
282 int main(int argc
, char **argv
)
284 int ret
= EXIT_SUCCESS
;
286 struct isl_options
*options
;
288 options
= isl_options_new_with_defaults();
290 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
291 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
294 for (const auto &f
: tests
) {
295 std::cout
<< f
.first
<< "\n";
298 } catch (const isl::exception
&e
) {
299 std::cerr
<< e
.what() << "\n";