Skip to content

Commit 2df5795

Browse files
committed
Speedup Polygon.random_points()
1 parent 21b33c7 commit 2df5795

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

deepxde/geometry/geometry_2d.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,12 @@ def boundary_normal(self, x):
431431
return np.array([0, 0])
432432

433433
def random_points(self, n, random="pseudo"):
434-
x = []
434+
x = np.empty((0, 2))
435435
vbbox = self.bbox[1] - self.bbox[0]
436436
while len(x) < n:
437-
x_new = np.random.rand(1, 2) * vbbox + self.bbox[0]
438-
if self.inside(x_new):
439-
x.append(x_new)
440-
return np.vstack(x)
437+
x_new = np.random.rand(n, 2) * vbbox + self.bbox[0]
438+
x = np.vstack((x, x_new[self.inside(x_new)]))
439+
return x[:n]
441440

442441
def uniform_boundary_points(self, n):
443442
density = n / self.perimeter

0 commit comments

Comments
 (0)