Skip to content

Commit 07702a1

Browse files
max-sixtyLukeMathWalker
authored andcommitted
Upgrade to rand 0.7.0 (#659)
* upgrade to rand 0.7.0 * move benches to rand_distr * upgrade rand in numeric-tests too * not sure why we need extern crate but it seems we do?! * cargo fmt * move distributions to rand_distr * Normal now returns Result * bump ndarray-rand to 0.10.0 * bump required rust to 1.32 because of getrandom * rand_distr to dev dependencies * bump version, add note to readme * update benches * fix ndarray-rand edition idioms * cargo fmt after cargo fix * note in lib.rs * Improve formatting * Mention Rust 1.32 in ndarray-rand changelog
1 parent 32fb1a7 commit 07702a1

File tree

8 files changed

+49
-26
lines changed

8 files changed

+49
-26
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sudo: required
44
dist: trusty
55
matrix:
66
include:
7-
- rust: 1.31.0
7+
- rust: 1.32.0
88
env:
99
- FEATURES='test docs'
1010
- rust: stable

ndarray-rand/Cargo.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ndarray-rand"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
edition = "2018"
55
authors = ["bluss"]
66
license = "MIT/Apache-2.0"
@@ -13,9 +13,15 @@ description = "Constructors for randomized arrays. `rand` integration for `ndarr
1313
keywords = ["multidimensional", "matrix", "rand", "ndarray"]
1414

1515
[dependencies]
16-
rand = "0.6.0"
1716
ndarray = { version = "0.12.0", path = ".." }
1817

18+
[dependencies.rand]
19+
version = "0.7.0"
20+
features = ["small_rng"]
21+
22+
[dev-dependencies]
23+
rand_distr = "0.2.1"
24+
1925
[package.metadata.release]
2026
no-dev-version = true
2127

ndarray-rand/README.rst

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
ndarray-rand
22
============
33

4+
Dependencies
5+
------------
6+
7+
``ndarray-rand`` depends on ``rand`` 0.7. If you use any other items from
8+
``rand``, you need to specify a compatible version of ``rand`` in your
9+
``Cargo.toml``. If you want to use a RNG or distribution from another crate
10+
with ``ndarray-rand``, you need to make sure that crate also depends on the
11+
correct version of ``rand``. Otherwise, the compiler will return errors saying
12+
that the items are not compatible (e.g. that a type doesn't implement a
13+
necessary trait).
14+
415
Recent Changes
516
--------------
617

18+
- 0.10.0
19+
20+
- Require rand 0.7
21+
- Require Rust 1.32 or later
22+
723
- 0.9.0
824

925
- Require rand 0.6

ndarray-rand/benches/bench.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
11
#![feature(test)]
22

3-
extern crate ndarray;
4-
extern crate ndarray_rand;
5-
extern crate rand;
63
extern crate test;
74

85
use ndarray::Array;
96
use ndarray_rand::RandomExt;
107
use ndarray_rand::F32;
11-
use rand::distributions::Normal;
12-
use rand::distributions::Uniform;
8+
use rand_distr::Normal;
9+
use rand_distr::Uniform;
1310

1411
use test::Bencher;
1512

1613
#[bench]
1714
fn uniform_f32(b: &mut Bencher) {
1815
let m = 100;
19-
b.iter(|| {
20-
let a = Array::random((m, m), Uniform::new(-1f32, 1.));
21-
a
22-
});
16+
b.iter(|| Array::random((m, m), Uniform::new(-1f32, 1.)));
2317
}
2418

2519
#[bench]
2620
fn norm_f32(b: &mut Bencher) {
2721
let m = 100;
28-
b.iter(|| {
29-
let a = Array::random((m, m), F32(Normal::new(0., 1.)));
30-
a
31-
});
22+
b.iter(|| Array::random((m, m), F32(Normal::new(0., 1.).unwrap())));
3223
}
3324

3425
#[bench]
3526
fn norm_f64(b: &mut Bencher) {
3627
let m = 100;
37-
b.iter(|| {
38-
let a = Array::random((m, m), Normal::new(0., 1.));
39-
a
40-
});
28+
b.iter(|| Array::random((m, m), Normal::new(0., 1.).unwrap()));
4129
}

ndarray-rand/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
//! Constructors for randomized arrays. `rand` integration for `ndarray`.
1010
//!
1111
//! See [**`RandomExt`**](trait.RandomExt.html) for usage examples.
12+
//!
13+
//! **Note:** `ndarray-rand` depends on `rand` 0.7. If you use any other items
14+
//! from `rand`, you need to specify a compatible version of `rand` in your
15+
//! `Cargo.toml`. If you want to use a RNG or distribution from another crate
16+
//! with `ndarray-rand`, you need to make sure that crate also depends on the
17+
//! correct version of `rand`. Otherwise, the compiler will return errors
18+
//! saying that the items are not compatible (e.g. that a type doesn't
19+
//! implement a necessary trait).
1220
1321
use rand::distributions::Distribution;
1422
use rand::rngs::SmallRng;

numeric-tests/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ publish = false
88
approx = "0.3.2"
99
ndarray = { path = "..", features = ["approx"] }
1010
ndarray-rand = { path = "../ndarray-rand/" }
11-
rand = "0.6.0"
11+
rand_distr = "0.2.1"
12+
13+
[dependencies.rand]
14+
version = "0.7.0"
15+
features = ["small_rng"]
1216

1317
[lib]
1418
test = false

numeric-tests/tests/accuracy.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
extern crate approx;
2+
extern crate rand_distr;
23
extern crate ndarray;
34
extern crate ndarray_rand;
45
extern crate rand;
56

67
use ndarray_rand::{RandomExt, F32};
7-
use rand::{FromEntropy, Rng};
8+
use rand::{Rng, SeedableRng};
89
use rand::rngs::SmallRng;
910

1011
use ndarray::prelude::*;
@@ -14,7 +15,7 @@ use ndarray::{
1415
};
1516
use ndarray::linalg::general_mat_mul;
1617

17-
use rand::distributions::Normal;
18+
use rand_distr::Normal;
1819

1920
use approx::{assert_abs_diff_eq, assert_relative_eq};
2021

@@ -52,12 +53,12 @@ fn reference_mat_mul<A, S, S2>(lhs: &ArrayBase<S, Ix2>, rhs: &ArrayBase<S2, Ix2>
5253
fn gen<D>(d: D) -> Array<f32, D>
5354
where D: Dimension,
5455
{
55-
Array::random(d, F32(Normal::new(0., 1.)))
56+
Array::random(d, F32(Normal::new(0., 1.).unwrap()))
5657
}
5758
fn gen_f64<D>(d: D) -> Array<f64, D>
5859
where D: Dimension,
5960
{
60-
Array::random(d, Normal::new(0., 1.))
61+
Array::random(d, Normal::new(0., 1.).unwrap())
6162
}
6263

6364
#[test]

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//! needs matching memory layout to be efficient (with some exceptions).
6262
//! + Efficient floating point matrix multiplication even for very large
6363
//! matrices; can optionally use BLAS to improve it further.
64-
//! - **Requires Rust 1.31**
64+
//! - **Requires Rust 1.32**
6565
//!
6666
//! ## Crate Feature Flags
6767
//!

0 commit comments

Comments
 (0)