Skip to content

Commit 84851c8

Browse files
bottlerfacebook-github-bot
authored andcommitted
camera iteration #1408
Summary: Use IndexError so that a camera object is an iterable Reviewed By: shapovalov Differential Revision: D42312021 fbshipit-source-id: 67c417d5f1398e8b30a6944468eda057b4ceb444
1 parent b7e3b7b commit 84851c8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pytorch3d/renderer/cameras.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def __getitem__(
432432
f"Boolean index of shape {index.shape} does not match cameras"
433433
)
434434
elif max(index) >= len(self):
435-
raise ValueError(f"Index {max(index)} is out of bounds for select cameras")
435+
raise IndexError(f"Index {max(index)} is out of bounds for select cameras")
436436

437437
for field in self._FIELDS:
438438
val = getattr(self, field, None)

tests/test_cameras.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,11 @@ def test_join_batch_orthographic(self):
866866
self.join_cameras_as_batch_fov(FoVOrthographicCameras)
867867
self.join_cameras_as_batch(OrthographicCameras)
868868

869+
def test_iterable(self):
870+
for camera_type in [PerspectiveCameras, OrthographicCameras]:
871+
a_list = list(camera_type())
872+
self.assertEqual(len(a_list), 1)
873+
869874

870875
############################################################
871876
# FoVPerspective Camera #
@@ -1009,7 +1014,7 @@ def test_getitem(self):
10091014
self.assertClose(c135.R, R_matrix[SLICE, ...])
10101015

10111016
# Check errors with get item
1012-
with self.assertRaisesRegex(ValueError, "out of bounds"):
1017+
with self.assertRaisesRegex(IndexError, "out of bounds"):
10131018
cam[N_CAMERAS]
10141019

10151020
with self.assertRaisesRegex(ValueError, "does not match cameras"):

0 commit comments

Comments
 (0)