data.TensorDataset¶
Class Signature¶
class TensorDataset(*tensors_or_arrays: Tensor | _ArrayLike)
Parameters¶
tensors_or_arrays (Tensor | _ArrayLike): One or more Lucid tensors or array-like objects convertible to Lucid tensors. All must have equal length along the first axis. Scalars are not allowed.
Mathematical Shape Constraints¶
Let \(\{\mathbf{T}^{(k)}\}_{k=1}^K\) denote the tensors after conversion from array-likes, each with shape \((N, d_1^{(k)}, \dots, d_{m_k}^{(k)})\). The length of the dataset is \(N\) and the sample at index \(i\) is given by
Note
Array-like inputs are automatically converted to lucid.Tensor.
Warning
All tensors must share the same first-dimension size \(N\).
Returns¶
__len__ (int): Number of samples \(N\).
__getitem__ (tuple[Tensor, …]): Tuple of indexed tensors for the given index idx. Supported index types include int, slice, list, tuple, and lucid.Tensor (bool/int indexers).
Examples¶
import lucid
from lucid.data import TensorDataset
x = [[1, 2], [3, 4]] # array-like
y = lucid.arange(2)
ds = TensorDataset(x, y)
assert len(ds) == 2
x0, y0 = ds[0]
# Slice indexing
xb, yb = ds[:1]
# Move tensors to GPU (Metal/MLX)
ds.to("gpu")
Additional Notes¶
TensorDataset.to(device) moves all tensors to the specified device (“cpu” or “gpu”).
Indexing semantics follow
lucid.Tensor.Useful for pairing Lucid tensors or array-likes in supervised learning tasks.