Ejemplo n.º 1
0
 def test_matrix_update(self):
     mat = self.matrix.update((1, 2), 1)
     self.assertEqual(mat[1, 2], IntegerInterval(1))
     mat = self.matrix.update(([1, 2], 1), 1)
     val = IntegerInterval([1, 9])
     self.assertEqual(mat[1, 1], val)
     self.assertEqual(mat[2, 1], val)
Ejemplo n.º 2
0
 def test_matrix_content(self):
     intervals = [IntegerInterval(v) for v in self.vector_values]
     self.assertListEqual(intervals, list(self.vector))
     x_shape, y_shape = self.matrix.shape
     for x, y in itertools.product(range(x_shape), range(y_shape)):
         val = IntegerInterval(self.matrix_values[x][y])
         self.assertEqual(val, self.matrix[x, y])
Ejemplo n.º 3
0
 def test_MetaState(self):
     meta_state = MetaState({
         self.x: BinaryArithExpr(
             operators.ADD_OP, self.x, IntegerInterval(1)),
         self.y: BinaryArithExpr(
             operators.MULTIPLY_OP, self.x, IntegerInterval(2)),
     })
     test_state = BoxState(x=[2, 3], y=[2, 4])
     state = arith_eval(meta_state, self.state)
     self.assertEqual(test_state, state)
Ejemplo n.º 4
0
 def test_multi_dim_coupled_subscripts_dependence(self):
     """
     for (x in 0...9) { a[x + 1, x + 1] = a[x, x]; }
     """
     expr_1 = expression_factory(
         operators.ADD_OP, self.x, IntegerInterval(1))
     expr_2 = expression_factory(
         operators.ADD_OP, self.x, IntegerInterval(1))
     source = Subscript(expr_1, expr_2)
     sink = Subscript(self.x, self.x)
     dist_vect = dependence_vector([self.x], [self.sx], source, sink)
     self.assertEqual(dist_vect, (1, ))
Ejemplo n.º 5
0
 def test_multi_dim_coupled_subscripts_independence(self):
     """
     for (x in 0...9) { a[x + 1, x + 2] = a[x, x]; }
     """
     expr_1 = expression_factory(
         operators.ADD_OP, self.x, IntegerInterval(1))
     expr_2 = expression_factory(
         operators.ADD_OP, self.x, IntegerInterval(2))
     source = Subscript(expr_1, expr_2)
     sink = Subscript(self.x, self.x)
     self.assertRaises(
         ISLIndependenceException, dependence_vector,
         [self.x], [self.sx], source, sink)
Ejemplo n.º 6
0
 def test_FixExpr(self):
     bool_expr = BinaryBoolExpr(operators.LESS_OP, self.x, self.y)
     loop_state = MetaState({
         self.x: BinaryArithExpr(
             operators.ADD_OP, self.x, IntegerInterval(1)),
         self.y: self.y,
     })
     init_state = MetaState({
         self.x: self.x, self.y: self.y,
     })
     test_expr = FixExpr(bool_expr, loop_state, self.x, init_state)
     test_value = IntegerInterval(3)
     value = arith_eval(test_expr, self.state)
     self.assertEqual(test_value, value)
Ejemplo n.º 7
0
    def test_SelectExpr(self):
        test_expr = SelectExpr(
            BinaryBoolExpr(operators.LESS_OP, self.x, ErrorSemantics(1.5)),
            IntegerInterval(0), self.y)
        test_value = IntegerInterval(0)
        value = arith_eval(test_expr, self.state)
        self.assertEqual(test_value, value)

        test_expr = SelectExpr(
            BinaryBoolExpr(operators.LESS_OP, self.z, ErrorSemantics(1.5)),
            IntegerInterval(0), self.y)
        test_value = IntegerInterval([0, 3])
        value = arith_eval(test_expr, self.state)
        self.assertEqual(test_value, value)
Ejemplo n.º 8
0
 def setUp(self):
     self.context = LabelContext('test_context')
     mat = IntegerIntervalArray([1, 2, 3, 4])
     self.x = Variable('x', int_type)
     self.y = Variable('y', int_type)
     self.z = Variable('z', IntegerArrayType([4]))
     self.state = BoxState({
         self.x: [1, 2],
         self.y: 3,
         self.z: mat,
     })
     self.x_label = self.context.Label(
         self.x, IntegerInterval([1, 2]), None)
     self.y_label = self.context.Label(self.y, IntegerInterval(3), None)
     self.z_label = self.context.Label(self.z, mat, None)
