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 doesn't work with rand 0.7 #658

Closed
ngoldbaum opened this issue Jul 17, 2019 · 7 comments · Fixed by #659
Closed

ndarray-rand doesn't work with rand 0.7 #658

ngoldbaum opened this issue Jul 17, 2019 · 7 comments · Fixed by #659
Labels

Comments

@ngoldbaum
Copy link

ngoldbaum commented Jul 17, 2019

The test program in the ndarray-rand documentation doesn't compile with rand 0.7:

main.rs:

use ndarray::Array;
use ndarray_rand::RandomExt;
use rand::distributions::Uniform;

fn main() {
    let a = Array::random((2, 5), Uniform::new(0., 10.));
    println!("{:8.4}", a);
}

cargo.toml:

[package]
name = "rand-test"
version = "0.1.0"
authors = ["Nathan Goldbaum <[email protected]>"]
edition = "2018"

[dependencies]
ndarray = { version = "0.12", features = ["blas"] }
ndarray-rand = "0.9"
rand = "0.7"

compile error:

    Updating crates.io index
   Compiling rand-test v0.1.0 (/home/goldbaum/Documents/rand-test)
error[E0277]: the trait bound `rand::distributions::uniform::Uniform<{float}>: rand::distributions::Distribution<_>` is not satisfied
 --> src/main.rs:6:13
  |
6 |     let a = Array::random((2, 5), Uniform::new(0., 10.));
  |             ^^^^^^^^^^^^^ the trait `rand::distributions::Distribution<_>` is not implemented for `rand::distributions::uniform::Uniform<{float}>`
  |
  = note: required by `ndarray_rand::RandomExt::random`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `rand-test`.

It works if I specify rand = "0.6" in cargo.toml.

Apologies if this issue is documented already and I've missed it.

@ngoldbaum
Copy link
Author

perhaps i'm hitting rust-lang/rust#22750. I guess if ndarray-rand doesn't support rand 0.7 that should be encoded in ndarray-rand's cargo.toml?

@ngoldbaum
Copy link
Author

Ah I see it does specify 0.6 explicitly:

rand = "0.6.0"

@LukeMathWalker
Copy link
Member

LukeMathWalker commented Jul 17, 2019

I had the exact same issue a couple of hours ago when working on rust-ndarray/ndarray-linalg#166 - I am little bit surprised by cargo's behavior here, because ndarray-rand does indeed specify 0.6.

I guess, overall, we should aim to keep close to the latest release of rand - #659 goes in the right direction.

@max-sixty
Copy link
Contributor

Any ideas why cargo doesn't use 0.6.0?

Is there some complexity with there being a workspace?

Seems unlikely but @ngoldbaum if the cargo.toml above includes the full semver version rand = "0.6.0" (with the trailing patch version included), does that work?

@ngoldbaum
Copy link
Author

Argh, I'm sorry, I copy/pasted the cargo.toml that works. It does work if I explicitly depend on rand 0.6 and fails if I use rand 0.7. I've edited the issue to reflect that.

@max-sixty
Copy link
Contributor

Ah OK that makes sense.

I had thought cargo would use the necessary version for each crate... Or at least state that there were conflicting versions - not sure why this silently breaks...

@jturner314
Copy link
Member

Yeah, the bad error messages are an instance of rust-lang/rust#22750. Hopefully that'll get fixed at some point. This kind of issue has come up in the past with ndarray-rand (e.g. #530).

We should update ndarray-rand to use the latest version of rand (#659).

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

Successfully merging a pull request may close this issue.

4 participants