Skip to content

Commit 0248b87

Browse files
committed
compiler: only parenthesise non-atom
1 parent 253a68a commit 0248b87

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

devito/ir/cgen/printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def _print_UnaryOp(self, expr, op=None, parenthesize=False):
370370

371371
def _print_Cast(self, expr):
372372
cast = f'({self._print(expr._C_ctype)}{self._print(expr.stars)})'
373-
return self._print_UnaryOp(expr, op=cast, parenthesize=True)
373+
return self._print_UnaryOp(expr, op=cast, parenthesize=not expr.base.is_Atom)
374374

375375
def _print_ComponentAccess(self, expr):
376376
return f"{self._print(expr.base)}.{expr.sindex}"

devito/passes/iet/languages/CXX.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def _print_Cast(self, expr):
127127
return super()._print_Cast(expr)
128128
caster = 'reinterpret_cast' if expr.reinterpret else 'static_cast'
129129
cast = f'{caster}<{tstr}{self._print(expr.stars)}>'
130-
return self._print_UnaryOp(expr, op=cast, parenthesize=True)
130+
return self._print_UnaryOp(expr, op=cast, parenthesize=not expr.base.is_Atom)
131131

132132
def _print_ListInitializer(self, expr):
133133
li = super()._print_ListInitializer(expr)

devito/symbolics/manipulation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from devito.finite_differences.differentiable import (
1111
EvalDerivative, IndexDerivative
1212
)
13-
from devito.symbolics.extended_sympy import DefFunction, rfunc, LONG
13+
from devito.symbolics.extended_sympy import DefFunction, rfunc
14+
from devito.symbolics.extended_dtypes import LONG
1415
from devito.symbolics.queries import q_leaf
1516
from devito.symbolics.search import (
1617
retrieve_indexed, retrieve_functions, retrieve_symbols

examples/mpi/overview.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@
486486
" MPI_Request rsend;\n",
487487
"\n",
488488
" float *restrict bufg_vec __attribute__ ((aligned (64)));\n",
489-
" posix_memalign((void**)(&bufg_vec),64,sizeof(float)*(long)(y_size)*(long)(x_size));\n",
489+
" posix_memalign((void**)(&bufg_vec),64,sizeof(float)*(long)y_size*(long)x_size);\n",
490490
" float *restrict bufs_vec __attribute__ ((aligned (64)));\n",
491-
" posix_memalign((void**)(&bufs_vec),64,sizeof(float)*(long)(y_size)*(long)(x_size));\n",
491+
" posix_memalign((void**)(&bufs_vec),64,sizeof(float)*(long)y_size*(long)x_size);\n",
492492
"\n",
493493
" MPI_Irecv(bufs_vec,x_size*y_size,MPI_FLOAT,fromrank,13,comm,&(rrecv));\n",
494494
" if (torank != MPI_PROC_NULL)\n",

examples/performance/00_overview.ipynb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,7 @@
725725
" }\n",
726726
" }\n",
727727
" STOP(section0,timers)\n",
728-
"}\n",
729-
"\n"
728+
"}\n"
730729
]
731730
}
732731
],
@@ -1193,13 +1192,13 @@
11931192
"int Kernel(struct dataobj *restrict f_vec, struct dataobj *restrict u_vec, const float h_y, const int time_M, const int time_m, const int x0_blk0_size, const int x_M, const int x_m, const int y0_blk0_size, const int y_M, const int y_m, const int z_M, const int z_m, const int nthreads, const int z_size, const int x_size, const int y_size, struct profiler * timers)\n",
11941193
"{\n",
11951194
" float **restrict pr2_vec __attribute__ ((aligned (64)));\n",
1196-
" posix_memalign((void**)(&pr2_vec),64,sizeof(float*)*(long)(nthreads));\n",
1195+
" posix_memalign((void**)(&pr2_vec),64,sizeof(float*)*(long)nthreads);\n",
11971196
" float *restrict r0_vec __attribute__ ((aligned (64)));\n",
1198-
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)(z_size)*(long)(y_size)*(long)(x_size));\n",
1197+
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)z_size*(long)y_size*(long)x_size);\n",
11991198
" #pragma omp parallel num_threads(nthreads)\n",
12001199
" {\n",
12011200
" const int tid = omp_get_thread_num();\n",
1202-
" posix_memalign((void**)(&(pr2_vec[tid])),64,sizeof(float)*(long)(z_size)*(4 + (long)(y0_blk0_size)));\n",
1201+
" posix_memalign((void**)(&(pr2_vec[tid])),64,sizeof(float)*(long)z_size*(4 + (long)y0_blk0_size));\n",
12031202
" }\n",
12041203
"\n",
12051204
" float (*restrict f)[f_vec->size[1]][f_vec->size[2]] __attribute__ ((aligned (64))) = (float (*)[f_vec->size[1]][f_vec->size[2]]) f_vec->data;\n",
@@ -1413,7 +1412,7 @@
14131412
"name": "stdout",
14141413
"output_type": "stream",
14151414
"text": [
1416-
"posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)(z_size)*(long)(y_size)*(long)(x_size));\n"
1415+
"posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)z_size*(long)y_size*(long)x_size);\n"
14171416
]
14181417
}
14191418
],
@@ -1484,13 +1483,13 @@
14841483
"int Kernel(struct dataobj *restrict f_vec, struct dataobj *restrict u_vec, const float h_y, const int time_M, const int time_m, const int x_M, const int x_m, const int y_M, const int y_m, const int z_M, const int z_m, const int nthreads, const int z_size, const int x_size, const int y_size, struct profiler * timers)\n",
14851484
"{\n",
14861485
" float **restrict pr2_vec __attribute__ ((aligned (64)));\n",
1487-
" posix_memalign((void**)(&pr2_vec),64,sizeof(float*)*(long)(nthreads));\n",
1486+
" posix_memalign((void**)(&pr2_vec),64,sizeof(float*)*(long)nthreads);\n",
14881487
" float *restrict r0_vec __attribute__ ((aligned (64)));\n",
1489-
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)(z_size)*(long)(y_size)*(long)(x_size));\n",
1488+
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)z_size*(long)y_size*(long)x_size);\n",
14901489
" #pragma omp parallel num_threads(nthreads)\n",
14911490
" {\n",
14921491
" const int tid = omp_get_thread_num();\n",
1493-
" posix_memalign((void**)(&(pr2_vec[tid])),64,sizeof(float)*(long)(z_size)*(4 + (long)(y_size)));\n",
1492+
" posix_memalign((void**)(&(pr2_vec[tid])),64,sizeof(float)*(long)z_size*(4 + (long)y_size));\n",
14941493
" }\n",
14951494
"\n",
14961495
" float (*restrict f)[f_vec->size[1]][f_vec->size[2]] __attribute__ ((aligned (64))) = (float (*)[f_vec->size[1]][f_vec->size[2]]) f_vec->data;\n",
@@ -1627,11 +1626,11 @@
16271626
"int Kernel(struct dataobj *restrict f_vec, struct dataobj *restrict u_vec, const float h_x, const float h_y, const int time_M, const int time_m, const int x0_blk0_size, const int x1_blk0_size, const int x_M, const int x_m, const int y0_blk0_size, const int y1_blk0_size, const int y_M, const int y_m, const int z_M, const int z_m, const int nthreads, const int x_size, const int y_size, const int z_size, struct profiler * timers)\n",
16281627
"{\n",
16291628
" float *restrict r0_vec __attribute__ ((aligned (64)));\n",
1630-
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)(z_size)*(long)(y_size)*(long)(x_size));\n",
1629+
" posix_memalign((void**)(&r0_vec),64,sizeof(float)*(long)z_size*(long)y_size*(long)x_size);\n",
16311630
" float *restrict r3_vec __attribute__ ((aligned (64)));\n",
1632-
" posix_memalign((void**)(&r3_vec),64,sizeof(float)*(long)(z_size)*(4 + (long)(y_size))*(4 + (long)(x_size)));\n",
1631+
" posix_memalign((void**)(&r3_vec),64,sizeof(float)*(long)z_size*(4 + (long)y_size)*(4 + (long)x_size));\n",
16331632
" float *restrict r4_vec __attribute__ ((aligned (64)));\n",
1634-
" posix_memalign((void**)(&r4_vec),64,sizeof(float)*(long)(z_size)*(4 + (long)(y_size))*(4 + (long)(x_size)));\n",
1633+
" posix_memalign((void**)(&r4_vec),64,sizeof(float)*(long)z_size*(4 + (long)y_size)*(4 + (long)x_size));\n",
16351634
"\n",
16361635
" float (*restrict f)[f_vec->size[1]][f_vec->size[2]] __attribute__ ((aligned (64))) = (float (*)[f_vec->size[1]][f_vec->size[2]]) f_vec->data;\n",
16371636
" float (*restrict r0)[y_size][z_size] __attribute__ ((aligned (64))) = (float (*)[y_size][z_size]) r0_vec;\n",

