Struct ai_dataloader::indexable::sampler::BatchSampler
source · pub struct BatchSampler<S = SequentialSampler> {
pub sampler: S,
pub batch_size: usize,
pub drop_last: bool,
}Expand description
Wraps another sampler to yield a mini-batch of indices.
Arguments
sampler- Base sampler.batch_size- Size of mini-batch.drop_last- Iftrue, the sampler will drop the last batch if its size would be less thanbatch_size.
Examples:
use ai_dataloader::sampler::SequentialSampler;
use ai_dataloader::sampler::BatchSampler;
let dataset = vec![0, 1, 2, 3];
let batch_sampler = BatchSampler {
sampler: SequentialSampler {
data_source_len: dataset.len(),
},
batch_size: 2,
drop_last: false,
};
let mut iter = batch_sampler.iter();
assert_eq!(iter.next(), Some(vec![0, 1]));
assert_eq!(iter.next(), Some(vec![2, 3]));Fields§
§sampler: SBase sampler.
batch_size: usizeSize of mini batch.
drop_last: boolIf true, the sampler will drop the last batch if
its size were less than batch_size.
Implementations§
source§impl<S: Sampler> BatchSampler<S>
impl<S: Sampler> BatchSampler<S>
sourcepub fn iter(&self) -> BatchIterator<S::IntoIter> ⓘ
pub fn iter(&self) -> BatchIterator<S::IntoIter> ⓘ
Return an iterator over the BatchSampler.
Trait Implementations§
source§impl<S: Clone> Clone for BatchSampler<S>
impl<S: Clone> Clone for BatchSampler<S>
source§fn clone(&self) -> BatchSampler<S>
fn clone(&self) -> BatchSampler<S>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<S: Debug> Debug for BatchSampler<S>
impl<S: Debug> Debug for BatchSampler<S>
source§impl<S: Hash> Hash for BatchSampler<S>
impl<S: Hash> Hash for BatchSampler<S>
source§impl<S: Sampler> Len for BatchSampler<S>
impl<S: Sampler> Len for BatchSampler<S>
source§impl<S: Ord> Ord for BatchSampler<S>
impl<S: Ord> Ord for BatchSampler<S>
source§fn cmp(&self, other: &BatchSampler<S>) -> Ordering
fn cmp(&self, other: &BatchSampler<S>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<S: PartialEq> PartialEq<BatchSampler<S>> for BatchSampler<S>
impl<S: PartialEq> PartialEq<BatchSampler<S>> for BatchSampler<S>
source§fn eq(&self, other: &BatchSampler<S>) -> bool
fn eq(&self, other: &BatchSampler<S>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl<S: PartialOrd> PartialOrd<BatchSampler<S>> for BatchSampler<S>
impl<S: PartialOrd> PartialOrd<BatchSampler<S>> for BatchSampler<S>
source§fn partial_cmp(&self, other: &BatchSampler<S>) -> Option<Ordering>
fn partial_cmp(&self, other: &BatchSampler<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl<S: Eq> Eq for BatchSampler<S>
impl<S> StructuralEq for BatchSampler<S>
impl<S> StructuralPartialEq for BatchSampler<S>
Auto Trait Implementations§
impl<S> RefUnwindSafe for BatchSampler<S>where S: RefUnwindSafe,
impl<S> Send for BatchSampler<S>where S: Send,
impl<S> Sync for BatchSampler<S>where S: Sync,
impl<S> Unpin for BatchSampler<S>where S: Unpin,
impl<S> UnwindSafe for BatchSampler<S>where S: UnwindSafe,
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