raskr / rust-autograd

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

tensordot fails on assert #23

Closed hwchen closed 4 years ago

hwchen commented 4 years ago

Hello, I may have found a bug.

I was trying to evaluate a dot product:

use autograd as ag;
use autograd::Tensor;
use autograd::ndarray::arr1;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let x: Tensor<f32> = ag::placeholder(&[4]);
    let y: Tensor<f32> = 2. * ag::tensordot(&x, &x, &[0], &[0]);

    let arr = arr1(&[0f32,1.,2.,3.]).into_dyn();

    println!("{:?}", y.eval(&[ag::Feed(&x, arr.view())]));

    Ok(())
}

which gives me the error:

thread 'main' panicked at 'assertion failed: perm_len >= 2', /home/hwchen/.cargo/registry/src/github.com-1ecc6299db9ec823/autograd-0.9.6/src/ops/math_ops.rs:344:9

Removing the assert at https://github.com/raskr/rust-autograd/blob/97a5ad0881e0e996202b15de8bb2098b4d56206f/src/ops/math_ops.rs#L344 allows the operation to proceed and gives me the answer I expect.

I don't know enough to know whether the assert can just be modified, so I didn't create a pull request.

Thanks!

raskr commented 4 years ago

Fixed in v0.9.7. As you mentioned, the assertion in transpose was incorrect! https://github.com/raskr/rust-autograd/commit/1b19bafd35c29cd6230a2cd1e81bec5f435bb358

hwchen commented 4 years ago

thanks for the fix!