View into a parent dataset restricted to a list of indices.
Useful for train/val splits, k-fold cross-validation, or any time a contiguous subset of a larger dataset is needed without copying the underlying data.
Parameters
datasetDatasetParent dataset to view into.
indiceslist of intIndices into
dataset that compose this subset. Order is
preserved; duplicates are allowed.Notes
A Subset is purely an index-restricted view — the parent
dataset is held by reference and no sample is copied. Subsets may
be nested freely (a Subset of a Subset) because
the parent only needs to satisfy the map-style protocol.
Examples
>>> import lucid
>>> from lucid.utils.data import Subset, TensorDataset
>>> X, y = lucid.randn(100, 4), lucid.zeros(100)
>>> full = TensorDataset(X, y)
>>> train = Subset(full, list(range(0, 80)))
>>> val = Subset(full, list(range(80, 100)))
>>> len(train), len(val)
(80, 20)Used by 1
Constructors
1Dunder methods
2Return the number of indices in the subset.