pub struct DataLoader<D, S, C> { /* private fields */ }Expand description
DataLoader for batching and iterating over datasets
The DataLoader provides an efficient way to iterate over datasets in batches, with support for parallel loading, shuffling, and various optimization strategies.
§Type Parameters
D: Dataset type implementing the Dataset traitS: Sampler type implementing the BatchSampler traitC: Collate function type implementing the Collate trait
§Examples
ⓘ
use torsh_data::dataloader::core::DataLoader;
use torsh_data::dataset::TensorDataset;
let dataset = TensorDataset::new(vec![1, 2, 3, 4, 5]);
let dataloader = DataLoader::builder(dataset)
.batch_size(2)
.num_workers(4)
.build()?;
for batch in dataloader.iter() {
// Process batch
}Implementations§
Source§impl<D: Dataset> DataLoader<D, (), ()>
impl<D: Dataset> DataLoader<D, (), ()>
Sourcepub fn builder(dataset: D) -> DataLoaderBuilder<D>
pub fn builder(dataset: D) -> DataLoaderBuilder<D>
Source§impl<D, S, C> DataLoader<D, S, C>
impl<D, S, C> DataLoader<D, S, C>
Sourcepub fn iter(&self) -> DataLoaderIterator<'_, D, S, C> ⓘ
pub fn iter(&self) -> DataLoaderIterator<'_, D, S, C> ⓘ
Create an iterator over the dataset
Returns a DataLoaderIterator that will yield batches according to the configured sampler and collation function.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of batches
Returns the total number of batches that will be produced by this DataLoader, based on the underlying sampler’s batch count.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the dataloader is empty
Returns true if the DataLoader will produce zero batches.
Sourcepub fn collate_fn(&self) -> &C
pub fn collate_fn(&self) -> &C
Get the collate function
Sourcepub fn num_workers(&self) -> usize
pub fn num_workers(&self) -> usize
Get the number of workers
Trait Implementations§
Source§impl<D, S, C> DataLoaderTrait<D, C> for DataLoader<D, S, C>
impl<D, S, C> DataLoaderTrait<D, C> for DataLoader<D, S, C>
Auto Trait Implementations§
impl<D, S, C> Freeze for DataLoader<D, S, C>
impl<D, S, C> RefUnwindSafe for DataLoader<D, S, C>
impl<D, S, C> Send for DataLoader<D, S, C>
impl<D, S, C> Sync for DataLoader<D, S, C>
impl<D, S, C> Unpin for DataLoader<D, S, C>
impl<D, S, C> UnsafeUnpin for DataLoader<D, S, C>
impl<D, S, C> UnwindSafe for DataLoader<D, S, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.