pub struct RandomSampler { /* private fields */ }Expand description
順列でバッチ添字を供給する(PyTorch RandomSampler 相当。イシュー
#2182)。同一の manual_seed の下で DataLoader{shuffle=true} と
添字順が bit 完全一致する(start_epoch
が shuffled_indices を 1 回の crate::rng::with_global_rng
クロージャ内で呼ぶため)。
Implementations§
Source§impl RandomSampler
impl RandomSampler
Sourcepub fn new(
len: usize,
batch_size: usize,
drop_last: bool,
) -> Result<RandomSampler, DataError>
pub fn new( len: usize, batch_size: usize, drop_last: bool, ) -> Result<RandomSampler, DataError>
batch_size == 0 は DataError::ZeroBatchSize。
Trait Implementations§
Source§impl Debug for RandomSampler
impl Debug for RandomSampler
Source§impl Sampler for RandomSampler
impl Sampler for RandomSampler
Source§fn next_batch(&mut self) -> Vec<usize>
fn next_batch(&mut self) -> Vec<usize>
次バッチの添字列。空の
Vec は epoch 終了の番兵。Source§fn num_batches(&self) -> Option<usize>
fn num_batches(&self) -> Option<usize>
1 epoch あたりのバッチ数(既知なら
Some。既定は None)。
SamplerBatches::size_hint・HookedBatches::size_hint は
本メソッドの戻り値(epoch 全体の静的総数)と、各イテレータ自身が
追跡する「これまでに yield した数」の差分で残数を計算する
(レビュー指摘: イシュー #2182 review・PR #2310 codex-review
P2 是正)。カスタム Sampler 実装が進捗追跡用の別メソッドを
override する必要はなく、本メソッドだけを実装すれば途中経過・
epoch 終了後のどちらでも Iterator::size_hint の「残り要素数」
契約(下限の非過大申告)を満たす。Auto Trait Implementations§
impl Freeze for RandomSampler
impl RefUnwindSafe for RandomSampler
impl Send for RandomSampler
impl Sync for RandomSampler
impl Unpin for RandomSampler
impl UnsafeUnpin for RandomSampler
impl UnwindSafe for RandomSampler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more