1212//!
1313//! ## Note
1414//!
15- //! `ndarray-rand` depends on [`rand` 0.7 ][rand].
15+ //! `ndarray-rand` depends on [`rand` 0.8 ][rand].
1616//!
1717//! [`rand`][rand] and [`rand_distr`][rand_distr]
1818//! are re-exported as sub-modules, [`ndarray_rand::rand`](rand/index.html)
1919//! and [`ndarray_rand::rand_distr`](rand_distr/index.html) respectively.
2020//! You can use these submodules for guaranteed version compatibility or
2121//! convenience.
2222//!
23- //! [rand]: https://docs.rs/rand/0.7
24- //! [rand_distr]: https://docs.rs/rand_distr/0.3
23+ //! [rand]: https://docs.rs/rand/0.8
24+ //! [rand_distr]: https://docs.rs/rand_distr/0.4
2525//!
2626//! If you want to use a random number generator or distribution from another crate
2727//! with `ndarray-rand`, you need to make sure that the other crate also depends on the
@@ -35,16 +35,16 @@ use crate::rand::seq::index;
3535use crate::rand::{thread_rng, Rng, SeedableRng};
3636
3737use ndarray::{Array, Axis, RemoveAxis, ShapeBuilder};
38- use ndarray::{ArrayBase, DataOwned, Dimension};
38+ use ndarray::{ArrayBase, DataOwned, RawData, Data, Dimension};
3939#[cfg(feature = "quickcheck")]
4040use quickcheck::{Arbitrary, Gen};
4141
42- /// [ `rand`](https://docs.rs/rand/0.7) , re-exported for convenience and version-compatibility.
42+ /// `rand`, re-exported for convenience and version-compatibility.
4343pub mod rand {
4444 pub use rand::*;
4545}
4646
47- /// [ `rand-distr`](https://docs.rs/rand_distr/0.3) , re-exported for convenience and version-compatibility.
47+ /// `rand-distr`, re-exported for convenience and version-compatibility.
4848pub mod rand_distr {
4949 pub use rand_distr::*;
5050}
@@ -55,16 +55,15 @@ pub mod rand_distr {
5555/// for other types.
5656///
5757/// The default RNG is a fast automatically seeded rng (currently
58- /// [`rand::rngs::SmallRng`](https://docs.rs/rand/0.7/rand/rngs/struct.SmallRng.html)
59- /// seeded from [`rand::thread_rng`](https://docs.rs/rand/0.7/rand/fn.thread_rng.html)).
58+ /// [`rand::rngs::SmallRng`], seeded from [`rand::thread_rng`]).
6059///
6160/// Note that `SmallRng` is cheap to initialize and fast, but it may generate
6261/// low-quality random numbers, and reproducibility is not guaranteed. See its
6362/// documentation for information. You can select a different RNG with
6463/// [`.random_using()`](#tymethod.random_using).
6564pub trait RandomExt<S, A, D>
6665where
67- S: DataOwned <Elem = A>,
66+ S: RawData <Elem = A>,
6867 D: Dimension,
6968{
7069 /// Create an array with shape `dim` with elements drawn from
8887 fn random<Sh, IdS>(shape: Sh, distribution: IdS) -> ArrayBase<S, D>
8988 where
9089 IdS: Distribution<S::Elem>,
90+ S: DataOwned<Elem = A>,
9191 Sh: ShapeBuilder<Dim = D>;
9292
9393 /// Create an array with shape `dim` with elements drawn from
@@ -118,6 +118,7 @@ where
118118 where
119119 IdS: Distribution<S::Elem>,
120120 R: Rng + ?Sized,
121+ S: DataOwned<Elem = A>,
121122 Sh: ShapeBuilder<Dim = D>;
122123
123124 /// Sample `n_samples` lanes slicing along `axis` using the default RNG.
@@ -164,6 +165,7 @@ where
164165 fn sample_axis(&self, axis: Axis, n_samples: usize, strategy: SamplingStrategy) -> Array<A, D>
165166 where
166167 A: Copy,
168+ S: Data<Elem = A>,
167169 D: RemoveAxis;
168170
169171 /// Sample `n_samples` lanes slicing along `axis` using the specified RNG `rng`.
@@ -224,17 +226,19 @@ where
224226 where
225227 R: Rng + ?Sized,
226228 A: Copy,
229+ S: Data<Elem = A>,
227230 D: RemoveAxis;
228231}
229232
230233impl<S, A, D> RandomExt<S, A, D> for ArrayBase<S, D>
231234where
232- S: DataOwned <Elem = A>,
235+ S: RawData <Elem = A>,
233236 D: Dimension,
234237{
235238 fn random<Sh, IdS>(shape: Sh, dist: IdS) -> ArrayBase<S, D>
236239 where
237240 IdS: Distribution<S::Elem>,
241+ S: DataOwned<Elem = A>,
238242 Sh: ShapeBuilder<Dim = D>,
239243 {
240244 Self::random_using(shape, dist, &mut get_rng())
@@ -244,6 +248,7 @@ where
244248 where
245249 IdS: Distribution<S::Elem>,
246250 R: Rng + ?Sized,
251+ S: DataOwned<Elem = A>,
247252 Sh: ShapeBuilder<Dim = D>,
248253 {
249254 Self::from_shape_simple_fn(shape, move || dist.sample(rng))
@@ -252,6 +257,7 @@ where
252257 fn sample_axis(&self, axis: Axis, n_samples: usize, strategy: SamplingStrategy) -> Array<A, D>
253258 where
254259 A: Copy,
260+ S: Data<Elem = A>,
255261 D: RemoveAxis,
256262 {
257263 self.sample_axis_using(axis, n_samples, strategy, &mut get_rng())
@@ -267,6 +273,7 @@ where
267273 where
268274 R: Rng + ?Sized,
269275 A: Copy,
276+ S: Data<Elem = A>,
270277 D: RemoveAxis,
271278 {
272279 let indices: Vec<_> = match strategy {
@@ -298,7 +305,7 @@ pub enum SamplingStrategy {
298305#[cfg(feature = "quickcheck")]
299306impl Arbitrary for SamplingStrategy {
300307 fn arbitrary<G: Gen>(g: &mut G) -> Self {
301- if g.gen_bool(0.5 ) {
308+ if bool::arbitrary(g ) {
302309 SamplingStrategy::WithReplacement
303310 } else {
304311 SamplingStrategy::WithoutReplacement
0 commit comments