1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! The process-wide random number generator, seedable for reproducible runs.
//!
//! [`Tensor::randn`](crate::Tensor::randn), [`Tensor::rand`](crate::Tensor::rand),
//! [`Tensor::uniform`](crate::Tensor::uniform), weight initialisation in [`nn`](crate::nn)
//! and [`functional::dropout`](crate::functional::dropout) all draw from it. Until
//! [`manual_seed`] is called it is the thread-local OS-seeded generator; after it,
//! every draw comes from one seeded generator, so the same program produces the
//! same numbers on every run.
use StdRng;
use ;
use ;
static SEEDED: = new;
/// Seed the generator behind every random tensor, initialiser and dropout mask.
///
/// Like `torch.manual_seed`: call it once at the start of a program. Calling it
/// again with the same seed restarts the same sequence.
///
/// ```
/// use ferrotensor::{manual_seed, Device, Tensor};
///
/// let device = Device::cpu();
/// manual_seed(42);
/// let a = Tensor::randn(&[4], &device).to_vec();
/// manual_seed(42);
/// let b = Tensor::randn(&[4], &device).to_vec();
/// assert_eq!(a, b);
/// ```
/// Run `f` with the seeded generator if [`manual_seed`] was called, else with
/// the thread-local OS-seeded one.
pub