From c0d2c6aff24e31be8344475bf3b3fa0967576120 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sat, 20 Jul 2019 13:45:32 +0100 Subject: [PATCH 01/13] Re-export distribution trait and implemented dists --- ndarray-rand/src/lib.rs | 10 +++++++++- ndarray-rand/tests/tests.rs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index 6e2a4591e..56506aa9f 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -10,13 +10,21 @@ //! //! See [**`RandomExt`**](trait.RandomExt.html) for usage examples. -use rand::distributions::Distribution; use rand::rngs::SmallRng; use rand::{thread_rng, Rng, SeedableRng}; use ndarray::ShapeBuilder; use ndarray::{ArrayBase, DataOwned, Dimension}; + +/// `rand`'s `Distribution` trait, re-exported for convenience. +pub use rand::distributions::Distribution; + +/// `rand`'s distributions, re-exported for convenience and version-compatibility. +pub mod distributions { + pub use rand::distributions::*; +} + /// Constructors for n-dimensional arrays with random elements. /// /// This trait extends ndarray’s `ArrayBase` and can not be implemented diff --git a/ndarray-rand/tests/tests.rs b/ndarray-rand/tests/tests.rs index 1f936d25c..040aa8a15 100644 --- a/ndarray-rand/tests/tests.rs +++ b/ndarray-rand/tests/tests.rs @@ -1,6 +1,6 @@ use ndarray::Array; use ndarray_rand::RandomExt; -use rand::distributions::Uniform; +use ndarray_rand::distributions::Uniform; #[test] fn test_dim() { From 8b6618eac45af613ebedcb7fbdb2513372a7863c Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sat, 20 Jul 2019 13:53:23 +0100 Subject: [PATCH 02/13] Export from the crate module --- ndarray-rand/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index 56506aa9f..c91d12e0b 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -18,7 +18,7 @@ use ndarray::{ArrayBase, DataOwned, Dimension}; /// `rand`'s `Distribution` trait, re-exported for convenience. -pub use rand::distributions::Distribution; +pub use crate::distributions::Distribution; /// `rand`'s distributions, re-exported for convenience and version-compatibility. pub mod distributions { From e55986d591cc2427c781a588318f54a1884af9d5 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sat, 20 Jul 2019 14:00:30 +0100 Subject: [PATCH 03/13] Adapt doc tests --- ndarray-rand/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index c91d12e0b..91f834d7d 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -50,13 +50,12 @@ where /// overflows usize. /// /// ``` - /// extern crate rand; /// extern crate ndarray; /// extern crate ndarray_rand; /// - /// use rand::distributions::Uniform; /// use ndarray::Array; /// use ndarray_rand::RandomExt; + /// use ndarray_rand::distributions::Uniform; /// /// # fn main() { /// let a = Array::random((2, 5), Uniform::new(0., 10.)); @@ -109,13 +108,12 @@ where /// A wrapper type that allows casting f64 distributions to f32 /// /// ``` -/// extern crate rand; /// extern crate ndarray; /// extern crate ndarray_rand; /// -/// use rand::distributions::Normal; /// use ndarray::Array; /// use ndarray_rand::{RandomExt, F32}; +/// use ndarray_rand::distributions::Normal; /// /// # fn main() { /// let a = Array::random((2, 5), F32(Normal::new(0., 1.))); From bd60a36ad6133adc4fe0f7bd6f92a6b637b980b5 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sat, 20 Jul 2019 19:35:09 +0100 Subject: [PATCH 04/13] Run cargo fmt --- ndarray-rand/src/lib.rs | 1 - ndarray-rand/tests/tests.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index 91f834d7d..5f095d344 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -16,7 +16,6 @@ use rand::{thread_rng, Rng, SeedableRng}; use ndarray::ShapeBuilder; use ndarray::{ArrayBase, DataOwned, Dimension}; - /// `rand`'s `Distribution` trait, re-exported for convenience. pub use crate::distributions::Distribution; diff --git a/ndarray-rand/tests/tests.rs b/ndarray-rand/tests/tests.rs index 040aa8a15..7a400f153 100644 --- a/ndarray-rand/tests/tests.rs +++ b/ndarray-rand/tests/tests.rs @@ -1,6 +1,6 @@ use ndarray::Array; -use ndarray_rand::RandomExt; use ndarray_rand::distributions::Uniform; +use ndarray_rand::RandomExt; #[test] fn test_dim() { From 0eea9e495aa64988f7d1c00fbe8a1c8fe2d79ced Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 18:22:17 +0100 Subject: [PATCH 05/13] Re-export the whole rand crate. Adjust docs, readme and examples. --- ndarray-rand/README.rst | 13 +++++++----- ndarray-rand/src/lib.rs | 40 ++++++++++++++++++++----------------- ndarray-rand/tests/tests.rs | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/ndarray-rand/README.rst b/ndarray-rand/README.rst index d764b6cbb..a7ce10ccd 100644 --- a/ndarray-rand/README.rst +++ b/ndarray-rand/README.rst @@ -4,11 +4,14 @@ ndarray-rand Dependencies ------------ -``ndarray-rand`` depends on ``rand`` 0.7. If you use any other items from -``rand``, you need to specify a compatible version of ``rand`` in your -``Cargo.toml``. If you want to use a RNG or distribution from another crate -with ``ndarray-rand``, you need to make sure that crate also depends on the -correct version of ``rand``. Otherwise, the compiler will return errors saying +``ndarray-rand`` depends on ``rand`` 0.7. + +`rand` is re-exported as a sub-module, `ndarray_rand::rand`. Please rely on this submodule for +guaranteed compatibility. + +If you want to use a random number generator or distribution from another crate +with ``ndarray-rand``, you need to make sure that the other crate also depends on the +same version of ``rand``. Otherwise, the compiler will return errors saying that the items are not compatible (e.g. that a type doesn't implement a necessary trait). diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index df8e38887..df3548269 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -6,30 +6,34 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Constructors for randomized arrays. `rand` integration for `ndarray`. +//! Constructors for randomized arrays: `rand` integration for `ndarray`. //! //! See [**`RandomExt`**](trait.RandomExt.html) for usage examples. //! -//! **Note:** `ndarray-rand` depends on `rand` 0.7. If you use any other items -//! from `rand`, you need to specify a compatible version of `rand` in your -//! `Cargo.toml`. If you want to use a RNG or distribution from another crate -//! with `ndarray-rand`, you need to make sure that crate also depends on the -//! correct version of `rand`. Otherwise, the compiler will return errors -//! saying that the items are not compatible (e.g. that a type doesn't -//! implement a necessary trait). +//! ## Note +//! +//! `ndarray-rand` depends on `rand` 0.7. +//! +//! `rand` is re-exported as a sub-module, `ndarray_rand::rand`. Please rely on this submodule for +//! guaranteed compatibility. +//! +//! If you want to use a random number generator or distribution from another crate +//! with ``ndarray-rand``, you need to make sure that the other crate also depends on the +//! same version of ``rand``. Otherwise, the compiler will return errors saying +//! that the items are not compatible (e.g. that a type doesn't implement a +//! necessary trait). -use rand::rngs::SmallRng; -use rand::{thread_rng, Rng, SeedableRng}; + +use crate::rand::rngs::SmallRng; +use crate::rand::{thread_rng, Rng, SeedableRng}; +use crate::rand::distributions::Distribution; use ndarray::ShapeBuilder; use ndarray::{ArrayBase, DataOwned, Dimension}; -/// `rand`'s `Distribution` trait, re-exported for convenience. -pub use crate::distributions::Distribution; - -/// `rand`'s distributions, re-exported for convenience and version-compatibility. -pub mod distributions { - pub use rand::distributions::*; +/// `rand`, re-exported for convenience and version-compatibility. +pub mod rand { + pub use rand::*; } /// Constructors for n-dimensional arrays with random elements. @@ -62,7 +66,7 @@ where /// /// use ndarray::Array; /// use ndarray_rand::RandomExt; - /// use ndarray_rand::distributions::Uniform; + /// use ndarray_rand::rand::distributions::Uniform; /// /// # fn main() { /// let a = Array::random((2, 5), Uniform::new(0., 10.)); @@ -120,7 +124,7 @@ where /// /// use ndarray::Array; /// use ndarray_rand::{RandomExt, F32}; -/// use ndarray_rand::distributions::Normal; +/// use ndarray_rand::rand::distributions::Normal; /// /// # fn main() { /// let a = Array::random((2, 5), F32(Normal::new(0., 1.))); diff --git a/ndarray-rand/tests/tests.rs b/ndarray-rand/tests/tests.rs index 7a400f153..48e67b50f 100644 --- a/ndarray-rand/tests/tests.rs +++ b/ndarray-rand/tests/tests.rs @@ -1,5 +1,5 @@ use ndarray::Array; -use ndarray_rand::distributions::Uniform; +use ndarray_rand::rand::distributions::Uniform; use ndarray_rand::RandomExt; #[test] From 0f79978bb09d084dc819dd34982f506e66f563fa Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 18:35:53 +0100 Subject: [PATCH 06/13] Refactor ndarray-rand readme and changelog. --- ndarray-rand/Cargo.toml | 1 + ndarray-rand/{README.rst => README.md} | 83 +++++++++++--------------- ndarray-rand/RELEASES.md | 50 ++++++++++++++++ 3 files changed, 86 insertions(+), 48 deletions(-) rename ndarray-rand/{README.rst => README.md} (50%) create mode 100644 ndarray-rand/RELEASES.md diff --git a/ndarray-rand/Cargo.toml b/ndarray-rand/Cargo.toml index 024174a28..d26aace82 100644 --- a/ndarray-rand/Cargo.toml +++ b/ndarray-rand/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0" repository = "https://github.com/rust-ndarray/ndarray" documentation = "https://docs.rs/ndarray-rand/" +readme = "README.md" description = "Constructors for randomized arrays. `rand` integration for `ndarray`." diff --git a/ndarray-rand/README.rst b/ndarray-rand/README.md similarity index 50% rename from ndarray-rand/README.rst rename to ndarray-rand/README.md index a7ce10ccd..51455e1b9 100644 --- a/ndarray-rand/README.rst +++ b/ndarray-rand/README.md @@ -1,8 +1,33 @@ ndarray-rand ============ +Constructors for randomized arrays: `rand`'s integration with `ndarray`. + +Example +======= + +Generate a 2-dimensional array with shape `(2,5)` and elements drawn from a uniform distribution +over the `(0., 10.)` interval: + +```rust +extern crate ndarray; +extern crate ndarray_rand; + +use ndarray::Array; +use ndarray_rand::RandomExt; +use ndarray_rand::rand::distributions::Uniform; + +fn main() { + let a = Array::random((2, 5), Uniform::new(0., 10.)); + println!("{:8.4}", a); + // Example Output: + // [[ 8.6900, 6.9824, 3.8922, 6.5861, 2.4890], + // [ 0.0914, 5.5186, 5.8135, 5.2361, 3.1879]] +} +``` + Dependencies ------------- +============ ``ndarray-rand`` depends on ``rand`` 0.7. @@ -15,55 +40,19 @@ same version of ``rand``. Otherwise, the compiler will return errors saying that the items are not compatible (e.g. that a type doesn't implement a necessary trait). -Recent Changes --------------- +Recent changes +============== -- 0.10.0 +0.10.0 +------ - - Require rand 0.7 + - Require `rand` 0.7 - Require Rust 1.32 or later + - Re-export `rand` as a submodule, `ndarray_rand::rand` + +Check _[Changelogs](https://github.com/rust-ndarray/ndarray/ndarray-rand/RELEASES.md)_ to see +the changes introduced in previous releases. -- 0.9.0 - - - Require rand 0.6 - -- 0.8.0 - - - Require ndarray 0.12 - - Require rand 0.5 - -- 0.7.0 - - - Require ndarray 0.11 - - Require rand 0.4 - -- 0.6.1 - - - Clean up implementation of ``Array::random`` by @v-shmyhlo - -- 0.6.0 - - - Require ndarray 0.10.0 - -- 0.5.0 - - - Require ndarray 0.9 - -- 0.4.0 - - - Require ndarray 0.8 - -- 0.3.0 - - - Require ndarray 0.7 - -- 0.2.0 - - - Require ndarray 0.6 - -- 0.1.0 - - - Initial release License ======= @@ -75,5 +64,3 @@ http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms. - - diff --git a/ndarray-rand/RELEASES.md b/ndarray-rand/RELEASES.md new file mode 100644 index 000000000..c437c82aa --- /dev/null +++ b/ndarray-rand/RELEASES.md @@ -0,0 +1,50 @@ +Recent Changes +-------------- + +- 0.10.0 + + - Require `rand` 0.7 + - Require Rust 1.32 or later + - Re-export `rand` as a submodule, `ndarray_rand::rand` + +- 0.9.0 + + - Require rand 0.6 + +- 0.8.0 + + - Require ndarray 0.12 + - Require rand 0.5 + +- 0.7.0 + + - Require ndarray 0.11 + - Require rand 0.4 + +- 0.6.1 + + - Clean up implementation of ``Array::random`` by @v-shmyhlo + +- 0.6.0 + + - Require ndarray 0.10.0 + +- 0.5.0 + + - Require ndarray 0.9 + +- 0.4.0 + + - Require ndarray 0.8 + +- 0.3.0 + + - Require ndarray 0.7 + +- 0.2.0 + + - Require ndarray 0.6 + +- 0.1.0 + + - Initial release From 29d4c4bc1b8965bf5b86645170c96f929599d97b Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 18:50:11 +0100 Subject: [PATCH 07/13] Re-export rand-distr. Update docs accordingly. Add hyperlinks where helpful. --- ndarray-rand/Cargo.toml | 4 +--- ndarray-rand/README.md | 12 +++++++----- ndarray-rand/src/lib.rs | 23 +++++++++++++++-------- ndarray-rand/tests/tests.rs | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ndarray-rand/Cargo.toml b/ndarray-rand/Cargo.toml index d26aace82..a12195f3b 100644 --- a/ndarray-rand/Cargo.toml +++ b/ndarray-rand/Cargo.toml @@ -15,14 +15,12 @@ keywords = ["multidimensional", "matrix", "rand", "ndarray"] [dependencies] ndarray = { version = "0.12.0", path = ".." } +rand_distr = "0.2.1" [dependencies.rand] version = "0.7.0" features = ["small_rng"] -[dev-dependencies] -rand_distr = "0.2.1" - [package.metadata.release] no-dev-version = true diff --git a/ndarray-rand/README.md b/ndarray-rand/README.md index 51455e1b9..50fab0508 100644 --- a/ndarray-rand/README.md +++ b/ndarray-rand/README.md @@ -15,7 +15,7 @@ extern crate ndarray_rand; use ndarray::Array; use ndarray_rand::RandomExt; -use ndarray_rand::rand::distributions::Uniform; +use ndarray_rand::rand_distr::Uniform; fn main() { let a = Array::random((2, 5), Uniform::new(0., 10.)); @@ -31,12 +31,13 @@ Dependencies ``ndarray-rand`` depends on ``rand`` 0.7. -`rand` is re-exported as a sub-module, `ndarray_rand::rand`. Please rely on this submodule for -guaranteed compatibility. +[`rand`](https://docs.rs/rand/0.7.0/rand/) and [`rand-distr`](https://docs.rs/rand_distr/0.2.1/rand_distr/) are +re-exported as sub-modules, `ndarray_rand::rand` and `ndarray_rand::rand_distr` respectively. +Please rely on these submodules for guaranteed version compatibility. If you want to use a random number generator or distribution from another crate -with ``ndarray-rand``, you need to make sure that the other crate also depends on the -same version of ``rand``. Otherwise, the compiler will return errors saying +with `ndarray-rand`, you need to make sure that the other crate also depends on the +same version of `rand`. Otherwise, the compiler may return errors saying that the items are not compatible (e.g. that a type doesn't implement a necessary trait). @@ -49,6 +50,7 @@ Recent changes - Require `rand` 0.7 - Require Rust 1.32 or later - Re-export `rand` as a submodule, `ndarray_rand::rand` + - Re-export `rand-distr` as a submodule, `ndarray_rand::rand_distr` Check _[Changelogs](https://github.com/rust-ndarray/ndarray/ndarray-rand/RELEASES.md)_ to see the changes introduced in previous releases. diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index df3548269..56acb96d9 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -12,14 +12,16 @@ //! //! ## Note //! -//! `ndarray-rand` depends on `rand` 0.7. +//! `ndarray-rand` depends on [`rand` 0.7.0](https://docs.rs/rand/0.7.0/rand/). //! -//! `rand` is re-exported as a sub-module, `ndarray_rand::rand`. Please rely on this submodule for -//! guaranteed compatibility. +//! [`rand`](https://docs.rs/rand/0.7.0/rand/) and [`rand-distr`](https://docs.rs/rand_distr/0.2.1/rand_distr/) +//! are re-exported as sub-modules, [`ndarray_rand::rand`](rand/index.html) +//! and [`ndarray_rand::rand_distr`](rand_distr/index.html) respectively. +//! Please rely on these submodules for guaranteed version compatibility. //! //! If you want to use a random number generator or distribution from another crate -//! with ``ndarray-rand``, you need to make sure that the other crate also depends on the -//! same version of ``rand``. Otherwise, the compiler will return errors saying +//! with `ndarray-rand`, you need to make sure that the other crate also depends on the +//! same version of `rand`. Otherwise, the compiler will return errors saying //! that the items are not compatible (e.g. that a type doesn't implement a //! necessary trait). @@ -31,19 +33,24 @@ use crate::rand::distributions::Distribution; use ndarray::ShapeBuilder; use ndarray::{ArrayBase, DataOwned, Dimension}; -/// `rand`, re-exported for convenience and version-compatibility. +/// [`rand`](https://docs.rs/rand/0.7.0/rand/), re-exported for convenience and version-compatibility. pub mod rand { pub use rand::*; } +/// [`rand-distr`](https://docs.rs/rand_distr/0.2.1/rand_distr/), re-exported for convenience and version-compatibility. +pub mod rand_distr { + pub use rand_distr::*; +} + /// Constructors for n-dimensional arrays with random elements. /// /// This trait extends ndarray’s `ArrayBase` and can not be implemented /// for other types. /// /// The default RNG is a fast automatically seeded rng (currently -/// [`rand::rngs::SmallRng`](https://docs.rs/rand/0.5/rand/rngs/struct.SmallRng.html) -/// seeded from [`rand::thread_rng`](https://docs.rs/rand/0.5/rand/fn.thread_rng.html)). +/// [`rand::rngs::SmallRng`](https://docs.rs/rand/0.7/rand/rngs/struct.SmallRng.html) +/// seeded from [`rand::thread_rng`](https://docs.rs/rand/0.7/rand/fn.thread_rng.html)). /// /// Note that `SmallRng` is cheap to initialize and fast, but it may generate /// low-quality random numbers, and reproducibility is not guaranteed. See its diff --git a/ndarray-rand/tests/tests.rs b/ndarray-rand/tests/tests.rs index 48e67b50f..6e64a10b9 100644 --- a/ndarray-rand/tests/tests.rs +++ b/ndarray-rand/tests/tests.rs @@ -1,5 +1,5 @@ use ndarray::Array; -use ndarray_rand::rand::distributions::Uniform; +use ndarray_rand::rand_distr::Uniform; use ndarray_rand::RandomExt; #[test] From a6b25f94fd502da18d9d30a19b7dda6d53509fe6 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 18:51:02 +0100 Subject: [PATCH 08/13] Keep stuff in sync --- ndarray-rand/RELEASES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ndarray-rand/RELEASES.md b/ndarray-rand/RELEASES.md index c437c82aa..d99fd3f8f 100644 --- a/ndarray-rand/RELEASES.md +++ b/ndarray-rand/RELEASES.md @@ -6,6 +6,7 @@ Recent Changes - Require `rand` 0.7 - Require Rust 1.32 or later - Re-export `rand` as a submodule, `ndarray_rand::rand` + - Re-export `rand-distr` as a submodule, `ndarray_rand::rand_distr` - 0.9.0 From d66449880534a1a016ed265b1bfe5cbb80f346f6 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 18:54:54 +0100 Subject: [PATCH 09/13] Update docs to use rand_distr --- ndarray-rand/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index 56acb96d9..e96c1224c 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -73,7 +73,7 @@ where /// /// use ndarray::Array; /// use ndarray_rand::RandomExt; - /// use ndarray_rand::rand::distributions::Uniform; + /// use ndarray_rand::rand_distr::Uniform; /// /// # fn main() { /// let a = Array::random((2, 5), Uniform::new(0., 10.)); @@ -131,10 +131,11 @@ where /// /// use ndarray::Array; /// use ndarray_rand::{RandomExt, F32}; -/// use ndarray_rand::rand::distributions::Normal; +/// use ndarray_rand::rand_distr::Normal; /// /// # fn main() { -/// let a = Array::random((2, 5), F32(Normal::new(0., 1.))); +/// let distribution_f64 = Normal::new(0., 1.).expect("Failed to create normal distribution"); +/// let a = Array::random((2, 5), F32(distribution_f64)); /// println!("{:8.4}", a); /// // Example Output: /// // [[ -0.6910, 1.1730, 1.0902, -0.4092, -1.7340], From d964d5d4d0140d9301eb82a6abfa57e8e8242ae3 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 19:39:32 +0100 Subject: [PATCH 10/13] Add doc example to random_using with seedable rng (Isaac64) --- ndarray-rand/Cargo.toml | 3 +++ ndarray-rand/src/lib.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ndarray-rand/Cargo.toml b/ndarray-rand/Cargo.toml index a12195f3b..c91760717 100644 --- a/ndarray-rand/Cargo.toml +++ b/ndarray-rand/Cargo.toml @@ -21,6 +21,9 @@ rand_distr = "0.2.1" version = "0.7.0" features = ["small_rng"] +[dev-dependencies] +rand_isaac = "0.2.0" + [package.metadata.release] no-dev-version = true diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index e96c1224c..25a61bdc9 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -91,6 +91,30 @@ where /// `distribution`, using a specific Rng `rng`. /// /// ***Panics*** if the number of elements overflows usize. + /// + /// ``` + /// extern crate ndarray; + /// extern crate ndarray_rand; + /// extern crate rand_isaac; + /// + /// 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); + /// // Example Output: + /// // [[ 8.6900, 6.9824, 3.8922, 6.5861, 2.4890], + /// // [ 0.0914, 5.5186, 5.8135, 5.2361, 3.1879]] + /// # } fn random_using(shape: Sh, distribution: IdS, rng: &mut R) -> ArrayBase where IdS: Distribution, From 080cc541d97823e908b31805aa98dcd0a2f4d4d2 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Sun, 4 Aug 2019 19:40:48 +0100 Subject: [PATCH 11/13] Run cargo fmt --- ndarray-rand/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index 25a61bdc9..b2a740c7d 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -25,10 +25,9 @@ //! that the items are not compatible (e.g. that a type doesn't implement a //! necessary trait). - +use crate::rand::distributions::Distribution; use crate::rand::rngs::SmallRng; use crate::rand::{thread_rng, Rng, SeedableRng}; -use crate::rand::distributions::Distribution; use ndarray::ShapeBuilder; use ndarray::{ArrayBase, DataOwned, Dimension}; From 1963d3601b2159871243f0413373a5731c1dbdc7 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Mon, 9 Sep 2019 21:15:27 +0100 Subject: [PATCH 12/13] Remove extern crate from doc tests --- ndarray-rand/src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ndarray-rand/src/lib.rs b/ndarray-rand/src/lib.rs index b2a740c7d..be747fd23 100644 --- a/ndarray-rand/src/lib.rs +++ b/ndarray-rand/src/lib.rs @@ -67,9 +67,6 @@ where /// overflows usize. /// /// ``` - /// extern crate ndarray; - /// extern crate ndarray_rand; - /// /// use ndarray::Array; /// use ndarray_rand::RandomExt; /// use ndarray_rand::rand_distr::Uniform; @@ -92,10 +89,6 @@ where /// ***Panics*** if the number of elements overflows usize. /// /// ``` - /// extern crate ndarray; - /// extern crate ndarray_rand; - /// extern crate rand_isaac; - /// /// use ndarray::Array; /// use ndarray_rand::RandomExt; /// use ndarray_rand::rand::SeedableRng; @@ -149,9 +142,6 @@ where /// A wrapper type that allows casting f64 distributions to f32 /// /// ``` -/// extern crate ndarray; -/// extern crate ndarray_rand; -/// /// use ndarray::Array; /// use ndarray_rand::{RandomExt, F32}; /// use ndarray_rand::rand_distr::Normal; From 5e6022f3f64c7ccd17b2d9cea9167938d5bb355b Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Mon, 9 Sep 2019 21:56:58 +0100 Subject: [PATCH 13/13] Remove extern crate from README --- ndarray-rand/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/ndarray-rand/README.md b/ndarray-rand/README.md index 50fab0508..e993440df 100644 --- a/ndarray-rand/README.md +++ b/ndarray-rand/README.md @@ -10,9 +10,6 @@ Generate a 2-dimensional array with shape `(2,5)` and elements drawn from a unif over the `(0., 10.)` interval: ```rust -extern crate ndarray; -extern crate ndarray_rand; - use ndarray::Array; use ndarray_rand::RandomExt; use ndarray_rand::rand_distr::Uniform;