Skip to content

Commit 9f2cc3d

Browse files
committed
Bump rand to 0.9.0 and rand_distr to 0.5.0
1 parent 41bace1 commit 9f2cc3d

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ num-traits = { version = "0.2", default-features = false }
9696
num-complex = { version = "0.4", default-features = false }
9797
approx = { version = "0.5", default-features = false }
9898
quickcheck = { version = "1.0", default-features = false }
99-
rand = { version = "0.8.0", features = ["small_rng"] }
100-
rand_distr = { version = "0.4.0" }
99+
rand = { version = "0.9.0", features = ["small_rng"] }
100+
rand_distr = { version = "0.5.0" }
101101
itertools = { version = "0.13.0", default-features = false, features = ["use_std"] }
102102
cblas-sys = { version = "0.1.4", default-features = false }
103103

ndarray-rand/benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use test::Bencher;
1313
fn uniform_f32(b: &mut Bencher)
1414
{
1515
let m = 100;
16-
b.iter(|| Array::random((m, m), Uniform::new(-1f32, 1.)));
16+
b.iter(|| Array::random((m, m), Uniform::new(-1f32, 1.).unwrap()));
1717
}
1818

1919
#[bench]

ndarray-rand/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
//! that the items are not compatible (e.g. that a type doesn't implement a
3030
//! necessary trait).
3131
32-
use crate::rand::distributions::{Distribution, Uniform};
32+
use crate::rand::distr::{Distribution, Uniform};
3333
use crate::rand::rngs::SmallRng;
3434
use crate::rand::seq::index;
35-
use crate::rand::{thread_rng, Rng, SeedableRng};
35+
use crate::rand::{rng, Rng, SeedableRng};
3636

3737
use ndarray::{Array, Axis, RemoveAxis, ShapeBuilder};
3838
use ndarray::{ArrayBase, Data, DataOwned, Dimension, RawData};
@@ -71,8 +71,8 @@ where
7171
/// Create an array with shape `dim` with elements drawn from
7272
/// `distribution` using the default RNG.
7373
///
74-
/// ***Panics*** if creation of the RNG fails or if the number of elements
75-
/// overflows usize.
74+
/// ***Panics*** if creation of the RNG fails, the number of elements
75+
/// overflows usize, or the axis has zero length.
7676
///
7777
/// ```
7878
/// use ndarray::Array;
@@ -95,7 +95,8 @@ where
9595
/// Create an array with shape `dim` with elements drawn from
9696
/// `distribution`, using a specific Rng `rng`.
9797
///
98-
/// ***Panics*** if the number of elements overflows usize.
98+
/// ***Panics*** if the number of elements overflows usize
99+
/// or the axis has zero length.
99100
///
100101
/// ```
101102
/// use ndarray::Array;
@@ -270,7 +271,7 @@ where
270271
{
271272
let indices: Vec<_> = match strategy {
272273
SamplingStrategy::WithReplacement => {
273-
let distribution = Uniform::from(0..self.len_of(axis));
274+
let distribution = Uniform::new(0, self.len_of(axis)).unwrap();
274275
(0..n_samples).map(|_| distribution.sample(rng)).collect()
275276
}
276277
SamplingStrategy::WithoutReplacement => index::sample(rng, self.len_of(axis), n_samples).into_vec(),
@@ -308,5 +309,5 @@ impl Arbitrary for SamplingStrategy
308309

309310
fn get_rng() -> SmallRng
310311
{
311-
SmallRng::from_rng(thread_rng()).expect("create SmallRng from thread_rng failed")
312+
SmallRng::from_rng(&mut rng())
312313
}

ndarray-rand/tests/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
4141
fn 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()
5252
fn 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

5959
quickcheck! {
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

@@ -136,7 +136,7 @@ fn is_subset(a: &Array2<f64>, b: &ArrayView1<f64>, axis: Axis) -> bool
136136
fn 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()
145145
fn 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

Comments
 (0)