From a9c8d6a7ccf65e79fc57d3e92818becb513ae4d3 Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Sat, 26 Apr 2025 21:01:57 +0200 Subject: [PATCH] Apply 4 suggestion(s) to 2 file(s) Co-authored-by: Frederik Hennig <frederik.hennig@fau.de> --- src/pystencils/backend/kernelcreation/context.py | 9 ++++----- src/pystencils/backend/kernelcreation/freeze.py | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pystencils/backend/kernelcreation/context.py b/src/pystencils/backend/kernelcreation/context.py index 3e79bf24a..48e2f4a3a 100644 --- a/src/pystencils/backend/kernelcreation/context.py +++ b/src/pystencils/backend/kernelcreation/context.py @@ -207,7 +207,7 @@ class KernelCreationContext: def add_reduction_info( self, lhs_name: str, - lhs_dtype: PsType, + lhs_dtype: PsNumericType, reduction_op: ReductionOp, ): """Create ReductionInfo instance and add to its corresponding lookup table for a given symbol name.""" @@ -215,16 +215,15 @@ class KernelCreationContext: # make sure that lhs symbol never occurred before ReductionAssignment if self.find_symbol(lhs_name): raise KernelConstraintsError( - f"Left-hand side {lhs_name} of ReductionAssignment already exists in symbol table. " - f"Make sure that it is only used once in a kernel's ReductionAssignment." + f"Cannot create reduction with symbol {lhs_name}: " + "Another symbol with the same name already exist." ) # add symbol for lhs with pointer datatype for write-back mechanism pointer_symb = self.get_symbol(lhs_name, PsPointerType(lhs_dtype)) # create kernel-local copy of lhs symbol - local_symb = PsSymbol(f"{lhs_name}_local", lhs_dtype) - self.add_symbol(local_symb) + local_symb = self.get_new_symbol(f"{lhs_name}_local", lhs_dtype) # match for reduction operation and set neutral init_val init_val: PsExpression diff --git a/src/pystencils/backend/kernelcreation/freeze.py b/src/pystencils/backend/kernelcreation/freeze.py index b1bb4cd4a..598716567 100644 --- a/src/pystencils/backend/kernelcreation/freeze.py +++ b/src/pystencils/backend/kernelcreation/freeze.py @@ -198,9 +198,8 @@ class FreezeExpressions: lhs_dtype = lhs_symbol.dtype lhs_name = lhs_symbol.name - assert isinstance( - lhs_dtype, PsNumericType - ), "Reduction assignments require type information of the lhs symbol." + if not isinstance(lhs_dtype, PsNumericType): + raise FreezeError("Reduction symbol must have a numeric data type.") # get reduction info from context reduction_info = self._ctx.add_reduction_info( -- GitLab