Skip to content

Commit 138b5c2

Browse files
willfreyfmassa
authored andcommitted
Update fakedata.py (#780)
Raise an `IndexError` for `FakeData.__getitem__()` if the index would be out of range.
1 parent ef6e9af commit 138b5c2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

torchvision/datasets/fakedata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __getitem__(self, index):
3737
tuple: (image, target) where target is class_index of the target class.
3838
"""
3939
# create random image that is consistent with the index id
40+
if index >= len(self):
41+
raise IndexError("{} index out of range".format(self.__class__.__name__))
4042
rng_state = torch.get_rng_state()
4143
torch.manual_seed(index + self.random_offset)
4244
img = torch.randn(*self.image_size)

0 commit comments

Comments
 (0)