Trait Dataset

Source
pub trait Dataset {
    type Item;

    // Required methods
    fn len(&self) -> usize;
    fn get(&self, index: usize) -> Self::Item;

    // Provided methods
    fn cached(self, cache_dir: impl Into<PathBuf>) -> CachedDataset<Self>
       where Self: Sized { ... }
    fn iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> { ... }
}
Expand description

Generic Dataset trait, modeled after PyTorch’s utils.data.Dataset. It represents a collection of objects indexed in the range 0..len().

Required Associated Types§

Source

type Item

The type of objects procured by the Dataset.

Required Methods§

Source

fn len(&self) -> usize

The number of objects in the Dataset.

Source

fn get(&self, index: usize) -> Self::Item

Get the index’th element, where 0 <= index < len()

Provided Methods§

Source

fn cached(self, cache_dir: impl Into<PathBuf>) -> CachedDataset<Self>
where Self: Sized,

Modifies the dataset to check a cache directory before reading. If the cache entry is present, it’s used instead of the underlying get(). If the cache entry is absent, it will be created after calling get().

Source

fn iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_>

Produces an Iterator that produces the entire Dataset in indexed order.

Implementations on Foreign Types§

Source§

impl<D: Dataset + ?Sized> Dataset for &D

References to Datasets are also Datasets.

Source§

type Item = <D as Dataset>::Item

Source§

fn len(&self) -> usize

Source§

fn get(&self, index: usize) -> Self::Item

Source§

impl<D: Dataset + ?Sized> Dataset for Box<D>

Source§

type Item = <D as Dataset>::Item

Source§

fn len(&self) -> usize

Source§

fn get(&self, index: usize) -> Self::Item

Source§

impl<T: Clone> Dataset for [T]

A slice can act as an in-memory Dataset.

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn get(&self, index: usize) -> T

Implementors§

Source§

impl<D: Dataset> Dataset for CachedDataset<D>

Source§

type Item = <D as Dataset>::Item

Source§

impl<T, F: Fn(usize) -> T> Dataset for ClosureDataset<T, F>

Source§

type Item = T