Skip to content

Commit

Permalink
Merge pull request #2322 from devitocodes/weights-value
Browse files Browse the repository at this point in the history
compiler: Add Weights.value utility
  • Loading branch information
FabioLuporini authored Feb 28, 2024
2 parents 0dbe9c1 + 3b00540 commit 65002b6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,24 @@ def _xreplace(self, rule):
pass
return super()._xreplace(rule)

@cached_property
def _npweights(self):
# NOTE: `self.weights` cannot just be an array or SymPy will fail
# internally at `__eq__` since numpy arrays requite .all, not ==,
# for equality comparison
return np.array(self.weights)

def value(self, idx):
try:
v = self.weights[idx]
except TypeError:
# E.g., `idx` is a tuple
v = self._npweights[idx]
if v.is_Number:
return sympy.sympify(v)
else:
return self[idx]


class IndexDerivative(IndexSum):

Expand Down

0 comments on commit 65002b6

Please sign in to comment.