Skip to content

Commit 026b0ef

Browse files
committed
review comments
1 parent d15720d commit 026b0ef

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

firedrake/slate/slate.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,54 +336,48 @@ def __add__(self, other):
336336
other = as_slate(other)
337337
return Add(self, other)
338338
except TypeError:
339-
raise NotImplementedError("Type(s) for + not supported: '%s' '%s'"
340-
% (type(self), type(other)))
339+
return NotImplemented
341340

342341
def __radd__(self, other):
343342
# If other cannot be converted into a TensorBase, raise NotImplementedError.
344343
# Otherwise, delegate action to other.
345344
try:
346345
other = as_slate(other)
347-
return other.__add__(self)
346+
return other + self
348347
except TypeError:
349-
raise NotImplementedError("Type(s) for + not supported: '%s' '%s'"
350-
% (type(other), type(self)))
348+
return NotImplemented
351349

352350
def __sub__(self, other):
353351
try:
354352
other = as_slate(other)
355353
return Add(self, Negative(other))
356354
except TypeError:
357-
raise NotImplementedError("Type(s) for - not supported: '%s' '%s'"
358-
% (type(self), type(other)))
355+
return NotImplemented
359356

360357
def __rsub__(self, other):
361358
# If other cannot be converted into a TensorBase, raise NotImplementedError.
362359
# Otherwise, delegate action to other.
363360
try:
364361
other = as_slate(other)
365-
return other.__sub__(self)
362+
return other - self
366363
except TypeError:
367-
raise NotImplementedError("Type(s) for - not supported: '%s' '%s'"
368-
% (type(other), type(self)))
364+
return NotImplemented
369365

370366
def __mul__(self, other):
371367
try:
372368
other = as_slate(other)
373369
return Mul(self, other)
374370
except TypeError:
375-
raise NotImplementedError("Type(s) for * not supported: '%s' '%s'"
376-
% (type(self), type(other)))
371+
return NotImplemented
377372

378373
def __rmul__(self, other):
379374
# If other cannot be converted into a TensorBase, raise NotImplementedError.
380375
# Otherwise, delegate action to other.
381376
try:
382377
other = as_slate(other)
383-
return other.__mul__(self)
378+
return other * self
384379
except TypeError:
385-
raise NotImplementedError("Type(s) for * not supported: '%s' '%s'"
386-
% (type(other), type(self)))
380+
return NotImplemented
387381

388382
def __neg__(self):
389383
return Negative(self)

firedrake/variational_solver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def compute_bc_lifting(J, u):
136136
"""Return the action of the bilinear form J (without bcs) on a Function u."""
137137
if isinstance(J, MatrixBase) and J.has_bcs:
138138
# Extract the full form without bcs
139+
if not isinstance(J.a, (ufl.BaseForm, slate.slate.TensorBase)):
140+
raise TypeError(f"Could not remove bcs from {type(J).__name__}.")
139141
J = J.a
140142
return ufl_expr.action(J, u)
141143

0 commit comments

Comments
 (0)