diff --git a/pystencils/astnodes.py b/pystencils/astnodes.py index 6ccc39fea438021cd74381a23466b48780077332..47f1fd7d1d1715bf85e326e485aad8231dadcdfe 100644 --- a/pystencils/astnodes.py +++ b/pystencils/astnodes.py @@ -465,11 +465,13 @@ class LoopOverCoordinate(Node): @staticmethod def get_loop_counter_symbol(coordinate_to_loop_over): - return TypedSymbol(LoopOverCoordinate.get_loop_counter_name(coordinate_to_loop_over), 'int') + return TypedSymbol(LoopOverCoordinate.get_loop_counter_name(coordinate_to_loop_over), 'int', nonnegative=True) @staticmethod def get_block_loop_counter_symbol(coordinate_to_loop_over): - return TypedSymbol(LoopOverCoordinate.get_block_loop_counter_name(coordinate_to_loop_over), 'int') + return TypedSymbol(LoopOverCoordinate.get_block_loop_counter_name(coordinate_to_loop_over), + 'int', + nonnegative=True) @property def loop_counter_symbol(self): @@ -503,7 +505,7 @@ class SympyAssignment(Node): def __init__(self, lhs_symbol, rhs_expr, is_const=True): super(SympyAssignment, self).__init__(parent=None) self._lhs_symbol = lhs_symbol - self.rhs = sp.simplify(rhs_expr) + self.rhs = sp.sympify(rhs_expr) self._is_const = is_const self._is_declaration = self.__is_declaration() diff --git a/pystencils/cpu/kernelcreation.py b/pystencils/cpu/kernelcreation.py index 7859c537fe3fbe50a2e94bb2c2c67622f1c1f852..f351ce5a2bb03d723d22a8e1f772b25a934f7994 100644 --- a/pystencils/cpu/kernelcreation.py +++ b/pystencils/cpu/kernelcreation.py @@ -42,12 +42,11 @@ def create_kernel(assignments: AssignmentOrAstNodeList, function_name: str = "ke Returns: AST node representing a function, that can be printed as C or CUDA code """ - def type_symbol(term): if isinstance(term, Field.Access) or isinstance(term, TypedSymbol): return term elif isinstance(term, sp.Symbol): - if not hasattr(type_info, '__getitem__'): + if isinstance(type_info, str) or not hasattr(type_info, '__getitem__'): return TypedSymbol(term.name, create_type(type_info)) else: return TypedSymbol(term.name, type_info[term.name]) diff --git a/pystencils/data_types.py b/pystencils/data_types.py index d229eb040c711220336a2bcad00ec1938ae29969..20eb94d6b83474bfab46dc491a05b3b1ed2191d9 100644 --- a/pystencils/data_types.py +++ b/pystencils/data_types.py @@ -240,6 +240,10 @@ class TypedSymbol(sp.Symbol): def canonical(self): return self + @property + def reversed(self): + return self + def create_type(specification): """Creates a subclass of Type according to a string or an object of subclass Type. diff --git a/pystencils/simp/assignment_collection.py b/pystencils/simp/assignment_collection.py index fd5c827113ceb776defdcd8cb2ff95bddb293950..ce9f1c9fecaafb62a2f34789fdec5e7a02c537ef 100644 --- a/pystencils/simp/assignment_collection.py +++ b/pystencils/simp/assignment_collection.py @@ -111,6 +111,7 @@ class AssignmentCollection: "Not in SSA form - same symbol assigned multiple times" return bound_symbols_set + @property def free_fields(self): """All fields accessed in the assignment collection, which do not occur as left hand sides in any assignment.""" return {s.field for s in self.free_symbols if hasattr(s, 'field')} diff --git a/pystencils_tests/test_vectorization.py b/pystencils_tests/test_vectorization.py index 1505c7543ee632d1a80a0405fef8e7080fc9bd22..1fa1812eb8fced19d114ef3cb32900ec9b93f995 100644 --- a/pystencils_tests/test_vectorization.py +++ b/pystencils_tests/test_vectorization.py @@ -46,6 +46,7 @@ def test_inplace_update(): kernel(f=arr) np.testing.assert_equal(arr, 2) + def test_vectorization_fixed_size(): configurations = [] # Fixed size - multiple of four