Skip to main content

Module data

Module data 

Source
Expand description

Python bindings for torsh-data — Dataset and DataLoader APIs

Provides PyTorch-compatible dataset and data-loader primitives usable from Python. The bindings are deliberately concrete (no type-parameter leakage into Python) while still routing through the real torsh-data types wherever the API permits it.

§Design choices

  • PyDataset stores samples as Vec<Vec<f32>> (flat row-per-sample) so that it can implement torsh_data::Dataset and be passed to the real torsh_data::DataLoader::builder(). Each sample is exposed to Python as a Vec<f32>.

  • PyDataLoader owns a concrete SimpleDataLoader<PyDataset> or SimpleRandomDataLoader<PyDataset> depending on shuffle. Because these are different types we erase them behind a PyDataLoaderState enum so that a single #[pyclass] struct suffices.

  • Iteration is implemented on the Rust side via PyDataLoaderIter — a separate #[pyclass] that satisfies the __iter__/__next__ protocol.

Structs§

PyDataLoader
DataLoader wrapping a PyDataset with configurable batching and shuffling.
PyDataLoaderIter
Python iterator that steps through pre-materialised batches.
PyDataset
In-memory dataset of f32 sample rows exposed to Python.

Functions§

register_data_module
Register the data sub-module into the parent module m.