From 8d38f21ede9300c92d77438df9767a91da0ec2da Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Mon, 27 Jan 2025 15:32:45 +0100 Subject: [PATCH] apply review suggestions --- docs/source/reference/WorkingWithTypes.md | 3 +-- src/pystencils/field.py | 2 +- src/pystencils/jit/cpu_extension_module.py | 8 ++++---- src/pystencils/sympyextensions/typed_sympy.py | 3 --- tests/frontend/test_typed_sympy.py | 4 ---- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/docs/source/reference/WorkingWithTypes.md b/docs/source/reference/WorkingWithTypes.md index c7e3fb5ca..e0f928377 100644 --- a/docs/source/reference/WorkingWithTypes.md +++ b/docs/source/reference/WorkingWithTypes.md @@ -109,8 +109,7 @@ independent from the code generator configuration. Pystencils enforces that all symbols, constants, and fields occuring inside an expression have the same data type. -The code generator will never introduce implicit casts -- -if any type conflicts arise, it will terminate with an error. +The code generator will never introduce implicit casts--if any type conflicts arise, it will terminate with an error. Still, there are cases where you want to combine subexpressions of different types; maybe you need to compute geometric information from loop counters or other integers, diff --git a/src/pystencils/field.py b/src/pystencils/field.py index a4c2712a6..246232efd 100644 --- a/src/pystencils/field.py +++ b/src/pystencils/field.py @@ -1127,7 +1127,7 @@ def fields( """Creates pystencils fields from a string description. The description must be a string of the form - ``"name(index-shape) [name(index-shape) ...] <data-type>[<dimension-or-shape>]"``, + ``"name(index-shape) [name(index-shape) ...]: <data-type>[<dimension-or-shape>]"``, where: - ``name`` is the name of the respective field diff --git a/src/pystencils/jit/cpu_extension_module.py b/src/pystencils/jit/cpu_extension_module.py index 48a7eebeb..55f1961ca 100644 --- a/src/pystencils/jit/cpu_extension_module.py +++ b/src/pystencils/jit/cpu_extension_module.py @@ -230,12 +230,12 @@ if( !kwargs || !PyDict_Check(kwargs) ) {{ else: return None - def get_field_buffer(self, field: Field): + def get_field_buffer(self, field: Field) -> str: """Get the Python buffer object for the given field.""" return f"buffer_{field.name}" - def extract_field(self, field: Field): - """Adds an array, and returns the name of the underlying Py_Buffer.""" + def extract_field(self, field: Field) -> None: + """Add the necessary code to extract the NumPy array for a given field""" if field not in self._array_extractions: extraction_code = self.TMPL_EXTRACT_ARRAY.format(name=field.name) actual_dtype = self._buffer_types[field] @@ -302,7 +302,7 @@ if( !kwargs || !PyDict_Check(kwargs) ) {{ return param.name - def extract_params(self, params: tuple[Parameter, ...]): + def extract_params(self, params: tuple[Parameter, ...]) -> None: for param in params: if ptr_props := param.get_properties(FieldBasePtr): prop: FieldBasePtr = cast(FieldBasePtr, ptr_props.pop()) diff --git a/src/pystencils/sympyextensions/typed_sympy.py b/src/pystencils/sympyextensions/typed_sympy.py index 290576368..e2435d6bb 100644 --- a/src/pystencils/sympyextensions/typed_sympy.py +++ b/src/pystencils/sympyextensions/typed_sympy.py @@ -174,9 +174,6 @@ class TypeCast(sp.Function): @classmethod def eval(cls, expr: sp.Basic, tatom: TypeAtom) -> TypeCast | None: - if isinstance(expr, TypeCast): - return TypeCast(expr.args[0], tatom) - dtype = tatom.get() if cls is not BoolCast and isinstance(dtype, PsNumericType) and dtype.is_bool(): return BoolCast(expr, tatom) diff --git a/tests/frontend/test_typed_sympy.py b/tests/frontend/test_typed_sympy.py index 29b872952..bf6058537 100644 --- a/tests/frontend/test_typed_sympy.py +++ b/tests/frontend/test_typed_sympy.py @@ -63,10 +63,6 @@ def test_casts(): expr_reconst = pickle.loads(dump) assert expr_reconst == expr - # Double Cast Elimination - expr = tcast(tcast(x, "int32"), "uint64") - assert expr == tcast(x, "uint64") - # Boolean Casts bool_expr = tcast(x, "bool") assert isinstance(bool_expr, boolalg.Boolean) -- GitLab