Skip to content

ndarray_rand: random_using() compilation error #875

Closed
@quietlychris

Description

@quietlychris

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!

Activity

changed the title [-]ndarray-_rand: random_using() compilation error[/-] [+]ndarray_rand: random_using() compilation error[/+] on Dec 27, 2020
relf

relf commented on Dec 27, 2020

@relf

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

jturner314 commented on Dec 27, 2020

@jturner314
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

quietlychris commented on Dec 27, 2020

@quietlychris
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @relf@jturner314@bluss@quietlychris

        Issue actions

          ndarray_rand: random_using() compilation error · Issue #875 · rust-ndarray/ndarray