I’m trying to do list(dataset) but it returns more than expected. In some setups it runs out of bounds. Sample code:
from torch.utils.data import Dataset

class NumbersDataset(Dataset):
    def __init__(self):
        self.samples = list(range(1, 1001))

    def __len__(self):
        return len(self.samples)-500

    def __getitem__(self, idx):
        return self.samples[idx]


dataset = NumbersDataset()

len(dataset)
> 500

len(list(dataset))
> 1000

I would expect list(dataset) to return 500, but somehow this is ignored.
The same problem happens when you iterate over the dataset with for loop.
I mean how does it even know that there are 1000 elements? 
Any ideas?