Skip to content

Commit dd1b8a8

Browse files
committed
misc: Reviewer nitpicks
1 parent e785ed8 commit dd1b8a8

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

devito/finite_differences/derivative.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __new__(cls, expr, *dims, **kwargs):
158158
@staticmethod
159159
def _validate_expr(expr):
160160
"""
161-
Validate the provided `expr`. It must be of "differentiable" type or
161+
Validate the provided `expr`. It must be of `Differentiable` type or
162162
convertible to "differentiable" type.
163163
"""
164164
if type(expr) is sympy.Derivative:
@@ -201,12 +201,13 @@ def _validate_deriv_order(deriv_order, dims):
201201
deriv_order = as_tuple(deriv_order)
202202
if len(deriv_order) != len(dims):
203203
raise ValueError(
204-
'Length of `deriv_order` does not match the length of dimensions'
204+
f'Length of `deriv_order`: {deriv_order !r}, '
205+
f'does not match the length of dimensions: {dims !r}'
205206
)
206-
if any([not is_integer(d) or d < 0 for d in deriv_order]):
207+
if any(not is_integer(d) or d < 0 for d in deriv_order):
207208
raise TypeError(
208-
'Invalid type in `deriv_order`, all elements must be non-negative'
209-
'Python `int`s'
209+
f'Invalid type in `deriv_order`: {deriv_order !r}, '
210+
'all elements must be non-negative Python `int`s'
210211
)
211212
return deriv_order
212213

@@ -220,8 +221,8 @@ def _count_derivatives(deriv_order, dims):
220221
if isinstance(d, Iterable):
221222
if not is_integer(d[1]) or d[1] < 0:
222223
raise TypeError(
223-
'Invalid type for derivative order, it must be'
224-
'non-negative Python `int`'
224+
f'Invalid type for derivative order: {d !r},'
225+
'it must be non-negative Python `int`'
225226
)
226227
else:
227228
dcounter[d[0]] += d[1]
@@ -232,12 +233,12 @@ def _count_derivatives(deriv_order, dims):
232233
@staticmethod
233234
def _validate_fd_order(fd_order, expr, dims, dcounter):
234235
"""
235-
If provided `fd_order` must correspond to the provided dimensions.
236-
Required `expr`, `dims` and the derivative counter to validate.
237-
If not provided the maximum supported order will be used.
236+
If provided, `fd_order` must correspond to the provided dimensions.
237+
Required: `expr`, `dims`, and the derivative counter to validate.
238+
If not provided, the maximum supported order will be used.
238239
"""
239240
if fd_order is not None:
240-
# If `fd_order` is specified validate
241+
# If `fd_order` is specified, then validate
241242
fcounter = defaultdict(int)
242243
# First create a dictionary mapping variable wrt which to differentiate
243244
# to the `fd_order`
@@ -254,9 +255,8 @@ def _validate_fd_order(fd_order, expr, dims, dcounter):
254255
else:
255256
order = expr.space_order
256257
if o > order > 1:
257-
# Only handle cases greater than 2 since mumble
258+
# Only handle cases greater than 2 since <mumble>
258259
# interpolation and averaging
259-
# TODO: Check if this is sane
260260
raise ValueError(
261261
f'Function does not support {d}-derivative with `fd_order` {o}'
262262
)
@@ -338,11 +338,9 @@ def __call__(self, x0=None, fd_order=None, side=None, method=None, **kwargs):
338338

339339
return self._rebuild(**rkw)
340340

341-
def _rebuild(self, *args, **kwargs):
341+
def func(self, *args, **kwargs):
342342
return super()._rebuild(*args, **kwargs)
343343

344-
func = _rebuild
345-
346344
def _subs(self, old, new, **hints):
347345
# Basic case
348346
if self == old:
@@ -611,8 +609,8 @@ def _eval_expand_nest(self, **hints):
611609
# 2. Count the number of derivatives to take wrt each variable as well as
612610
# the finite difference order to use by iterating over the chained lists of
613611
# variables.
614-
new_deriv_order = tuple(chain(self.deriv_order, self.expr.deriv_order))
615-
new_fd_order = tuple(chain(self.fd_order, self.expr.fd_order))
612+
new_deriv_order = chain(self.deriv_order, self.expr.deriv_order)
613+
new_fd_order = chain(self.fd_order, self.expr.fd_order)
616614
dcounter = defaultdict(int)
617615
fcounter = defaultdict(int)
618616
for d, do, fo in zip(new_dims, new_deriv_order, new_fd_order, strict=True):

0 commit comments

Comments
 (0)