Bundle several map-style datasets so each index returns a stacked tuple.
The bundled datasets must agree in length. Item i is the tuple
(d_1[i], d_2[i], \dots, d_K[i]) for each child dataset — handy
when paired modalities (image, caption, label) live in separate
sources but share a common index.
Accepts either positional children (StackDataset(d1, d2)) or
keyword children (StackDataset(image=d1, label=d2)); the two
forms are mutually exclusive. Positional construction returns
tuples; keyword construction returns dicts keyed by the supplied
names.
Parameters
Notes
Equivalent in spirit to a per-index zip across child datasets,
but exposed as a Dataset so it can drive a sampler-based
DataLoader. All children must satisfy len(d_k) == n
for some shared n; otherwise construction raises ValueError.
Examples
>>> import lucid
>>> from lucid.utils.data import StackDataset, TensorDataset
>>> X_img, y_lbl = lucid.randn(8, 3, 4, 4), lucid.randint(0, 10, (8,))
>>> images = TensorDataset(X_img)
>>> labels = TensorDataset(y_lbl)
>>> ds = StackDataset(image=images, label=labels)
>>> sample = ds[0]
>>> sorted(sample.keys())
['image', 'label']Used by 1
Constructors
1Bundle child datasets either positionally or by keyword.
Parameters
Raises
ValueErrorDunder methods
2Return one sample drawn from each child at index idx.
Parameters
idxintReturns
tuple or dictA tuple of child samples if the dataset was built positionally, otherwise a dict keyed by the keyword names supplied at construction time.
Return the common length shared by all bundled child datasets.