diff --git a/devito/deprecations.py b/devito/deprecations.py new file mode 100644 index 0000000000..17f61b0cf0 --- /dev/null +++ b/devito/deprecations.py @@ -0,0 +1,15 @@ +from functools import cached_property +from warnings import warn + + +class DevitoDeprecation(): + + @cached_property + def coeff_warn(self): + warn("The Coefficient API is deprecated and will be removed, coefficients should" + "be passed directly to the derivative object `u.dx(weights=...)", + DeprecationWarning, stacklevel=2) + return + + +deprecations = DevitoDeprecation() diff --git a/devito/finite_differences/coefficients.py b/devito/finite_differences/coefficients.py index ba7e9ea800..543bb5c9ba 100644 --- a/devito/finite_differences/coefficients.py +++ b/devito/finite_differences/coefficients.py @@ -1,13 +1,11 @@ -from warnings import warn +from devito.deprecations import deprecations __all__ = ['Coefficient', 'Substitutions'] class Coefficient: def __init__(self, deriv_order, function, dimension, weights): - warn("The Coefficient API is deprecated and will be removed, coefficients should" - "be passed directly to the derivative object `u.dx(weights=...)", - DeprecationWarning, stacklevel=2) + deprecations.coeff_warn self._weights = weights self._deriv_order = deriv_order self._function = function @@ -36,9 +34,7 @@ def weights(self): class Substitutions: def __init__(self, *args): - warn("The Coefficient API is deprecated and will be removed, coefficients should" - "be passed directly to the derivative object `u.dx(weights=...)", - DeprecationWarning, stacklevel=2) + deprecations.coeff_warn if any(not isinstance(arg, Coefficient) for arg in args): raise TypeError("Non Coefficient object within input") diff --git a/devito/finite_differences/tools.py b/devito/finite_differences/tools.py index 1e40e847f9..31538e0e3f 100644 --- a/devito/finite_differences/tools.py +++ b/devito/finite_differences/tools.py @@ -278,7 +278,10 @@ def generate_indices(expr, dim, order, side=None, matvec=None, x0=None, nweights o_min -= 1 if nweights > 0 and (o_max - o_min + 1) != nweights: + # We cannot infer how the stencil should be centered + # if nweights is more than one extra point. assert nweights == (o_max - o_min + 1) + 1 + # In the "one extra" case we need to pad with one point to symmetrize if (o_max - mid) > (mid - o_min): o_min -= 1 else: diff --git a/devito/types/equation.py b/devito/types/equation.py index e7405a8bb5..546c2c4e96 100644 --- a/devito/types/equation.py +++ b/devito/types/equation.py @@ -1,8 +1,7 @@ """User API to specify equations.""" -from warnings import warn - import sympy +from devito.deprecations import deprecations from devito.tools import as_tuple, frozendict from devito.types.lazy import Evaluable @@ -64,15 +63,14 @@ class Eq(sympy.Eq, Evaluable): def __new__(cls, lhs, rhs=0, subdomain=None, coefficients=None, implicit_dims=None, **kwargs): if coefficients is not None: - warn("The Substitution API is deprecated and will be removed, " - "coefficients should be passed directly to the derivative object" - " i.e `u.dx(weights=...)", - DeprecationWarning, stacklevel=2) + deprecations.coeff_warn kwargs['evaluate'] = False - # Backward compat + # Backward compatibility rhs = cls._apply_coeffs(rhs, coefficients) lhs = cls._apply_coeffs(lhs, coefficients) + obj = sympy.Eq.__new__(cls, lhs, rhs, **kwargs) + obj._subdomain = subdomain obj._substitutions = coefficients obj._implicit_dims = as_tuple(implicit_dims) @@ -82,7 +80,7 @@ def __new__(cls, lhs, rhs=0, subdomain=None, coefficients=None, implicit_dims=No @classmethod def _apply_coeffs(cls, expr, coefficients): """ - This process legacy API of Substitution/Coefficients applying the weights + This processes legacy API of Substitution/Coefficients applying the weights to the target Derivatives. """ from devito.symbolics import retrieve_derivatives