Skip to main content

DataLoader

Struct DataLoader 

Source
pub struct DataLoader<'ds> { /* private fields */ }
Expand description

Stateful batch iterator over a borrowed Dataset.

Corresponds to oa::DataLoader.

Implementations§

Source§

impl DataLoader<'static>

Source

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.

Source

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>

Source

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.

Source

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.

Source

pub fn reset(&mut self) -> Result<()>

Reset the epoch, rebuilding its index order from the configured seed.

Nonzero seeds reproduce the same order on every reset, matching the donor.

§Errors

Returns the index-building errors described by Self::new. A failed reset leaves the existing order and cursor unchanged.

Source

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.

Source

pub fn num_batches(&self) -> i64

Number of batches in the current epoch.

Source

pub fn current_batch(&self) -> i64

Index of the next batch that will be returned.

Source

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.

Auto Trait Implementations§

§

impl<'ds> !RefUnwindSafe for DataLoader<'ds>

§

impl<'ds> !Send for DataLoader<'ds>

§

impl<'ds> !Sync for DataLoader<'ds>

§

impl<'ds> !UnwindSafe for DataLoader<'ds>

§

impl<'ds> Forget for DataLoader<'ds>

§

impl<'ds> Freeze for DataLoader<'ds>
where &'ds dyn Dataset: Freeze, *const dyn Dataset + 'ds is !null: Freeze, PhantomData<dyn Dataset + 'ds>: Freeze, *const u8 is !null: Freeze, PhantomData<i64>: Freeze,

§

impl<'ds> Move for DataLoader<'ds>

§

impl<'ds> Unpin for DataLoader<'ds>
where &'ds dyn Dataset: Unpin, Box<dyn Dataset + 'ds>: Unpin, *const u8 is !null: Unpin,

§

impl<'ds> UnsafeUnpin for DataLoader<'ds>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.