Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,12 @@ def parse_kwargs(**kwargs):
if isinstance(overrides, dict):
options.update(overrides)

# A listed `linearize` (e.g., `opt=('linearize', {})`) must run after the
# symbol definitions, so it is turned into the homonymous option
if mode and 'linearize' in as_tuple(mode):
options.setdefault('linearize', True)
mode = tuple(i for i in as_tuple(mode) if i != 'linearize')

# `opt`, deprecated kwargs
kwopenmp = kwargs.get('openmp', options.get('openmp'))
if kwopenmp is None:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_linearize.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,26 @@ def test_bundle_derived_dim_stride():
assert bundle.symbolic_shape[p] is not bundle.symbolic_shape[rp]
assert bundle.symbolic_shape[rp] == 2
assert bundle.symbolic_shape.dindex(rp) == 1


@pytest.mark.parametrize('opt', [
(('linearize',), {}),
(('linearize',), {'linearize': True}),
(('openmp', 'linearize'), {'linearize': True}),
])
def test_linearize_as_pass(opt):
"""
Listing `linearize` among the passes enables linearization after the
symbol definitions are in place, as with `opt=('advanced', {'linearize': True})`.
"""
grid = Grid(shape=(4, 4))

u = TimeFunction(name='u', grid=grid)

op = Operator(Eq(u.forward, u + 1), opt=opt, name='LinearizeAsPass')

assert 'uL0' in str(op)

op.apply(time_M=2)

assert np.all(u.data[1] == 3)
Loading