From 6680a334b1e9d43bf2121136a546418cd7c4c76a Mon Sep 17 00:00:00 2001 From: mloubout Date: Sun, 3 May 2026 08:40:52 -0400 Subject: [PATCH] compiler: fix printing of nd pointers --- devito/ir/cgen/printer.py | 13 ++++++++++--- .../self_adjoint/sa_03_iso_correctness.ipynb | 6 +++--- examples/seismic/utils.py | 2 +- tests/test_iet.py | 13 ++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/devito/ir/cgen/printer.py b/devito/ir/cgen/printer.py index e3878c2a19..3f87496c62 100644 --- a/devito/ir/cgen/printer.py +++ b/devito/ir/cgen/printer.py @@ -2,6 +2,7 @@ Utilities to turn SymPy objects into C strings. """ from contextlib import suppress +from ctypes import _Pointer import numpy as np import sympy @@ -110,11 +111,17 @@ def parenthesize(self, item, level, strict=False): return super().parenthesize(item, level, strict=strict) def _print_PyCPointerType(self, expr): - ctype = f'{self._print_type(expr._type_)}' + base_type, nstart = expr, 0 + while issubclass(base_type, _Pointer): + base_type = base_type._type_ + nstart += 1 + + ctype = f'{self._print_type(base_type)}' + stars = '*' * nstart if ctype.endswith('*'): - return f'{ctype}*' + return f'{ctype}{stars}' else: - return f'{ctype} *' + return f'{ctype} {stars}' def _print_type(self, expr): with suppress(TypeError): diff --git a/examples/seismic/self_adjoint/sa_03_iso_correctness.ipynb b/examples/seismic/self_adjoint/sa_03_iso_correctness.ipynb index c4933e85ee..feba7f7824 100644 --- a/examples/seismic/self_adjoint/sa_03_iso_correctness.ipynb +++ b/examples/seismic/self_adjoint/sa_03_iso_correctness.ipynb @@ -578,9 +578,9 @@ "output_type": "stream", "text": [ "Operator `IsoFwdOperator` ran in 0.04 s\n", - "No source type defined, returning uninitiallized (zero) source\n", + "No source type defined, returning uninitialized (zero) source\n", "Operator `IsoAdjOperator` ran in 0.03 s\n", - "No source type defined, returning uninitiallized (zero) source\n", + "No source type defined, returning uninitialized (zero) source\n", "Operator `IsoAdjOperator` ran in 0.03 s\n" ] }, @@ -639,7 +639,7 @@ "output_type": "stream", "text": [ "Operator `IsoFwdOperator` ran in 0.03 s\n", - "No source type defined, returning uninitiallized (zero) source\n", + "No source type defined, returning uninitialized (zero) source\n", "Operator `IsoAdjOperator` ran in 0.03 s\n" ] }, diff --git a/examples/seismic/utils.py b/examples/seismic/utils.py index 468e44ddd6..b4eb98a5dc 100644 --- a/examples/seismic/utils.py +++ b/examples/seismic/utils.py @@ -194,7 +194,7 @@ def src(self): def new_src(self, name='src', src_type='self', coordinates=None): coords = coordinates or self.src_positions if self.src_type is None or src_type is None: - warning("No source type defined, returning uninitiallized (zero) source") + warning("No source type defined, returning uninitialized (zero) source") src = PointSource(name=name, grid=self.grid, time_range=self.time_axis, npoint=self.nsrc, coordinates=coords, diff --git a/tests/test_iet.py b/tests/test_iet.py index a481b2d740..e8e8f8444f 100644 --- a/tests/test_iet.py +++ b/tests/test_iet.py @@ -1,4 +1,4 @@ -from ctypes import c_void_p +from ctypes import POINTER, c_void_p import cgen import numpy as np @@ -20,6 +20,7 @@ FLOAT, Byref, Class, FieldFromComposite, InlineIf, ListInitializer, Macro, SizeOf, String ) +from devito.symbolics.extended_dtypes import c_complex from devito.tools import CustomDtype, as_tuple, dtype_to_ctype from devito.types import Array, CustomDimension, LocalObject, Pointer, Symbol from devito.types.misc import FunctionMap @@ -528,6 +529,16 @@ def test_codegen_quality0(): assert foo1.parameters[0] is a +def test_complex_array(): + grid = Grid(shape=(4, 4, 4)) + _, y, z = grid.dimensions + + a = Array(name='a', dimensions=grid.dimensions, dtype=POINTER(c_complex)) + + assert str(Definition(a)) == \ + "float _Complex **restrict a_vec __attribute__ ((aligned (64)));" + + def test_special_array_definition(): class MyArray(Array):