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

compiler: Add Weights.value utility #2322

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
compiler: Add Weights.value utility
  • Loading branch information
FabioLuporini committed Feb 27, 2024
commit 3b0054088bb27ebb8b687f7e9310384bf5a8ca7f
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break into two sentences? Reads a bit weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do in nxt pr

# 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
Loading