Skip to content

ndarray-rand #530

@DevinBayly

Description

@DevinBayly

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`. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions