1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
| # Copyright 2016-2017 Tobias Grosser
#
# Use of this software is governed by the MIT license
#
# Written by Tobias Grosser, Weststrasse 47, CH-8003, Zurich
import sys
import isl
# Test that isl objects can be constructed.
#
# This tests:
# - construction from a string
# - construction from an integer
# - static constructor without a parameter
# - conversion construction
#
# The tests to construct from integers and strings cover functionality that
# is also tested in the parameter type tests, but here the presence of
# multiple overloaded constructors and overload resolution is tested.
#
def test_constructors():
zero1 = isl.val("0")
assert(zero1.is_zero())
zero2 = isl.val(0)
assert(zero2.is_zero())
zero3 = isl.val.zero()
assert(zero3.is_zero())
bs = isl.basic_set("{ [1] }")
result = isl.set("{ [1] }")
s = isl.set(bs)
assert(s.is_equal(result))
# Test integer function parameters for a particular integer value.
#
def test_int(i):
val_int = isl.val(i)
val_str = isl.val(str(i))
assert(val_int.eq(val_str))
# Test integer function parameters.
#
# Verify that extreme values and zero work.
#
def test_parameters_int():
test_int(sys.maxsize)
test_int(-sys.maxsize - 1)
test_int(0)
# Test isl objects parameters.
#
# Verify that isl objects can be passed as lvalue and rvalue parameters.
# Also verify that isl object parameters are automatically type converted if
# there is an inheritance relation. Finally, test function calls without
# any additional parameters, apart from the isl object on which
# the method is called.
#
def test_parameters_obj():
a = isl.set("{ [0] }")
b = isl.set("{ [1] }")
c = isl.set("{ [2] }")
expected = isl.set("{ [i] : 0 <= i <= 2 }")
tmp = a.union(b)
res_lvalue_param = tmp.union(c)
assert(res_lvalue_param.is_equal(expected))
res_rvalue_param = a.union(b).union(c)
assert(res_rvalue_param.is_equal(expected))
a2 = isl.basic_set("{ [0] }")
assert(a.is_equal(a2))
two = isl.val(2)
half = isl.val("1/2")
res_only_this_param = two.inv()
assert(res_only_this_param.eq(half))
# Test different kinds of parameters to be passed to functions.
#
# This includes integer and isl object parameters.
#
def test_parameters():
test_parameters_int()
test_parameters_obj()
# Test that isl objects are returned correctly.
#
# This only tests that after combining two objects, the result is successfully
# returned.
#
def test_return_obj():
one = isl.val("1")
two = isl.val("2")
three = isl.val("3")
res = one.add(two)
assert(res.eq(three))
# Test that integer values are returned correctly.
#
def test_return_int():
one = isl.val("1")
neg_one = isl.val("-1")
zero = isl.val("0")
assert(one.sgn() > 0)
assert(neg_one.sgn() < 0)
assert(zero.sgn() == 0)
# Test that isl_bool values are returned correctly.
#
# In particular, check the conversion to bool in case of true and false.
#
def test_return_bool():
empty = isl.set("{ : false }")
univ = isl.set("{ : }")
b_true = empty.is_empty()
b_false = univ.is_empty()
assert(b_true)
assert(not b_false)
# Test that strings are returned correctly.
# Do so by calling overloaded isl.ast_build.from_expr methods.
#
def test_return_string():
context = isl.set("[n] -> { : }")
build = isl.ast_build.from_context(context)
pw_aff = isl.pw_aff("[n] -> { [n] }")
set = isl.set("[n] -> { : n >= 0 }")
expr = build.expr_from(pw_aff)
expected_string = "n"
assert(expected_string == expr.to_C_str())
expr = build.expr_from(set)
expected_string = "n >= 0"
assert(expected_string == expr.to_C_str())
# Test that return values are handled correctly.
#
# Test that isl objects, integers, boolean values, and strings are
# returned correctly.
#
def test_return():
test_return_obj()
test_return_int()
test_return_bool()
test_return_string()
# Test that foreach functions are modeled correctly.
#
# Verify that closures are correctly called as callback of a 'foreach'
# function and that variables captured by the closure work correctly. Also
# check that the foreach function handles exceptions thrown from
# the closure and that it propagates the exception.
#
def test_foreach():
s = isl.set("{ [0]; [1]; [2] }")
list = []
def add(bs):
list.append(bs)
s.foreach_basic_set(add)
assert(len(list) == 3)
assert(list[0].is_subset(s))
assert(list[1].is_subset(s))
assert(list[2].is_subset(s))
assert(not list[0].is_equal(list[1]))
assert(not list[0].is_equal(list[2]))
assert(not list[1].is_equal(list[2]))
def fail(bs):
raise "fail"
caught = False
try:
s.foreach_basic_set(fail)
except:
caught = True
assert(caught)
# Test the isl Python interface
#
# This includes:
# - Object construction
# - Different parameter types
# - Different return types
# - Foreach functions
#
test_constructors()
test_parameters()
test_return()
test_foreach()
|