camera iteration #1408

Summary: Use IndexError so that a camera object is an iterable

Reviewed By: shapovalov

Differential Revision: D42312021

fbshipit-source-id: 67c417d5f1398e8b30a6944468eda057b4ceb444
This commit is contained in:
Jeremy Reizenstein 2023-01-16 08:52:52 -08:00 committed by Facebook GitHub Bot
parent b7e3b7b16c
commit 84851c8312
2 changed files with 7 additions and 2 deletions

View File

@ -432,7 +432,7 @@ class CamerasBase(TensorProperties):
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)

View File

@ -866,6 +866,11 @@ class TestCamerasCommon(TestCaseMixin, unittest.TestCase):
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 #
@ -1009,7 +1014,7 @@ class TestFoVPerspectiveProjection(TestCaseMixin, unittest.TestCase):
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"):