Skip to content

Commit 6680a33

Browse files
committed
compiler: fix printing of nd pointers
1 parent 39f2b57 commit 6680a33

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

devito/ir/cgen/printer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Utilities to turn SymPy objects into C strings.
33
"""
44
from contextlib import suppress
5+
from ctypes import _Pointer
56

67
import numpy as np
78
import sympy
@@ -110,11 +111,17 @@ def parenthesize(self, item, level, strict=False):
110111
return super().parenthesize(item, level, strict=strict)
111112

112113
def _print_PyCPointerType(self, expr):
113-
ctype = f'{self._print_type(expr._type_)}'
114+
base_type, nstart = expr, 0
115+
while issubclass(base_type, _Pointer):
116+
base_type = base_type._type_
117+
nstart += 1
118+
119+
ctype = f'{self._print_type(base_type)}'
120+
stars = '*' * nstart
114121
if ctype.endswith('*'):
115-
return f'{ctype}*'
122+
return f'{ctype}{stars}'
116123
else:
117-
return f'{ctype} *'
124+
return f'{ctype} {stars}'
118125

119126
def _print_type(self, expr):
120127
with suppress(TypeError):

examples/seismic/self_adjoint/sa_03_iso_correctness.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@
578578
"output_type": "stream",
579579
"text": [
580580
"Operator `IsoFwdOperator` ran in 0.04 s\n",
581-
"No source type defined, returning uninitiallized (zero) source\n",
581+
"No source type defined, returning uninitialized (zero) source\n",
582582
"Operator `IsoAdjOperator` ran in 0.03 s\n",
583-
"No source type defined, returning uninitiallized (zero) source\n",
583+
"No source type defined, returning uninitialized (zero) source\n",
584584
"Operator `IsoAdjOperator` ran in 0.03 s\n"
585585
]
586586
},
@@ -639,7 +639,7 @@
639639
"output_type": "stream",
640640
"text": [
641641
"Operator `IsoFwdOperator` ran in 0.03 s\n",
642-
"No source type defined, returning uninitiallized (zero) source\n",
642+
"No source type defined, returning uninitialized (zero) source\n",
643643
"Operator `IsoAdjOperator` ran in 0.03 s\n"
644644
]
645645
},

examples/seismic/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def src(self):
194194
def new_src(self, name='src', src_type='self', coordinates=None):
195195
coords = coordinates or self.src_positions
196196
if self.src_type is None or src_type is None:
197-
warning("No source type defined, returning uninitiallized (zero) source")
197+
warning("No source type defined, returning uninitialized (zero) source")
198198
src = PointSource(name=name, grid=self.grid,
199199
time_range=self.time_axis, npoint=self.nsrc,
200200
coordinates=coords,

tests/test_iet.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ctypes import c_void_p
1+
from ctypes import POINTER, c_void_p
22

33
import cgen
44
import numpy as np
@@ -20,6 +20,7 @@
2020
FLOAT, Byref, Class, FieldFromComposite, InlineIf, ListInitializer, Macro, SizeOf,
2121
String
2222
)
23+
from devito.symbolics.extended_dtypes import c_complex
2324
from devito.tools import CustomDtype, as_tuple, dtype_to_ctype
2425
from devito.types import Array, CustomDimension, LocalObject, Pointer, Symbol
2526
from devito.types.misc import FunctionMap
@@ -528,6 +529,16 @@ def test_codegen_quality0():
528529
assert foo1.parameters[0] is a
529530

530531

532+
def test_complex_array():
533+
grid = Grid(shape=(4, 4, 4))
534+
_, y, z = grid.dimensions
535+
536+
a = Array(name='a', dimensions=grid.dimensions, dtype=POINTER(c_complex))
537+
538+
assert str(Definition(a)) == \
539+
"float _Complex **restrict a_vec __attribute__ ((aligned (64)));"
540+
541+
531542
def test_special_array_definition():
532543

533544
class MyArray(Array):

0 commit comments

Comments
 (0)