diff --git a/pystencils/astnodes.py b/pystencils/astnodes.py index d91c1dad7036c8cc2f3e2664e047c5b9a13dbd12..c9d66ae260a9dc89697999b437d960ca06d21c77 100644 --- a/pystencils/astnodes.py +++ b/pystencils/astnodes.py @@ -345,14 +345,6 @@ class Block(Node): assert self._nodes.count(insert_before) == 1 idx = self._nodes.index(insert_before) - # move all assignment (definitions to the top) - if isinstance(new_node, SympyAssignment) and new_node.is_declaration: - while idx > 0: - pn = self._nodes[idx - 1] - if isinstance(pn, LoopOverCoordinate) or isinstance(pn, Conditional): - idx -= 1 - else: - break if not if_not_exists or self._nodes[idx] != new_node: self._nodes.insert(idx, new_node) @@ -361,14 +353,6 @@ class Block(Node): assert self._nodes.count(insert_after) == 1 idx = self._nodes.index(insert_after) + 1 - # move all assignment (definitions to the top) - if isinstance(new_node, SympyAssignment) and new_node.is_declaration: - while idx > 0: - pn = self._nodes[idx - 1] - if isinstance(pn, LoopOverCoordinate) or isinstance(pn, Conditional): - idx -= 1 - else: - break if not if_not_exists or not (self._nodes[idx - 1] == new_node or (idx < len(self._nodes) and self._nodes[idx] == new_node)): self._nodes.insert(idx, new_node) diff --git a/pystencils_tests/test_move_constant_before_loop.py b/pystencils_tests/test_move_constant_before_loop.py index ea736dd183459a896ccf5d86662386a1a396c85c..fb9e537b266f0cdf617e1fabb76c6b33d4e9e801 100644 --- a/pystencils_tests/test_move_constant_before_loop.py +++ b/pystencils_tests/test_move_constant_before_loop.py @@ -25,9 +25,9 @@ def test_symbol_renaming(): loops = block.atoms(LoopOverCoordinate) assert len(loops) == 2 - assert len(block.args[2].body.args) == 1 + assert len(block.args[1].body.args) == 1 assert len(block.args[3].body.args) == 2 for loop in loops: assert len(loop.parent.args) == 4 # 2 loops + 2 subexpressions - assert loop.parent.args[0].lhs.name != loop.parent.args[1].lhs.name + assert loop.parent.args[0].lhs.name != loop.parent.args[2].lhs.name