diff --git a/pystencils/astnodes.py b/pystencils/astnodes.py index ef0bcc6d758fdb67fc42b708038882360a9eee65..6976b857c1757734472ff63d344a2bf63220b0f1 100644 --- a/pystencils/astnodes.py +++ b/pystencils/astnodes.py @@ -377,6 +377,8 @@ class Block(Node): return tmp def replace(self, child, replacements): + if self._nodes.count(child) != 1: + print('here') assert self._nodes.count(child) == 1 idx = self._nodes.index(child) del self._nodes[idx] diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index f425eef885203c6305e69fbdd56226dbf0b36aa9..139c8b0f62a0fcdd73d5db212c210b5816bfef49 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -219,7 +219,7 @@ class CBackend: method_name = f"_print_{cls.__name__}" if hasattr(self, method_name): return getattr(self, method_name)(node) - raise NotImplementedError(f"{self.__class__.__name__} does not support node of type {node.__class__.__name__}") + return self.sympy_printer.doprint(node) def _print_AbstractType(self, node): return str(node) diff --git a/pystencils/integer_set_analysis.py b/pystencils/integer_set_analysis.py index 2e37c643fa6fd6497b918606efbc57c86995a760..a3fcd37a291fa18a33937b86287c58f57eadd50e 100644 --- a/pystencils/integer_set_analysis.py +++ b/pystencils/integer_set_analysis.py @@ -5,6 +5,7 @@ import sympy as sp import pystencils.astnodes as ast from pystencils.typing import parents_of_type +from pystencils.backends import generate_c def remove_brackets(s): @@ -51,7 +52,7 @@ def simplify_loop_counter_dependent_conditional(conditional): dofs_in_loops, iteration_set = isl_iteration_set(conditional) if dofs_in_condition.issubset(dofs_in_loops): symbol_names = ','.join(dofs_in_loops) - condition_str = remove_brackets(str(conditional.condition_expr)) + condition_str = remove_brackets(generate_c(conditional.condition_expr)) condition_set = isl.BasicSet(f"{{ [{symbol_names}] : {condition_str} }}") if condition_set.is_empty(): diff --git a/pystencils/transformations.py b/pystencils/transformations.py index 2e885904a1dfe8a0450b4d807aabcba365be56a7..7725e611f18f0597750a4d38f9c3e582da93bf04 100644 --- a/pystencils/transformations.py +++ b/pystencils/transformations.py @@ -772,7 +772,8 @@ def simplify_conditionals(node: ast.Node, loop_counter_simplification: bool = Fa default. """ for conditional in node.atoms(ast.Conditional): - conditional.condition_expr = sp.simplify(conditional.condition_expr) + # TODO simplify conditional before the type system! + # conditional.condition_expr = sp.simplify(conditional.condition_expr) if conditional.condition_expr == sp.true: conditional.parent.replace(conditional, [conditional.true_block]) elif conditional.condition_expr == sp.false: diff --git a/pystencils/typing/leaf_typing.py b/pystencils/typing/leaf_typing.py index d95ef81c32317b7d74ed13c551770f52962f339e..b8cefb450adb5f3ead35618c5dcb28447b5854f9 100644 --- a/pystencils/typing/leaf_typing.py +++ b/pystencils/typing/leaf_typing.py @@ -102,7 +102,7 @@ class TypeAdder: # Possible Problems - Do we need to support this? # - Mixture in expression with int and float # - Mixture in expression with uint64 and sint64 - # TODO: Lowest log level should log all casts ----> cast factory, make cast should contain logging + # TODO Logging: Lowest log level should log all casts ----> cast factory, make cast should contain logging def figure_out_type(self, expr) -> Tuple[Any, Union[BasicType, PointerType]]: # Trivial cases from pystencils.field import Field @@ -112,7 +112,6 @@ class TypeAdder: # TOOO: check the access if isinstance(expr, Field.Access): - # TODO if Struct, look at the reinterpreted dtype return expr, expr.dtype elif isinstance(expr, TypedSymbol): return expr, expr.dtype @@ -139,7 +138,7 @@ class TypeAdder: elif isinstance(expr, BooleanAtom): return expr, bool_type elif isinstance(expr, Relational): - # TODO JAN: Code duplication with general case + # TODO Jan: Code duplication with general case args_types = [self.figure_out_type(arg) for arg in expr.args] collated_type = collate_types([t for _, t in args_types]) if isinstance(expr, sp.Equality) and collated_type.is_float(): @@ -188,7 +187,7 @@ class TypeAdder: return expr.func(expr.args[0], expr.args[1], *new_expressions), collated_type # elif isinstance(expr, sp.Mul): # raise NotImplementedError('sp.Mul') - # # TODO can we ignore this and move it to general expr handling, i.e. removing Mul? + # # TODO can we ignore this and move it to general expr handling, i.e. removing Mul? (See todo in backend) # # args_types = [self.figure_out_type(arg) for arg in expr.args if arg not in (-1, 1)] elif isinstance(expr, sp.Indexed): raise NotImplementedError('sp.Indexed') diff --git a/pystencils_tests/test_blocking_staggered.py b/pystencils_tests/test_blocking_staggered.py index a79efe7c4445faa9baeb8323383b382a42f2cf33..722c2a35871c27a008123f053b8bd7a446d937a0 100644 --- a/pystencils_tests/test_blocking_staggered.py +++ b/pystencils_tests/test_blocking_staggered.py @@ -12,8 +12,10 @@ def test_blocking_staggered(): f[0, 0, 0] - f[0, 0, -1], ] assignments = [ps.Assignment(stag.staggered_access(d), terms[i]) for i, d in enumerate(stag.staggered_stencil)] + reference_kernel = ps.create_staggered_kernel(assignments) + print(ps.show_code(reference_kernel)) + reference_kernel = reference_kernel.compile() kernel = ps.create_staggered_kernel(assignments, cpu_blocking=(3, 16, 8)).compile() - reference_kernel = ps.create_staggered_kernel(assignments).compile() print(ps.show_code(kernel.ast)) f_arr = np.random.rand(80, 33, 19)