1
1
use ndarray:: { Array , Array2 , ArrayView1 , Axis } ;
2
2
#[ cfg( feature = "quickcheck" ) ]
3
- use ndarray_rand:: rand:: { distributions :: Distribution , thread_rng } ;
3
+ use ndarray_rand:: rand:: { distr :: Distribution , rng } ;
4
4
5
5
use ndarray:: ShapeBuilder ;
6
6
use ndarray_rand:: rand_distr:: Uniform ;
@@ -13,7 +13,7 @@ fn test_dim()
13
13
let ( mm, nn) = ( 5 , 5 ) ;
14
14
for m in 0 ..mm {
15
15
for n in 0 ..nn {
16
- let a = Array :: random ( ( m, n) , Uniform :: new ( 0. , 2. ) ) ;
16
+ let a = Array :: random ( ( m, n) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
17
17
assert_eq ! ( a. shape( ) , & [ m, n] ) ;
18
18
assert ! ( a. iter( ) . all( |x| * x < 2. ) ) ;
19
19
assert ! ( a. iter( ) . all( |x| * x >= 0. ) ) ;
@@ -28,7 +28,7 @@ fn test_dim_f()
28
28
let ( mm, nn) = ( 5 , 5 ) ;
29
29
for m in 0 ..mm {
30
30
for n in 0 ..nn {
31
- let a = Array :: random ( ( m, n) . f ( ) , Uniform :: new ( 0. , 2. ) ) ;
31
+ let a = Array :: random ( ( m, n) . f ( ) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
32
32
assert_eq ! ( a. shape( ) , & [ m, n] ) ;
33
33
assert ! ( a. iter( ) . all( |x| * x < 2. ) ) ;
34
34
assert ! ( a. iter( ) . all( |x| * x >= 0. ) ) ;
@@ -41,7 +41,7 @@ fn test_dim_f()
41
41
fn sample_axis_on_view ( )
42
42
{
43
43
let m = 5 ;
44
- let a = Array :: random ( ( m, 4 ) , Uniform :: new ( 0. , 2. ) ) ;
44
+ let a = Array :: random ( ( m, 4 ) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
45
45
let _samples = a
46
46
. view ( )
47
47
. sample_axis ( Axis ( 0 ) , m, SamplingStrategy :: WithoutReplacement ) ;
@@ -52,15 +52,15 @@ fn sample_axis_on_view()
52
52
fn oversampling_without_replacement_should_panic ( )
53
53
{
54
54
let m = 5 ;
55
- let a = Array :: random ( ( m, 4 ) , Uniform :: new ( 0. , 2. ) ) ;
55
+ let a = Array :: random ( ( m, 4 ) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
56
56
let _samples = a. sample_axis ( Axis ( 0 ) , m + 1 , SamplingStrategy :: WithoutReplacement ) ;
57
57
}
58
58
59
59
quickcheck ! {
60
60
#[ cfg_attr( miri, ignore) ] // Takes an insufferably long time
61
61
fn oversampling_with_replacement_is_fine( m: u8 , n: u8 ) -> TestResult {
62
62
let ( m, n) = ( m as usize , n as usize ) ;
63
- let a = Array :: random( ( m, n) , Uniform :: new( 0. , 2. ) ) ;
63
+ let a = Array :: random( ( m, n) , Uniform :: new( 0. , 2. ) . unwrap ( ) ) ;
64
64
// Higher than the length of both axes
65
65
let n_samples = m + n + 1 ;
66
66
@@ -90,12 +90,12 @@ quickcheck! {
90
90
#[ cfg_attr( miri, ignore) ] // This takes *forever* with Miri
91
91
fn sampling_behaves_as_expected( m: u8 , n: u8 , strategy: SamplingStrategy ) -> TestResult {
92
92
let ( m, n) = ( m as usize , n as usize ) ;
93
- let a = Array :: random( ( m, n) , Uniform :: new( 0. , 2. ) ) ;
94
- let mut rng = & mut thread_rng ( ) ;
93
+ let a = Array :: random( ( m, n) , Uniform :: new( 0. , 2. ) . unwrap ( ) ) ;
94
+ let mut rng = & mut rng ( ) ;
95
95
96
96
// We don't want to deal with sampling from 0-length axes in this test
97
97
if m != 0 {
98
- let n_row_samples = Uniform :: from ( 1 .. m+1 ) . sample( & mut rng) ;
98
+ let n_row_samples = Uniform :: new ( 1 , m+1 ) . unwrap ( ) . sample( & mut rng) ;
99
99
if !sampling_works( & a, strategy. clone( ) , Axis ( 0 ) , n_row_samples) {
100
100
return TestResult :: failed( ) ;
101
101
}
@@ -105,7 +105,7 @@ quickcheck! {
105
105
106
106
// We don't want to deal with sampling from 0-length axes in this test
107
107
if n != 0 {
108
- let n_col_samples = Uniform :: from ( 1 .. n+1 ) . sample( & mut rng) ;
108
+ let n_col_samples = Uniform :: new ( 1 , n+1 ) . unwrap ( ) . sample( & mut rng) ;
109
109
if !sampling_works( & a, strategy, Axis ( 1 ) , n_col_samples) {
110
110
return TestResult :: failed( ) ;
111
111
}
@@ -136,7 +136,7 @@ fn is_subset(a: &Array2<f64>, b: &ArrayView1<f64>, axis: Axis) -> bool
136
136
fn sampling_without_replacement_from_a_zero_length_axis_should_panic ( )
137
137
{
138
138
let n = 5 ;
139
- let a = Array :: random ( ( 0 , n) , Uniform :: new ( 0. , 2. ) ) ;
139
+ let a = Array :: random ( ( 0 , n) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
140
140
let _samples = a. sample_axis ( Axis ( 0 ) , 1 , SamplingStrategy :: WithoutReplacement ) ;
141
141
}
142
142
@@ -145,6 +145,6 @@ fn sampling_without_replacement_from_a_zero_length_axis_should_panic()
145
145
fn sampling_with_replacement_from_a_zero_length_axis_should_panic ( )
146
146
{
147
147
let n = 5 ;
148
- let a = Array :: random ( ( 0 , n) , Uniform :: new ( 0. , 2. ) ) ;
148
+ let a = Array :: random ( ( 0 , n) , Uniform :: new ( 0. , 2. ) . unwrap ( ) ) ;
149
149
let _samples = a. sample_axis ( Axis ( 0 ) , 1 , SamplingStrategy :: WithReplacement ) ;
150
150
}
0 commit comments