diff --git a/docs/source/reference/WorkingWithTypes.md b/docs/source/reference/WorkingWithTypes.md index c7e3fb5cacd7448717f2e47ebe8d75f1836406aa..e0f9283773cea55453ecdfe2377dc82b096e0741 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 a4c2712a62dece39086a3ba2def1a2ce85e1f2b5..246232efde7a6b432598f614492725e2ea063cff 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 48a7eebeb9aafe847d00d8e72374f9a4b695be61..55f1961ca5c00963c16912ada738788688a93452 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 290576368a0d24997df4af74b466c204cb9ae318..e2435d6bbe570887e0903c67f6041ed9911c02be 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 29b872952f605511ca44501efa761f889838a1a9..bf6058537a7217851d22987f3b011edea08058c8 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)