class
Sampler
Sampler()Abstract base class for index samplers used by DataLoader.
A sampler iterates over integer indices into a map-style dataset.
Subclasses must implement __iter__ (yielding indices) and
__len__ (total number of indices produced per epoch).
Notes
Samplers decouple which samples are visited from how they are
fetched — the dataset answers __getitem__(i) and the sampler
decides the sequence of i values. This separation is what lets
DataLoader swap iteration policies (sequential / random /
weighted / distributed) without touching the dataset.
Examples
>>> class Even(Sampler):
... def __init__(self, n): self.n = n
... def __iter__(self): return iter(range(0, self.n, 2))
... def __len__(self): return (self.n + 1) // 2
>>> list(Even(6))
[0, 2, 4]