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: random_using() compilation error #875

Closed
quietlychris opened this issue Dec 27, 2020 · 3 comments
Closed

ndarray_rand: random_using() compilation error #875

quietlychris opened this issue Dec 27, 2020 · 3 comments

Comments

@quietlychris
Copy link

Hello,

I've been working on creating a reproducible random array for testing variations on a neural network architecture, and came across a bit of an issue with trying to instantiate an Array using the Isaac64 RNG, which seems like it should be supported by the crate. Per the docs, I tried building the listed example in a stand-alone project, with the following in main.rs

use ndarray::Array;
use ndarray_rand::RandomExt;
use ndarray_rand::rand::SeedableRng;
use ndarray_rand::rand_distr::Uniform;
use rand_isaac::isaac64::Isaac64Rng;

fn main() {
    // Get a seeded random number generator for reproducibility (Isaac64 algorithm)
    let seed = 42;
    let mut rng = Isaac64Rng::seed_from_u64(seed);

    // Generate a random array using `rng`
    let a = Array::random_using((2, 5), Uniform::new(0., 10.), &mut rng);
    println!("{:8.4}", a);
}

and this in my Cargo.toml file.

[dependencies]
ndarray = "0.13"
ndarray-rand = "0.13"
rand = "0.8"
rand_isaac = "0.3"

However, each time I receive

error[E0599]: no function or associated item named `random_using` found for struct `ArrayBase<OwnedRepr<_>, _>` in the current scope
  --> src/main.rs:13:20
   |
13 |     let a = Array::random_using((2, 5), Uniform::new(0., 10.), &mut rng);
   |                    ^^^^^^^^^^^^ function or associated item not found in `ArrayBase<OwnedRepr<_>, _>`

I've tested this behavior using both rustc 1.48.0 (7eac88abb 2020-11-16) and rustc 1.51.0-nightly (0b644e419 2020-12-26). I didn't see a test in ndarray/ndarray-rand/tests/test.rs that covers the random_using() function, which means this error may have been missed by CI, although it's certainly possible that I may have missed something.

I'd be happy to test any corrections, and I have find the time, I may be able to dig into this an submit a PR fixing, although I have a few other things on my plate before I can get there. Thanks, and hope your holidays have been well!

@quietlychris quietlychris changed the title ndarray-_rand: random_using() compilation error ndarray_rand: random_using() compilation error Dec 27, 2020
@relf
Copy link

relf commented Dec 27, 2020

I think I've met the same problem. I have to stick to ndarray-rand="0.11" to make it work (I use ndarray="0.13" as well).

@jturner314
Copy link
Member

I think the issue is incompatible versions, as @relf indicated. For ndarray-rand 0.13, you need to use ndarray 0.14, rand 0.8, and rand_distr 0.4. (See the dependencies in the right column on the crates.io page for ndarray-rand 0.13.) If you want to stay on ndarray 0.13.0 for now, the latest version of ndarray-rand that supports it is ndarray-rand 0.11.0.

Hopefully, the error message for this type of thing will be improved in the future. (See rust-lang/rust#22750.) In the meantime, it would be worth adding a note about the correct version of ndarray to the main page of the docs, near where it says, "ndarray-rand depends on rand 0.8."

@quietlychris
Copy link
Author

quietlychris commented Dec 27, 2020

Ah, gotcha. I was hoping to keep using ndarray 0.13.* until 0.15 gets released, since it from the threads it seems the plan was to have that happen relatively soon, but I can just move up to 0.14 in the interim.

At least on my system, using ndarray-rand = "0.13", ndarray = "0.14 works, but I get an error if I try ndarray-rand = "0.11", ndarray = "0.13".

@bluss bluss closed this as completed Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants