#include <limits.h>
#include <isl_ctx_private.h>
#include <isl_map_private.h>
+#include <isl/aff.h>
#include <isl/set.h>
#include <isl/flow.h>
#include <isl/constraint.h>
void test_div(struct isl_ctx *ctx)
{
isl_int v;
- int pos;
struct isl_dim *dim;
- struct isl_div *div;
struct isl_basic_set *bset;
struct isl_constraint *c;
isl_int_init(v);
/* test 1 */
- dim = isl_dim_set_alloc(ctx, 0, 1);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, 1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
+
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
/* test 2 */
- dim = isl_dim_set_alloc(ctx, 0, 1);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, 1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
+
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
/* test 3 */
- dim = isl_dim_set_alloc(ctx, 0, 1);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, 1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 4);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
+
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
/* test 4 */
- dim = isl_dim_set_alloc(ctx, 0, 1);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
isl_int_set_si(v, 1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 6);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
+
assert(isl_basic_set_is_empty(bset));
isl_basic_set_free(bset);
/* test 5 */
- dim = isl_dim_set_alloc(ctx, 0, 2);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
+
assert(bset && bset->n_div == 0);
isl_basic_set_free(bset);
/* test 6 */
- dim = isl_dim_set_alloc(ctx, 0, 2);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 6);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
+
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
* and we end up with the original equality and div again.
* Perhaps we can avoid the introduction of this temporary div.
*/
- dim = isl_dim_set_alloc(ctx, 0, 3);
+ dim = isl_dim_set_alloc(ctx, 0, 4);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
isl_int_set_si(v, -3);
isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 6);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
+
/* Test disabled for now */
/*
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
/* test 8 */
- dim = isl_dim_set_alloc(ctx, 0, 4);
+ dim = isl_dim_set_alloc(ctx, 0, 5);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
isl_int_set_si(v, -3);
isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 6);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_constant(c, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
+
/* Test disabled for now */
/*
assert(bset && bset->n_div == 1);
isl_basic_set_free(bset);
/* test 9 */
- dim = isl_dim_set_alloc(ctx, 0, 2);
+ dim = isl_dim_set_alloc(ctx, 0, 4);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, -2);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_int_set_si(v, -1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, 3);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
isl_int_set_si(v, 2);
isl_constraint_set_constant(c, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
+
bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
assert(!isl_basic_set_is_empty(bset));
isl_basic_set_free(bset);
/* test 10 */
- dim = isl_dim_set_alloc(ctx, 0, 2);
+ dim = isl_dim_set_alloc(ctx, 0, 3);
bset = isl_basic_set_universe(dim);
c = isl_equality_alloc(isl_basic_set_get_dim(bset));
isl_int_set_si(v, 1);
isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
- div = isl_div_alloc(isl_basic_set_get_dim(bset));
- c = isl_constraint_add_div(c, div, &pos);
isl_int_set_si(v, -2);
- isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+ isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
bset = isl_basic_set_add_constraint(bset, c);
+ bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
+
bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
isl_basic_set_free(bset);
assert(isl_pw_qpolynomial_is_zero(pwqp1));
isl_pw_qpolynomial_free(pwqp1);
+
+ str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
+ pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+ pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
+ 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)
is_tilable = 1;
is_parallel = 1;
is_nonneg = 1;
+ isl_union_set_free(delta);
} else {
- delta_set = isl_union_set_copy_set(delta);
+ delta_set = isl_set_from_union_set(delta);
slice = isl_set_universe(isl_set_get_dim(delta_set));
for (i = 0; i < tilable; ++i)
isl_set_free(origin);
isl_set_free(delta_set);
}
- isl_union_set_free(delta);
if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
is_injection < 0 || is_complete < 0)
return 0;
}
+int test_aff(isl_ctx *ctx)
+{
+ const char *str;
+ isl_set *set;
+ isl_dim *dim;
+ isl_local_space *ls;
+ isl_aff *aff;
+ int zero;
+
+ dim = isl_dim_set_alloc(ctx, 0, 1);
+ ls = isl_local_space_from_dim(dim);
+ aff = isl_aff_zero(ls);
+
+ aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+ aff = isl_aff_scale_down_ui(aff, 3);
+ aff = isl_aff_floor(aff);
+ aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+ aff = isl_aff_scale_down_ui(aff, 2);
+ aff = isl_aff_floor(aff);
+ aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+
+ str = "{ [10] }";
+ set = isl_set_read_from_str(ctx, str, 0);
+ aff = isl_aff_gist(aff, set);
+
+ aff = isl_aff_add_constant_si(aff, -16);
+ zero = isl_aff_plain_is_zero(aff);
+ isl_aff_free(aff);
+
+ if (zero < 0)
+ return -1;
+ if (!zero)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ return 0;
+}
+
+int test_dim_max(isl_ctx *ctx)
+{
+ int equal;
+ const char *str;
+ isl_map *map, *map2;
+ isl_set *set;
+ isl_pw_aff *pwaff;
+
+ str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
+ set = isl_set_read_from_str(ctx, str, -1);
+ pwaff = isl_set_dim_max(set, 0);
+ map = isl_map_from_pw_aff(pwaff);
+ str = "[N] -> { [] -> [10] : N >= 10; [] -> [N] : N <= 9 and N >= 0 }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ equal = isl_map_is_equal(map, map2);
+ isl_map_free(map);
+ isl_map_free(map2);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
+ set = isl_set_read_from_str(ctx, str, -1);
+ pwaff = isl_set_dim_max(set, 0);
+ map = isl_map_from_pw_aff(pwaff);
+ str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ equal = isl_map_is_equal(map, map2);
+ isl_map_free(map);
+ isl_map_free(map2);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
+ set = isl_set_read_from_str(ctx, str, -1);
+ pwaff = isl_set_dim_max(set, 0);
+ map = isl_map_from_pw_aff(pwaff);
+ str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ equal = isl_map_is_equal(map, map2);
+ isl_map_free(map);
+ isl_map_free(map2);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
+ "0 <= i < N and 0 <= j < M }";
+ map = isl_map_read_from_str(ctx, str, -1);
+ set = isl_map_range(map);
+
+ pwaff = isl_set_dim_max(isl_set_copy(set), 0);
+ map = isl_map_from_pw_aff(pwaff);
+ str = "[N,M] -> { [] -> [([(N-1)/16])] : M,N > 0 }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ equal = isl_map_is_equal(map, map2);
+ isl_map_free(map);
+ isl_map_free(map2);
+
+ pwaff = isl_set_dim_max(isl_set_copy(set), 3);
+ map = isl_map_from_pw_aff(pwaff);
+ str = "[N,M] -> { [] -> [t] : t = min(M-1,15) and M,N > 0 }";
+ map2 = isl_map_read_from_str(ctx, str, -1);
+ if (equal >= 0 && equal)
+ equal = isl_map_is_equal(map, map2);
+ isl_map_free(map);
+ isl_map_free(map2);
+
+ isl_set_free(set);
+
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ return 0;
+}
+
int main()
{
struct isl_ctx *ctx;
assert(srcdir);
ctx = isl_ctx_alloc();
+ if (test_dim_max(ctx) < 0)
+ goto error;
+ if (test_aff(ctx) < 0)
+ goto error;
if (test_injective(ctx) < 0)
goto error;
if (test_schedule(ctx) < 0)