Skip to content

Commit ccdfd11

Browse files
committed
Standardize shape validation for PointSetOperatorBC
1 parent 91bda9a commit ccdfd11

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

deepxde/icbc/boundary_conditions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,17 @@ class PointSetOperatorBC:
257257

258258
def __init__(self, points, values, func, batch_size=None, shuffle=True):
259259
self.points = np.array(points, dtype=config.real(np))
260-
if not isinstance(values, numbers.Number) and values.shape[1] != 1:
261-
raise RuntimeError("PointSetOperatorBC should output 1D values")
260+
if not isinstance(values, numbers.Number):
261+
values_arr = np.asarray(values)
262+
if values_arr.ndim != 2 or values_arr.shape[1] != 1:
263+
raise RuntimeError(
264+
f"PointSetOperatorBC received values of shape {values_arr.shape}, "
265+
f"expected 2D array of shape (N, 1)."
266+
)
267+
if values_arr.shape[0] != len(self.points):
268+
raise RuntimeError(
269+
f"PointSetOperatorBC received {len(self.points)} points but {values_arr.shape[0]} values."
270+
)
262271
self.values = bkd.as_tensor(values, dtype=config.real(bkd.lib))
263272
self.func = func
264273
self.batch_size = batch_size

0 commit comments

Comments
 (0)