Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndarray-rand #530

Closed
DevinBayly opened this issue Nov 7, 2018 · 6 comments
Closed

ndarray-rand #530

DevinBayly opened this issue Nov 7, 2018 · 6 comments
Labels

Comments

@DevinBayly
Copy link

The random function from the ndarray_rand::RandomExt trait seems to go unrecognized when following the test example on the repo.

extern crate rand;
extern crate ndarray;
extern crate ndarray_rand;



#[cfg(test)]
mod tests {
    use rand::distributions::Range;
    use ndarray::Array;
    use ndarray_rand::RandomExt;

    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
        let (mm, nn) = (5, 5);
        for m in 0..mm {
            for n in 0..nn {
                let a = Array::random((m, n), Range::new(0., 2.));
                assert_eq!(a.shape(), &[m, n]);
                assert!(a.iter().all(|x| *x <= 2.));
                assert!(a.iter().all(|x| *x >= 0.));
            }
        }
    }
}

cargo test generates this compilation error

   Compiling randarr v0.1.0 (/tmp/randarr)                                                                                                            
error[E0599]: no function or associated item named `random` found for type `ndarray::ArrayBase<ndarray::OwnedRepr<_>, _>` in the current scope        
  --> src/lib.rs:19:25                                                                                                                                
   |                                                                                                                                                  
19 |                 let a = Array::random((m, n), Range::new(0., 2.));                                                                               
   |                         ^^^^^^^^^^^^^ function or associated item not found in `ndarray::ArrayBase<ndarray::OwnedRepr<_>, _>`                    
                                                                                                                                                      
error: aborting due to previous error                                                                                                                 
                                                                                                                                                      
For more information about this error, try `rustc --explain E0599`.                                                                                   
error: Could not compile `randarr`. 
@jturner314
Copy link
Member

I'm not able to reproduce the issue. When I run cargo test in the ndarray-rand crate, all the tests pass. When I create a project with the following contents:

  • Cargo.toml

    [package]
    name = "foo"
    version = "0.1.0"
    
    [dependencies]
    ndarray = "0.12"
    ndarray-rand = "0.8"
    rand = "0.5"
  • src/main.rs

    extern crate rand;
    extern crate ndarray;
    extern crate ndarray_rand;
    
    use rand::distributions::Range;
    use ndarray::Array;
    use ndarray_rand::RandomExt;
    
    fn main() {
        assert_eq!(2 + 2, 4);
        let (mm, nn) = (5, 5);
        for m in 0..mm {
            for n in 0..nn {
                let a = Array::random((m, n), Range::new(0., 2.));
                assert_eq!(a.shape(), &[m, n]);
                assert!(a.iter().all(|x| *x <= 2.));
                assert!(a.iter().all(|x| *x >= 0.));
            }
        }
    }

it builds and runs fine. I'm using Rust 1.30.0.

Does the example I provided above work on your machine? If so, will you please provide more details about the case that is failing for you?

@DevinBayly
Copy link
Author

DevinBayly commented Nov 7, 2018 via email

@jturner314
Copy link
Member

Make sure the versions you're using are consistent. For example, ndarray-rand 0.8 requires ndarray 0.12 and rand 0.5, while ndarray-rand 0.7 requires ndarray 0.11 and rand 0.4. (See the README.)

@DevinBayly
Copy link
Author

DevinBayly commented Nov 7, 2018 via email

@jturner314
Copy link
Member

You're welcome. It's always nice when the problem is easy to solve. :)

@jturner314
Copy link
Member

By the way, this is related to rust-lang/rust#22750.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants