From 84851c8312a709a95215d36adc103f7af97d5b5f Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Mon, 16 Jan 2023 08:52:52 -0800 Subject: [PATCH] camera iteration #1408 Summary: Use IndexError so that a camera object is an iterable Reviewed By: shapovalov Differential Revision: D42312021 fbshipit-source-id: 67c417d5f1398e8b30a6944468eda057b4ceb444 --- pytorch3d/renderer/cameras.py | 2 +- tests/test_cameras.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index f130dbc0..22df74a8 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -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) diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 743ba14e..043d6d51 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -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"):