Skip to content

Commit 8662f13

Browse files
committed
refactor(transforms): improve error handling
1 parent 24d17fe commit 8662f13

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/aidsorb/transforms.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -318,25 +318,24 @@ class RandomErase:
318318
>>> erase = RandomErase(n_points=100)
319319
>>> erase(pcd)
320320
Traceback (most recent call last):
321-
..
322-
ValueError: resulting point cloud has no points
321+
...
322+
RuntimeError: resulting point cloud has no points
323323
"""
324324
def __init__(self, n_points):
325+
if n_points < 0:
326+
raise ValueError("'n_points' can't be negative")
325327
self.n_points = n_points
326328

327329
def __call__(self, pcd):
328330
check_shape(pcd)
329331

330-
if self.n_points < 0:
331-
raise ValueError("'n_points' can't be negative")
332-
333332
if 0 < self.n_points < 1:
334333
keep_size = len(pcd) - int(len(pcd) * self.n_points)
335334
else:
336335
keep_size = len(pcd) - self.n_points
337336

338337
if keep_size < 1:
339-
raise ValueError('resulting point cloud has no points')
338+
raise RuntimeError('resulting point cloud has no points')
340339

341340
# Indices of points to keep.
342341
indices = torch.randperm(len(pcd))[:keep_size]
@@ -369,14 +368,13 @@ class RandomSample:
369368
True
370369
"""
371370
def __init__(self, size):
371+
if size < 0:
372+
raise ValueError("'size' can't be negative")
372373
self.size = size
373374

374375
def __call__(self, pcd):
375376
check_shape(pcd)
376377

377-
if self.size < 0:
378-
raise ValueError("'size' can't be negative")
379-
380378
if self.size >= len(pcd):
381379
return pcd
382380

0 commit comments

Comments
 (0)