Skip to main content

Sampler

Trait Sampler 

Source
pub trait Sampler: Send {
    type Iter: Iterator<Item = usize> + Send;

    // Required methods
    fn iter(&self) -> Self::Iter;
    fn len(&self) -> usize;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn into_batch_sampler(
        self,
        batch_size: usize,
        drop_last: bool,
    ) -> BatchingSampler<Self>
       where Self: Sized { ... }
    fn into_distributed(
        self,
        num_replicas: usize,
        rank: usize,
    ) -> DistributedWrapper<Self>
       where Self: Sized { ... }
}
Expand description

Unified trait for sampling from a dataset

This trait provides a consistent interface for both individual sample and batch sampling strategies.

Required Associated Types§

Source

type Iter: Iterator<Item = usize> + Send

Iterator type returned by the sampler

Required Methods§

Source

fn iter(&self) -> Self::Iter

Create an iterator over indices

Source

fn len(&self) -> usize

Total number of samples that will be yielded

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if sampler is empty

Source

fn into_batch_sampler( self, batch_size: usize, drop_last: bool, ) -> BatchingSampler<Self>
where Self: Sized,

Convert this sampler into a batch sampler

Source

fn into_distributed( self, num_replicas: usize, rank: usize, ) -> DistributedWrapper<Self>
where Self: Sized,

Create a distributed version of this sampler

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§