pub struct DataLoader<'ds> { /* private fields */ }Expand description
Stateful batch iterator over a borrowed Dataset.
Corresponds to oa::DataLoader.
Implementations§
Source§impl DataLoader<'static>
impl DataLoader<'static>
Sourcepub fn classification(
runtime: &Runtime,
input: Matrix,
labels: Vec<u32>,
config: DataLoaderConfig,
) -> Result<Self>
pub fn classification( runtime: &Runtime, input: Matrix, labels: Vec<u32>, config: DataLoaderConfig, ) -> Result<Self>
Batch dense FP32 inputs and host class indices with one device row gather.
The input is [N, ...]. Each output target is a U32 vector with one
class index per sample. Shuffle, epoch seeds and partial batches follow
the ordinary loader configuration.
§Errors
Returns an error for invalid shape, count, runtime ownership or loader configuration.
Sourcepub fn classification_subset(
runtime: &Runtime,
input: Matrix,
start: usize,
labels: Vec<u32>,
config: DataLoaderConfig,
) -> Result<Self>
pub fn classification_subset( runtime: &Runtime, input: Matrix, start: usize, labels: Vec<u32>, config: DataLoaderConfig, ) -> Result<Self>
Batch a contiguous subset of a shared dense input without copying the split.
Labels correspond to the rows beginning at start. Shuffle and epoch
reset apply to those rows only.
§Errors
Returns an error for invalid shape, range, runtime ownership, or loader configuration.
Source§impl<'ds> DataLoader<'ds>
impl<'ds> DataLoader<'ds>
Sourcepub fn new(dataset: &'ds dyn Dataset, config: DataLoaderConfig) -> Result<Self>
pub fn new(dataset: &'ds dyn Dataset, config: DataLoaderConfig) -> Result<Self>
Construct a data loader and build the initial index order.
§Errors
Returns an error for a non-positive batch size, a negative dataset length, index allocation failure, or an unavailable clock for seed zero.
Sourcepub fn next_batch(&mut self) -> Result<Option<Batch>>
pub fn next_batch(&mut self) -> Result<Option<Batch>>
Advance to the next batch; None means the epoch is exhausted.
§Errors
Sample and collation failures are propagated without dropping samples or advancing the batch cursor. A caller may retry or explicitly reset.
Sourcepub fn reset_epoch(&mut self, epoch: u64) -> Result<()>
pub fn reset_epoch(&mut self, epoch: u64) -> Result<()>
Reset for a new data pass, deriving the shuffle order from the
configured seed mixed with the epoch number so each epoch iterates a
different deterministic order — the equivalent of reshuffling a
dataset between epochs. reset_epoch(0) reproduces Self::reset.
§Errors
Returns the index-building errors described by Self::new. A failed
reset leaves the existing order and cursor unchanged.
Sourcepub fn num_batches(&self) -> i64
pub fn num_batches(&self) -> i64
Number of batches in the current epoch.
Sourcepub fn current_batch(&self) -> i64
pub fn current_batch(&self) -> i64
Index of the next batch that will be returned.
Sourcepub fn seek(&mut self, epoch: u64, cursor: i64) -> Result<()>
pub fn seek(&mut self, epoch: u64, cursor: i64) -> Result<()>
Restore a recorded loader position: rebuild the deterministic shuffle
order for epoch exactly as Self::reset_epoch would, then place the
batch cursor at cursor. Together with the configured seed this
reproduces the exact sample sequence a checkpointed run would have
consumed next, which is the loader half of exact training resume.
cursor may equal the epoch’s batch count, denoting an exhausted epoch.
§Errors
Returns the index-building errors described by Self::new, or an
invalid-argument error when cursor exceeds the epoch’s batch count.
A failed seek leaves the existing order and cursor unchanged.