tests/test_iet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class SpecialObject2(LocalObject):
345345
assert 'bar<int,float>& obj2;' in str(iet)
346346
assert 'dummy obj3 = meh;' in str(iet)
347347
assert 'dummy obj4(1,2) = meh;' in str(iet)
348-
assert 'dummy obj5(ceil(1.0F/(float)(s))) = meh;' in str(iet)
348+
assert 'dummy obj5(ceil(1.0F/(float)s)) = meh;' in str(iet)
349349
assert 'float obj6 = meh;' in str(iet)
350350

351351

tests/test_symbolics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,10 @@ class BarCast(BaseCast):
426426
_dtype = 'bar'
427427

428428
v = BarCast(s, '**')
429-
assert ccode(v) == '(bar**)(s)'
429+
assert ccode(v) == '(bar**)s'
430430

431431
# Reconstruction
432-
assert ccode(v.func(*v.args)) == '(bar**)(s)'
432+
assert ccode(v.func(*v.args)) == '(bar**)s'
433433

434434
v1 = BarCast(s, '****')
435435
assert v != v1
@@ -442,19 +442,19 @@ def test_str_cast():
442442
assert not v.stars
443443
assert v.dtype == 'foo'
444444
assert v._op == '(foo)'
445-
assert ccode(v) == '(foo)(s)'
445+
assert ccode(v) == '(foo)s'
446446

447447
v = Cast(s, 'foo*')
448448
assert v.stars == '*'
449449
assert v.dtype == 'foo'
450450
assert v._op == '(foo*)'
451-
assert ccode(v) == '(foo*)(s)'
451+
assert ccode(v) == '(foo*)s'
452452

453453
v = Cast(s, 'foo **')
454454
assert v.stars == '**'
455455
assert v.dtype == 'foo'
456456
assert v._op == '(foo**)'
457-
assert ccode(v) == '(foo**)(s)'
457+
assert ccode(v) == '(foo**)s'
458458

459459

460460
def test_findexed():

0 commit comments

Comments
 (0)