rusttorch 0.4.0

Build, train, and run neural networks in Rust with LibTorch
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use rusttorch::{Device, Kind, Tensor, data::RandomSampler, manual_seed};

#[test]
fn random_sampler_does_not_change_libtorch_global_rng() {
    manual_seed(1_234);
    let expected = Tensor::randn([8], (Kind::Float, Device::Cpu));

    manual_seed(1_234);
    let _indices = RandomSampler::new(64, 42)
        .expect("positive length must be valid")
        .collect::<Vec<_>>();
    let actual = Tensor::randn([8], (Kind::Float, Device::Cpu));

    assert_eq!(
        Vec::<f32>::try_from(&actual).expect("random tensor must convert"),
        Vec::<f32>::try_from(&expected).expect("random tensor must convert")
    );
}