11use ndarray:: { Array , Array2 , ArrayView1 , Axis } ;
22#[ cfg( feature = "quickcheck" ) ]
3- use ndarray_rand:: rand:: { distributions :: Distribution , thread_rng } ;
3+ use ndarray_rand:: rand:: { distr :: Distribution , rng } ;
44
55use ndarray:: ShapeBuilder ;
66use ndarray_rand:: rand_distr:: Uniform ;
@@ -13,7 +13,7 @@ fn test_dim()
1313 let ( mm, nn) = ( 5 , 5 ) ;
1414 for m in 0 ..mm {
1515 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 ( ) ) ;
1717 assert_eq ! ( a. shape( ) , & [ m, n] ) ;
1818 assert ! ( a. iter( ) . all( |x| * x < 2. ) ) ;
1919 assert ! ( a. iter( ) . all( |x| * x >= 0. ) ) ;
@@ -28,7 +28,7 @@ fn test_dim_f()
2828 let ( mm, nn) = ( 5 , 5 ) ;
2929 for m in 0 ..mm {
3030 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 ( ) ) ;
3232 assert_eq ! ( a. shape( ) , & [ m, n] ) ;
3333 assert ! ( a. iter( ) . all( |x| * x < 2. ) ) ;
3434 assert ! ( a. iter( ) . all( |x| * x >= 0. ) ) ;
@@ -41,7 +41,7 @@ fn test_dim_f()
4141fn sample_axis_on_view ( )
4242{
4343 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 ( ) ) ;
4545 let _samples = a
4646 . view ( )
4747 . sample_axis ( Axis ( 0 ) , m, SamplingStrategy :: WithoutReplacement ) ;
@@ -52,15 +52,15 @@ fn sample_axis_on_view()
5252fn oversampling_without_replacement_should_panic ( )
5353{
5454 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 ( ) ) ;
5656 let _samples = a. sample_axis ( Axis ( 0 ) , m + 1 , SamplingStrategy :: WithoutReplacement ) ;
5757}
5858
5959quickcheck ! {
6060 #[ cfg_attr( miri, ignore) ] // Takes an insufferably long time
6161 fn oversampling_with_replacement_is_fine( m: u8 , n: u8 ) -> TestResult {
6262 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 ( ) ) ;
6464 // Higher than the length of both axes
6565 let n_samples = m + n + 1 ;
6666
@@ -90,12 +90,12 @@ quickcheck! {
9090 #[ cfg_attr( miri, ignore) ] // This takes *forever* with Miri
9191 fn sampling_behaves_as_expected( m: u8 , n: u8 , strategy: SamplingStrategy ) -> TestResult {
9292 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 ( ) ;
9595
9696 // We don't want to deal with sampling from 0-length axes in this test
9797 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) ;
9999 if !sampling_works( & a, strategy. clone( ) , Axis ( 0 ) , n_row_samples) {
100100 return TestResult :: failed( ) ;
101101 }
@@ -105,7 +105,7 @@ quickcheck! {
105105
106106 // We don't want to deal with sampling from 0-length axes in this test
107107 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) ;
109109 if !sampling_works( & a, strategy, Axis ( 1 ) , n_col_samples) {
110110 return TestResult :: failed( ) ;
111111 }
@@ -136,7 +136,7 @@ fn is_subset(a: &Array2<f64>, b: &ArrayView1<f64>, axis: Axis) -> bool
136136fn sampling_without_replacement_from_a_zero_length_axis_should_panic ( )
137137{
138138 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 ( ) ) ;
140140 let _samples = a. sample_axis ( Axis ( 0 ) , 1 , SamplingStrategy :: WithoutReplacement ) ;
141141}
142142
@@ -145,6 +145,6 @@ fn sampling_without_replacement_from_a_zero_length_axis_should_panic()
145145fn sampling_with_replacement_from_a_zero_length_axis_should_panic ( )
146146{
147147 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 ( ) ) ;
149149 let _samples = a. sample_axis ( Axis ( 0 ) , 1 , SamplingStrategy :: WithReplacement ) ;
150150}
0 commit comments