#include <assert.h>
#include <stdio.h>
#include <limits.h>
-#include <isl_ctx.h>
-#include <isl_set.h>
-#include <isl_flow.h>
-#include <isl_constraint.h>
-#include <isl_polynomial.h>
+#include <isl/ctx.h>
+#include <isl/set.h>
+#include <isl/flow.h>
+#include <isl/constraint.h>
+#include <isl/polynomial.h>
+#include <isl/union_map.h>
+#include <isl_map_private.h>
static char *srcdir;
isl_map_free(map);
}
+void test_parse_pwqp(isl_ctx *ctx, const char *str)
+{
+ isl_pw_qpolynomial *pwqp;
+
+ pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
+ assert(pwqp);
+ isl_pw_qpolynomial_free(pwqp);
+}
+
void test_parse(struct isl_ctx *ctx)
{
- isl_map *map;
+ isl_map *map, *map2;
const char *str;
str = "{ [i] -> [-i] }";
isl_map_free(map);
test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
+
+ str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
+ map = isl_map_read_from_str(ctx, str, -1);
+ str = "{ [new, old] -> [o0, o1] : "
+ "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
+ "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
+ "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ assert(isl_map_is_equal(map, map2));
+ isl_map_free(map);
+ isl_map_free(map2);
+
+ test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
}
void test_read(struct isl_ctx *ctx)
void test_pwqp(struct isl_ctx *ctx)
{
const char *str;
+ isl_set *set;
isl_pw_qpolynomial *pwqp1, *pwqp2;
str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
assert(isl_pw_qpolynomial_is_zero(pwqp1));
isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [i] -> i }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ str = "{ [k] : exists a : k = 2a }";
+ set = isl_set_read_from_str(ctx, str, 0);
+ pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
+ str = "{ [i] -> i }";
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+ pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+ assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+ isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ str = "{ [10] }";
+ set = isl_set_read_from_str(ctx, str, 0);
+ pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
+ str = "{ [i] -> 16 }";
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+ pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+ assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+ isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [i] -> ([(i)/2]) }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ str = "{ [k] : exists a : k = 2a+1 }";
+ set = isl_set_read_from_str(ctx, str, 0);
+ pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
+ str = "{ [i] -> -1/2 + 1/2 * i }";
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+ pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+ assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+ isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ str = "{ [i] -> ([(2 * [i/2])/5]) }";
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+ pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+ assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+ isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ str = "{ [x] -> x }";
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+ pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+ assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+ isl_pw_qpolynomial_free(pwqp1);
}
void test_split_periods(isl_ctx *ctx)
isl_pw_qpolynomial_free(pwqp);
}
+void test_union(isl_ctx *ctx)
+{
+ const char *str;
+ isl_union_set *uset1, *uset2;
+ isl_union_map *umap1, *umap2;
+
+ str = "{ [i] : 0 <= i <= 1 }";
+ uset1 = isl_union_set_read_from_str(ctx, str);
+ str = "{ [1] -> [0] }";
+ umap1 = isl_union_map_read_from_str(ctx, str);
+
+ umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
+ assert(isl_union_map_is_equal(umap1, umap2));
+
+ isl_union_map_free(umap1);
+ isl_union_map_free(umap2);
+
+ str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
+ umap1 = isl_union_map_read_from_str(ctx, str);
+ str = "{ A[i]; B[i] }";
+ uset1 = isl_union_set_read_from_str(ctx, str);
+
+ uset2 = isl_union_map_domain(umap1);
+
+ assert(isl_union_set_is_equal(uset1, uset2));
+
+ isl_union_set_free(uset1);
+ isl_union_set_free(uset2);
+}
+
+void test_bound(isl_ctx *ctx)
+{
+ const char *str;
+ isl_pw_qpolynomial *pwqp;
+ isl_pw_qpolynomial_fold *pwf;
+
+ str = "{ [[a, b, c, d] -> [e]] -> 0 }";
+ pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
+ pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
+ assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
+ isl_pw_qpolynomial_fold_free(pwf);
+}
+
+void test_lift(isl_ctx *ctx)
+{
+ const char *str;
+ isl_basic_map *bmap;
+ isl_basic_set *bset;
+
+ str = "{ [i0] : exists e0 : i0 = 4e0 }";
+ bset = isl_basic_set_read_from_str(ctx, str, 0);
+ bset = isl_basic_set_lift(bset);
+ bmap = isl_basic_map_from_range(bset);
+ bset = isl_basic_map_domain(bmap);
+ isl_basic_set_free(bset);
+}
+
int main()
{
struct isl_ctx *ctx;
assert(srcdir);
ctx = isl_ctx_alloc();
+ test_lift(ctx);
+ test_bound(ctx);
+ test_union(ctx);
test_split_periods(ctx);
test_parse(ctx);
test_pwqp(ctx);