12
12
//!
13
13
//! ## Note
14
14
//!
15
- //! `ndarray-rand` depends on [`rand` 0.7 ][rand].
15
+ //! `ndarray-rand` depends on [`rand` 0.8 ][rand].
16
16
//!
17
17
//! [`rand`][rand] and [`rand_distr`][rand_distr]
18
18
//! are re-exported as sub-modules, [`ndarray_rand::rand`](rand/index.html)
19
19
//! and [`ndarray_rand::rand_distr`](rand_distr/index.html) respectively.
20
20
//! You can use these submodules for guaranteed version compatibility or
21
21
//! convenience.
22
22
//!
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
25
25
//!
26
26
//! If you want to use a random number generator or distribution from another crate
27
27
//! 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;
35
35
use crate :: rand:: { thread_rng, Rng , SeedableRng } ;
36
36
37
37
use ndarray:: { Array , Axis , RemoveAxis , ShapeBuilder } ;
38
- use ndarray:: { ArrayBase , DataOwned , Dimension } ;
38
+ use ndarray:: { ArrayBase , DataOwned , RawData , Data , Dimension } ;
39
39
#[ cfg( feature = "quickcheck" ) ]
40
40
use quickcheck:: { Arbitrary , Gen } ;
41
41
42
- /// [ `rand`](https://docs.rs/rand/0.7) , re-exported for convenience and version-compatibility.
42
+ /// `rand`, re-exported for convenience and version-compatibility.
43
43
pub mod rand {
44
44
pub use rand:: * ;
45
45
}
46
46
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.
48
48
pub mod rand_distr {
49
49
pub use rand_distr:: * ;
50
50
}
@@ -55,16 +55,15 @@ pub mod rand_distr {
55
55
/// for other types.
56
56
///
57
57
/// 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`]).
60
59
///
61
60
/// Note that `SmallRng` is cheap to initialize and fast, but it may generate
62
61
/// low-quality random numbers, and reproducibility is not guaranteed. See its
63
62
/// documentation for information. You can select a different RNG with
64
63
/// [`.random_using()`](#tymethod.random_using).
65
64
pub trait RandomExt < S , A , D >
66
65
where
67
- S : DataOwned < Elem = A > ,
66
+ S : RawData < Elem = A > ,
68
67
D : Dimension ,
69
68
{
70
69
/// Create an array with shape `dim` with elements drawn from
88
87
fn random < Sh , IdS > ( shape : Sh , distribution : IdS ) -> ArrayBase < S , D >
89
88
where
90
89
IdS : Distribution < S :: Elem > ,
90
+ S : DataOwned < Elem = A > ,
91
91
Sh : ShapeBuilder < Dim = D > ;
92
92
93
93
/// Create an array with shape `dim` with elements drawn from
@@ -118,6 +118,7 @@ where
118
118
where
119
119
IdS : Distribution < S :: Elem > ,
120
120
R : Rng + ?Sized ,
121
+ S : DataOwned < Elem = A > ,
121
122
Sh : ShapeBuilder < Dim = D > ;
122
123
123
124
/// Sample `n_samples` lanes slicing along `axis` using the default RNG.
@@ -164,6 +165,7 @@ where
164
165
fn sample_axis ( & self , axis : Axis , n_samples : usize , strategy : SamplingStrategy ) -> Array < A , D >
165
166
where
166
167
A : Copy ,
168
+ S : Data < Elem = A > ,
167
169
D : RemoveAxis ;
168
170
169
171
/// Sample `n_samples` lanes slicing along `axis` using the specified RNG `rng`.
@@ -224,17 +226,19 @@ where
224
226
where
225
227
R : Rng + ?Sized ,
226
228
A : Copy ,
229
+ S : Data < Elem = A > ,
227
230
D : RemoveAxis ;
228
231
}
229
232
230
233
impl < S , A , D > RandomExt < S , A , D > for ArrayBase < S , D >
231
234
where
232
- S : DataOwned < Elem = A > ,
235
+ S : RawData < Elem = A > ,
233
236
D : Dimension ,
234
237
{
235
238
fn random < Sh , IdS > ( shape : Sh , dist : IdS ) -> ArrayBase < S , D >
236
239
where
237
240
IdS : Distribution < S :: Elem > ,
241
+ S : DataOwned < Elem = A > ,
238
242
Sh : ShapeBuilder < Dim = D > ,
239
243
{
240
244
Self :: random_using ( shape, dist, & mut get_rng ( ) )
@@ -244,6 +248,7 @@ where
244
248
where
245
249
IdS : Distribution < S :: Elem > ,
246
250
R : Rng + ?Sized ,
251
+ S : DataOwned < Elem = A > ,
247
252
Sh : ShapeBuilder < Dim = D > ,
248
253
{
249
254
Self :: from_shape_simple_fn ( shape, move || dist. sample ( rng) )
@@ -252,6 +257,7 @@ where
252
257
fn sample_axis ( & self , axis : Axis , n_samples : usize , strategy : SamplingStrategy ) -> Array < A , D >
253
258
where
254
259
A : Copy ,
260
+ S : Data < Elem = A > ,
255
261
D : RemoveAxis ,
256
262
{
257
263
self . sample_axis_using ( axis, n_samples, strategy, & mut get_rng ( ) )
@@ -267,6 +273,7 @@ where
267
273
where
268
274
R : Rng + ?Sized ,
269
275
A : Copy ,
276
+ S : Data < Elem = A > ,
270
277
D : RemoveAxis ,
271
278
{
272
279
let indices: Vec < _ > = match strategy {
@@ -298,7 +305,7 @@ pub enum SamplingStrategy {
298
305
#[ cfg( feature = "quickcheck" ) ]
299
306
impl Arbitrary for SamplingStrategy {
300
307
fn arbitrary < G : Gen > ( g : & mut G ) -> Self {
301
- if g . gen_bool ( 0.5 ) {
308
+ if bool :: arbitrary ( g ) {
302
309
SamplingStrategy :: WithReplacement
303
310
} else {
304
311
SamplingStrategy :: WithoutReplacement
0 commit comments