Ejemplo n.º 9
0
 def bool_expr(self):
     expr = BinaryBoolExpr(operators.LESS_OP, self.x, self.y)
     label_expr = BinaryBoolExpr(
         operators.LESS_OP, self.x_label, self.y_label)
     # FIXME bound for bool_expr does not make sense
     label = self.context.Label(expr, IntegerInterval([-2, -1]), None)
     return label, expr, label_expr
Ejemplo n.º 10
0
 def test_simple_independence(self):
     source = Subscript(
         expression_factory(operators.ADD_OP, self.x, IntegerInterval(20)))
     sink = Subscript(self.x)
     self.assertRaises(
         ISLIndependenceException, dependence_vector,
         [self.x], [self.sx], source, sink)
Ejemplo n.º 11
0
 def test_UnaryArithExpr(self):
     expr = UnaryArithExpr(operators.UNARY_SUBTRACT_OP, self.x)
     label_expr = UnaryArithExpr(
         operators.UNARY_SUBTRACT_OP, self.x_label)
     label = self.context.Label(expr, IntegerInterval([-2, -1]), None)
     env = {label: label_expr, self.x_label: self.x}
     test_value = LabelSemantics(label, env)
     self.compare(expr, test_value)
Ejemplo n.º 12
0
 def test_simple_subscripts(self):
     source = Subscript(
         expression_factory(operators.ADD_OP, self.x, IntegerInterval(1)))
     sink = Subscript(self.x)
     dist_vect = dependence_vector([self.x], [self.sx], source, sink)
     self.assertEqual(dist_vect, (1, ))
     dist = dependence_distance(dist_vect, [self.sx])
     self.assertEqual(dist, 1)
Ejemplo n.º 13
0
 def test_join_and_meet(self):
     other_matrix = IntArray([[9, 8, 7], [6, 5, 4], [3, 2, 1]])
     join_test_matrix = IntArray(
         self._list_elements_to_interval([[[1, 9], [2, 8], [3, 7]],
                                          [[4, 8], [5, 9], [4, 9]],
                                          [[3, 9], [2, 9], [1, 9]]]))
     self.assertEqual(self.matrix | other_matrix, join_test_matrix)
     bot = IntegerInterval(bottom=True)
     meet_test_matrix = IntArray([[bot, bot, 7], [6, 5, bot],
                                  [bot, bot, bot]])
     self.assertEqual(self.matrix & other_matrix, meet_test_matrix)
Ejemplo n.º 14
0
 def test_multi_dim_subscripts(self):
     """
     Test case::
         for (x in 0...9) {
             for (y in 1...10) {
                 a[x + 2, y] = ... a[x, y - 1] ...
             }
         }
     """
     expr = expression_factory(operators.ADD_OP, self.x, IntegerInterval(2))
     source = Subscript(expr, self.y)
     expr = expression_factory(
         operators.SUBTRACT_OP, self.y, IntegerInterval(1))
     sink = Subscript(self.x, expr)
     iter_slices = [self.sx, self.sy]
     dist_vect = dependence_vector(
         [self.x, self.y], iter_slices, source, sink)
     self.assertEqual(dist_vect, (2, 1))
     dist = dependence_distance(dist_vect, iter_slices)
     self.assertEqual(dist, 21)
Ejemplo n.º 15
0
 def test_simple_loop(self):
     program = """
     def main(real[30] a) {
         for (int i = 1; i < 10; i = i + 1) {
             a[i] = a[i - 1] + 1;
         }
         return a;
     }
     """
     flow = parse(program)
     meta_state = flow_to_meta_state(flow)
     fix_expr = meta_state[flow.outputs[0]]
     for_loop = ForLoopExtractor(fix_expr)
     expect_for_loop = {
         'iter_var': self.i,
         'start': IntegerInterval(1),
         'stop': IntegerInterval(10),
         'step': IntegerInterval(1),
         'has_inner_loops': False,
     }
     self.compare(for_loop, expect_for_loop)
Ejemplo n.º 16
0
 def test_BinaryArithExpr(self):
     expr = BinaryArithExpr(operators.ADD_OP, self.x, self.y)
     label_expr = BinaryArithExpr(
         operators.ADD_OP, self.x_label, self.y_label)
     label = self.context.Label(expr, IntegerInterval([4, 5]), None)
     env = {
         label: label_expr,
         self.x_label: self.x,
         self.y_label: self.y,
     }
     test_value = LabelSemantics(label, env)
     self.compare(expr, test_value)
