pub struct Generator { /* private fields */ }Expand description
プロセスグローバルな RNG(manual_seed/with_global_rng)とは
完全に独立した状態を持つ乱数源(PyTorch torch.Generator 相当。
イシュー #2156・親 #2131)。
用途は「グローバル状態を汚さない再現可能なサンプリング」。
Generator::new(seed) と manual_seed(seed) の直後に
グローバル自由関数(bernoulli/multinomial/normal)を
呼んだ結果は bit 完全一致する(いずれも
Xorshift64Star::new(seed) から始まるため。crates/autodiff/tests/ random_parity.rs で固定)。
&mut self で操作するためロックは不要(呼び出し元が所有権・借用で
排他制御を担う。with_global_rng の Mutex とは異なる設計)。
§用途限定
xorshift64* は暗号学的に安全な PRNG ではない(モジュール冒頭コメント 参照。OWASP A02)。鍵・トークン生成などセキュリティ用途には使用 しないこと。
Implementations§
Source§impl Generator
impl Generator
Sourcepub fn new(seed: u64) -> Generator
pub fn new(seed: u64) -> Generator
seed から新規の独立した RNG 状態を作る
(Xorshift64Star::new(seed) と同じ 0 補正を継承する)。
Sourcepub fn manual_seed(&mut self, seed: u64)
pub fn manual_seed(&mut self, seed: u64)
状態を seed からやり直す(manual_seed の Generator 版。
グローバル状態には一切触れない)。
Sourcepub fn initial_seed(&self) -> u64
pub fn initial_seed(&self) -> u64
Self::new/Self::manual_seed に渡された、補正前のシード値を
返す(PyTorch Generator.initial_seed() と同じ意味論)。
Sourcepub fn bernoulli(
&mut self,
probs: &Tensor<f32>,
) -> Result<Tensor<f32>, RngError>
pub fn bernoulli( &mut self, probs: &Tensor<f32>, ) -> Result<Tensor<f32>, RngError>
bernoulli の Generator 版。グローバル RNG は消費しない。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Generator
impl RefUnwindSafe for Generator
impl Send for Generator
impl Sync for Generator
impl Unpin for Generator
impl UnsafeUnpin for Generator
impl UnwindSafe for Generator
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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