From 5d583830991c014191fa50d6fb401215816716b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Tr=C3=BCmper?= Date: Thu, 17 Feb 2022 09:55:55 +0100 Subject: [PATCH 1/2] Bugfix: step width in iteration_length --- kerncraft/kernel.py | 3 ++- kerncraft/symbolic/__init__.py | 1 + kerncraft/symbolic/utils.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 kerncraft/symbolic/__init__.py create mode 100644 kerncraft/symbolic/utils.py diff --git a/kerncraft/kernel.py b/kerncraft/kernel.py index f8db9e7..3054bd4 100755 --- a/kerncraft/kernel.py +++ b/kerncraft/kernel.py @@ -37,6 +37,7 @@ from . import incore_model from .pycparser_utils import clean_code, replace_id +from kerncraft.symbolic.utils import int_ceil class LessParanthesizingCGenerator(CGenerator): def get_BinaryOp_precedence(self, n): @@ -420,7 +421,7 @@ def iteration_length(self, dimension=None): for var_name, start, end, incr in loops: # This unspools the iterations: - length = end-start + length = int_ceil((end-start), incr) total_length = total_length*length return self.subs_consts(total_length) diff --git a/kerncraft/symbolic/__init__.py b/kerncraft/symbolic/__init__.py new file mode 100644 index 0000000..b63a01f --- /dev/null +++ b/kerncraft/symbolic/__init__.py @@ -0,0 +1 @@ +from kerncraft.symbolic.utils import int_ceil, int_floor diff --git a/kerncraft/symbolic/utils.py b/kerncraft/symbolic/utils.py new file mode 100644 index 0000000..5099398 --- /dev/null +++ b/kerncraft/symbolic/utils.py @@ -0,0 +1,19 @@ +import sympy + +class int_floor(sympy.Function): + @classmethod + def eval(cls, x, y): + if x.is_Number and y.is_Number: + return x // y + + def _eval_is_integer(self): + return True + +class int_ceil(sympy.Function): + @classmethod + def eval(cls, x, y): + if x.is_Number and y.is_Number: + return sympy.ceiling(x / y) + + def _eval_is_integer(self): + return True From 0aea54643f349135789cc3458c48dc0d61c592d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Tr=C3=BCmper?= Date: Thu, 17 Feb 2022 13:11:21 +0100 Subject: [PATCH 2/2] step width fixes --- kerncraft/kernel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kerncraft/kernel.py b/kerncraft/kernel.py index 3054bd4..e5c72ba 100755 --- a/kerncraft/kernel.py +++ b/kerncraft/kernel.py @@ -515,7 +515,7 @@ def global_iterator_to_indices(self, git=None): loop_var = symbol_pos_int(var_name) # This unspools the iterations: - length = end-start # FIXME is incr handled correct here? + length = int_ceil((end-start), incr) counter = start+(((global_iterator*last_incr) // total_length)*incr) % length total_length = total_length*length last_incr = incr @@ -543,7 +543,7 @@ def global_iterator(self): total_length = sympy.Integer(1) for var_name, start, end, incr in reversed(self._loop_stack): loop_var = symbol_pos_int(var_name) - length = end - start # FIXME is incr handled correct here? + length = int_ceil((end-start), incr) global_iterator += (loop_var - start) * total_length total_length *= length return global_iterator