fn
default_convert
→objectdefault_convert(data: object)Recursively convert a single sample's elements to Lucid Tensors.
The inverse-flavour partner of default_collate:
default_collate stacks a batch list into batched tensors,
while default_convert walks a single sample (possibly
nested in lists / tuples / dicts / named tuples) and turns leaf
ndarrays / Python scalars into Tensor leaves. Existing
Tensors / strings / bytes pass through unchanged.
Parameters
dataobjectA sample, possibly nested. Supported leaf types are
Tensor, np.ndarray, int, float, bool,
str, and bytes. Container types dict, list,
tuple, and NamedTuple are walked recursively and their
original type is preserved.Returns
objectSame nested structure as data with leaf ndarrays / scalars
promoted to Tensor.
Notes
Used by DataLoader when a dataset returns numpy arrays per
sample but the user wants Tensor leaves before collation. Numpy
is imported lazily — this is one of the H4 bridge boundaries
(external data ingest).
Examples
>>> default_convert({"x": 1.5, "y": [1, 2]})
{'x': <Tensor ...>, 'y': [<Tensor ...>, <Tensor ...>]}