raskr / rust-autograd

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

"ndarray" and "autograd::ndarray" #42

Closed laocaoshilaocao closed 3 years ago

laocaoshilaocao commented 3 years ago

Hi, i am a beginner of this interesting rust deep learning library. When i try to run several basic examples using ndarray, i found that always has a compiler error saying i should use autograd::ndarray. Code and error are shown as follow:

    ag::with(|g| {
        let x = g.placeholder(&[-1,-1]);
        let value = array![[1., 1.]];  
        println!("{:?}", x.eval(&[x.given(value.view())]).unwrap()); 
    });
error[E0308]: mismatched types
  --> src\main.rs:14:43
   |
14 |         println!("{:?}", x.eval(&[x.given(value.view())]).unwrap());
   |                                           ^^^^^^^^^^^^ expected struct `autograd::ndarray::ArrayBase`, found struct `ndarray::ArrayBase`
   |
   = note: expected struct `autograd::ndarray::ArrayBase<autograd::ndarray::ViewRepr<&_>, _>`
              found struct `ndarray::ArrayBase<ndarray::ViewRepr<&{float}>, ndarray::Dim<[usize; 2]>>`
   = note: perhaps two different versions of crate `ndarray` are being used?

Is that compulsory to use ag::ndarray::array![[1., 1.]] instead of array![[1., 1.]] in this kind of cases? Thanks for your help.

laocaoshilaocao commented 3 years ago

Okay, i found that happens because i used the version 0.15.1 of ndarray. After i changed the dependence version to 0.12.1 everything works.

raskr commented 3 years ago

Thank you for the report, yes, ndarray is re-exported to avoid this problem for now.