Repository navigation
ndarray-rand #530
Copy link
Copy link
Closed
Labels
Description
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`.
Reactions are currently unavailable
Activity
jturner314 commentedon Nov 7, 2018
I'm not able to reproduce the issue. When I run
cargo testin thendarray-randcrate, all the tests pass. When I create a project with the following contents:Cargo.tomlsrc/main.rsit 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 commentedon Nov 7, 2018
jturner314 commentedon Nov 7, 2018
Make sure the versions you're using are consistent. For example,
ndarray-rand0.8 requiresndarray0.12 andrand0.5, whilendarray-rand0.7 requiresndarray0.11 andrand0.4. (See the README.)DevinBayly commentedon Nov 7, 2018
jturner314 commentedon Nov 7, 2018
You're welcome. It's always nice when the problem is easy to solve. :)
jturner314 commentedon Nov 7, 2018
By the way, this is related to rust-lang/rust#22750.