Skip to main content

RandomSampler

Struct RandomSampler 

Source
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

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Sampler for RandomSampler

Source§

fn start_epoch(&mut self) -> Result<(), DataError>

epoch 開始時に 1 回呼ぶ。抽選を伴う実装はここで確定させる。
Source§

fn next_batch(&mut self) -> Vec<usize>

次バッチの添字列。空の Vec は epoch 終了の番兵。
Source§

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V