Skip to content

Commit

Permalink
camera iteration #1408
Browse files Browse the repository at this point in the history
Summary: Use IndexError so that a camera object is an iterable

Reviewed By: shapovalov

Differential Revision: D42312021

fbshipit-source-id: 67c417d5f1398e8b30a6944468eda057b4ceb444
  • Loading branch information
bottler authored and facebook-github-bot committed Jan 16, 2023
1 parent b7e3b7b commit 84851c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pytorch3d/renderer/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def __getitem__(
f"Boolean index of shape {index.shape} does not match cameras"
)
elif max(index) >= len(self):
raise ValueError(f"Index {max(index)} is out of bounds for select cameras")
raise IndexError(f"Index {max(index)} is out of bounds for select cameras")

for field in self._FIELDS:
val = getattr(self, field, None)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,11 @@ def test_join_batch_orthographic(self):
self.join_cameras_as_batch_fov(FoVOrthographicCameras)
self.join_cameras_as_batch(OrthographicCameras)

def test_iterable(self):
for camera_type in [PerspectiveCameras, OrthographicCameras]:
a_list = list(camera_type())
self.assertEqual(len(a_list), 1)


############################################################
# FoVPerspective Camera #
Expand Down Expand Up @@ -1009,7 +1014,7 @@ def test_getitem(self):
self.assertClose(c135.R, R_matrix[SLICE, ...])

# Check errors with get item
with self.assertRaisesRegex(ValueError, "out of bounds"):
with self.assertRaisesRegex(IndexError, "out of bounds"):
cam[N_CAMERAS]

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

0 comments on commit 84851c8

Please sign in to comment.