Ejemplo n.º 17
0
    def test_FixExpr(self):
        init_state = MetaState({self.x: IntegerInterval(0)})
        init_label, init_env = self.label(init_state)

        invar = BoxState({self.x: IntegerInterval([0, 4])})
        end_invar = BoxState({self.x: IntegerInterval([1, 5])})

        loop_state = MetaState({
            self.x: BinaryArithExpr(
                operators.ADD_OP, self.x, IntegerInterval(1)),
        })
        loop_label, loop_env = self.label(loop_state, invar)

        bool_expr = BinaryBoolExpr(
            operators.LESS_OP, self.x, IntegerInterval(5))
        bool_labsem = self.label(bool_expr, end_invar)
        bool_label, _ = bool_labsem

        expr = FixExpr(bool_expr, loop_state, self.x, init_state)

        bound = IntegerInterval(5)
        label = self.context.Label(expr, bound, invar)
        label_expr = FixExpr(bool_labsem, loop_env, self.x, init_env)
        env = {label: label_expr}
        test_value = LabelSemantics(label, env)
        self.compare(expr, test_value)
Ejemplo n.º 18
0
 def test_SelectExpr(self):
     bool_label, bool_expr, bool_label_expr = self.bool_expr()
     expr = SelectExpr(bool_expr, self.x, self.y)
     label_expr = SelectExpr(bool_label, self.x_label, self.y_label)
     label = self.context.Label(expr, IntegerInterval([1, 2]), None)
     env = {
         label: label_expr,
         bool_label: bool_label_expr,
         self.x_label: self.x,
         self.y_label: self.y,
     }
     test_value = LabelSemantics(label, env)
     self.compare(expr, test_value)
Ejemplo n.º 19
0
 def test_AccessExpr(self):
     subscript = Subscript(self.y)
     expr = AccessExpr(self.z, subscript)
     label_subscript_expr = Subscript(self.y_label)
     subscript_label = self.context.Label(
         subscript, IntegerIntervalArray([self.state[self.y]]), None)
     label_expr = AccessExpr(self.z_label, subscript_label)
     label = self.context.Label(expr, IntegerInterval(4), None)
     env = {
         label: label_expr,
         subscript_label: label_subscript_expr,
         self.y_label: self.y,
         self.z_label: self.z,
     }
     test_value = LabelSemantics(label, env)
     self.compare(expr, test_value)
Ejemplo n.º 20
0
 def test_UpdateExpr(self):
     subscript = Subscript(self.y)
     expr = UpdateExpr(self.z, subscript, self.x)
     label_subscript_expr = Subscript(self.y_label)
     subscript_label = self.context.Label(
         subscript, IntegerIntervalArray([self.state[self.y]]), None)
     label_expr = UpdateExpr(self.z_label, subscript_label, self.x_label)
     new_bound = IntegerIntervalArray([1, 2, 3, IntegerInterval([1, 2])])
     label = self.context.Label(expr, new_bound, None)
     env = {
         label: label_expr,
         subscript_label: label_subscript_expr,
         self.x_label: self.x,
         self.y_label: self.y,
         self.z_label: self.z,
     }
     test_value = LabelSemantics(label, env)
     self.compare(expr, test_value)
Ejemplo n.º 21
0
 def test_UpdateExpr(self):
     test_expr = UpdateExpr(self.a, (self.x, self.y), IntegerInterval(2))
     test_value = IntegerIntervalArray(
         [[IntegerInterval([1, 2]), 2], [IntegerInterval([2, 3]), 4]])
     value = arith_eval(test_expr, self.array_state)
     self.assertEqual(test_value, value)
Ejemplo n.º 22
0
 def test_numeral(self):
     expr = IntegerInterval(1)
     label = self.context.Label(expr, expr, None)
     test_value = LabelSemantics(label, {label: expr})
     self.compare(expr, test_value)
Ejemplo n.º 23
0
 def _list_elements_to_interval(self, values):
     return [[IntegerInterval(e) for e in l] for l in values]
Ejemplo n.º 24
0
 def test_matrix_getter(self):
     self.assertEqual(self.matrix[1, 2], IntegerInterval([6, 9]))
     self.assertEqual(self.matrix[[0, 1], 1], IntegerInterval([2, 9]))
Ejemplo n.º 25
0
 def test_AccessExpr(self):
     test_expr = AccessExpr(self.a, (self.x, self.y))
     test_value = IntegerInterval([1, 3])
     value = arith_eval(test_expr, self.array_state)
     self.assertEqual(test_value, value)