Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dsl: Patch edge-case derivative specifications #2366

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
tests: Add test for derivative specification
  • Loading branch information
EdCaunt committed Apr 30, 2024
commit ca2d74836db788da80c2420cbfa64f0e8b5d784a
1 change: 1 addition & 0 deletions devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def _process_kwargs(cls, expr, *dims, **kwargs):
variable_count = [sympy.Tuple(s, dims.count(s))
for s in filter_ordered(dims)]
return dims, deriv_orders, fd_orders, variable_count

# Sanitise `dims`. ((x, 2), (y, 0)) is valid input, but (y, 0) should be dropped.
dims = tuple(d for d in dims if not (isinstance(d, Iterable) and d[1] == 0))

Expand Down
21 changes: 21 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,27 @@ def test_substitution(self):
assert f1 is not f2
assert f1.subs(f2, -1) == -1

def test_zero_spec(self):
"""
Test that derivatives specified as Derivative(f, (x, 2), (y, 0)) are
correctly handled.
"""
grid = Grid((11, 11))
x, y = grid.dimensions
f = Function(name="f", grid=grid, space_order=4)
# Check that both specifications match
drv0 = Derivative(f, (x, 2))
drv1 = Derivative(f, (x, 2), (y, 0))
assert drv0.dims == drv1.dims
assert drv0.fd_order == drv1.fd_order
assert drv0.deriv_order == drv1.deriv_order

# Check that substitution can applied correctly
expr0 = drv0 + 1
expr1 = drv1 + 1
assert expr0.subs(drv0, drv1) == expr1
assert expr1.subs(drv1, drv0) == expr0


class TestTwoStageEvaluation(object):

Expand Down
Loading