Skip to content

Commit e5e4557

Browse files
committed
misc: Various fixes
1 parent a7e2984 commit e5e4557

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

examples/seismic/tti/tti_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from contextlib import suppress
2+
13
import numpy as np
2-
from contrextlib import suppress
34

45
with suppress(ImportError):
56
import pytest

examples/seismic/tutorials/07.1_dispersion_relation.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,10 +1132,10 @@
11321132
"x = np.linspace(0, np.pi, 201)\n",
11331133
"m = np.arange(1, len(fornberg) + 1)\n",
11341134
"y_fornberg = - fornberg[0] - 2*np.sum(\n",
1135-
" [a_ * np.cos(m_*x) for a_, m_ in zip(fornberg[1:], m, strict=True)], axis=0\n",
1135+
" [a_ * np.cos(m_*x) for a_, m_ in zip(fornberg[1:], m, strict=False)], axis=0\n",
11361136
")\n",
11371137
"y_drp1 = - drp_stencil1[0] - 2*np.sum(\n",
1138-
" [a_ * np.cos(m_*x) for a_, m_ in zip(drp_stencil1[1:], m, strict=True)], axis=0\n",
1138+
" [a_ * np.cos(m_*x) for a_, m_ in zip(drp_stencil1[1:], m, strict=False)], axis=0\n",
11391139
")\n",
11401140
"\n",
11411141
"fig, ax = plt.subplots(1, 2)\n",

tests/test_caching.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ def test_sparse_function(self, operate_on_empty_cache):
678678
ncreated = 2+1+2+2+2+1+4
679679
# Note that injection is now lazy so no new symbols should be created
680680
assert len(_SymbolCache) == cur_cache_size
681-
_ = i.evaluate
681+
# The expression is not redundant, but storing it changes the symbol count
682+
i.evaluate # noqa: B018
682683

683684
assert len(_SymbolCache) == cur_cache_size + ncreated
684685

tests/test_dimension.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,8 +1492,29 @@ def test_stepping_dim_in_condition_lowering(self):
14921492
op.apply(time_M=threshold+3)
14931493
assert np.all(g.data[0, :, :] == threshold)
14941494
assert np.all(g.data[1, :, :] == threshold + 1)
1495-
assert 'if (g[t0][x + 1][y + 1] <= 10)\n' + \
1496-
'{\n g[t1][x + 1][y + 1] = g[t0][x + 1][y + 1] + 1' in str(op.ccode)
1495+
1496+
# We want to assert that the following snippet:
1497+
# ```
1498+
# if (g[t0][x + 1][y + 1] <= 10)
1499+
# {
1500+
# g[t1][x + 1][y + 1] = g[t0][x + 1][y + 1] + 1
1501+
# ```
1502+
# is in the generated code, but indentation etc. seems to vary.
1503+
part1 = 'if (g[t0][x + 1][y + 1] <= 10)\n'
1504+
part2 = 'g[t1][x + 1][y + 1] = g[t0][x + 1][y + 1] + 1'
1505+
whole_code = str(op.ccode)
1506+
1507+
try:
1508+
loc = whole_code.find(part1)
1509+
assert loc != -1
1510+
assert whole_code.find(part2, loc + len(part1)) != -1
1511+
except AssertionError:
1512+
# Try the alternative string
1513+
part1 = 'if (gL0(t0, x + 1, y + 1) <= 10)\n'
1514+
part2 = 'gL0(t1, x + 1, y + 1) = gL0(t0, x + 1, y + 1) + 1'
1515+
loc = whole_code.find(part1)
1516+
assert loc != -1
1517+
assert whole_code.find(part2, loc + len(part1)) != -1
14971518

14981519
def test_expr_like_lowering(self):
14991520
"""

tests/test_dle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222

2323
def get_blocksizes(op, opt, grid, blockshape, level=0):
24-
blocksizes = {f'{d}0_blk{level}_size': v
25-
for d, v in zip(grid.dimensions, blockshape, strict=True)}
24+
blocksizes = {
25+
f'{d}0_blk{level}_size': v
26+
for d, v in zip(grid.dimensions, blockshape, strict=False)
27+
}
2628
blocksizes = {k: v for k, v in blocksizes.items() if k in op._known_arguments}
2729
# Sanity check
2830
if grid.dim == 1 or len(blockshape) == 0:

0 commit comments

Comments
 (0)