raskr / rust-autograd

Tensors and differentiable operations (like TensorFlow) in Rust
MIT License
487 stars 37 forks source link

Inconsistent tensor caching #17

Closed zekyll closed 5 years ago

zekyll commented 5 years ago

I was under the impression that tensors are only evaluated once during a single call to eval, and the value is then cached for later uses. It seems to work like that in most cases, but I tried a simple example with some inconsistent results:

let ref a : ag::Tensor<f64> = ag::random_normal(&[1], 0.0, 1.0);
println!("{:?}", ag::eval(&[a - a], &[]));
println!("{:?}", ag::eval(&[a - 1.0 * a], &[]));

The first one produces a value 0 as expected. However the second one is always a nonzero value, so it seems to call the random number generator twice.

raskr commented 5 years ago

Fixed in v0.9.5!