Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to rand 0.7.0 #659

Merged
merged 22 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: required
dist: trusty
matrix:
include:
- rust: 1.31.0
- rust: 1.32.0
env:
- FEATURES='test docs'
- rust: stable
Expand Down
10 changes: 8 additions & 2 deletions ndarray-rand/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ndarray-rand"
version = "0.9.0"
version = "0.10.0"
edition = "2018"
authors = ["bluss"]
license = "MIT/Apache-2.0"
Expand All @@ -13,9 +13,15 @@ description = "Constructors for randomized arrays. `rand` integration for `ndarr
keywords = ["multidimensional", "matrix", "rand", "ndarray"]

[dependencies]
rand = "0.6.0"
ndarray = { version = "0.12.0", path = ".." }

[dependencies.rand]
version = "0.7.0"
features = ["small_rng"]

[dev-dependencies]
rand_distr = "0.2.1"

[package.metadata.release]
no-dev-version = true

15 changes: 15 additions & 0 deletions ndarray-rand/README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
ndarray-rand
============

Dependencies
------------

``ndarray-rand`` depends on ``rand`` 0.7. If you use any other items from
``rand``, you need to specify a compatible version of ``rand`` in your
``Cargo.toml``. If you want to use a RNG or distribution from another crate
with ``ndarray-rand``, you need to make sure that crate also depends on the
correct version of ``rand``. Otherwise, the compiler will return errors saying
that the items are not compatible (e.g. that a type doesn't implement a
necessary trait).
jturner314 marked this conversation as resolved.
Show resolved Hide resolved

Recent Changes
--------------

- 0.10.0

- Require rand 0.7

- 0.9.0

- Require rand 0.6
Expand Down
22 changes: 5 additions & 17 deletions ndarray-rand/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
#![feature(test)]

extern crate ndarray;
extern crate ndarray_rand;
extern crate rand;
extern crate test;

use ndarray::Array;
use ndarray_rand::RandomExt;
use ndarray_rand::F32;
use rand::distributions::Normal;
use rand::distributions::Uniform;
use rand_distr::Normal;
use rand_distr::Uniform;

use test::Bencher;

#[bench]
fn uniform_f32(b: &mut Bencher) {
let m = 100;
b.iter(|| {
let a = Array::random((m, m), Uniform::new(-1f32, 1.));
a
});
b.iter(|| Array::random((m, m), Uniform::new(-1f32, 1.)));
}

#[bench]
fn norm_f32(b: &mut Bencher) {
let m = 100;
b.iter(|| {
let a = Array::random((m, m), F32(Normal::new(0., 1.)));
a
});
b.iter(|| Array::random((m, m), F32(Normal::new(0., 1.).unwrap())));
}

#[bench]
fn norm_f64(b: &mut Bencher) {
let m = 100;
b.iter(|| {
let a = Array::random((m, m), Normal::new(0., 1.));
a
});
b.iter(|| Array::random((m, m), Normal::new(0., 1.).unwrap()));
}
8 changes: 8 additions & 0 deletions ndarray-rand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
//! Constructors for randomized arrays. `rand` integration for `ndarray`.
//!
//! See [**`RandomExt`**](trait.RandomExt.html) for usage examples.
//!
//! **Note:** `ndarray-rand` depends on `rand` 0.7. If you use any other items
//! from `rand`, you need to specify a compatible version of `rand` in your
//! `Cargo.toml`. If you want to use a RNG or distribution from another crate
//! with `ndarray-rand`, you need to make sure that crate also depends on the
//! correct version of `rand`. Otherwise, the compiler will return errors
//! saying that the items are not compatible (e.g. that a type doesn't
//! implement a necessary trait).

use rand::distributions::Distribution;
use rand::rngs::SmallRng;
Expand Down
6 changes: 5 additions & 1 deletion numeric-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ publish = false
approx = "0.3.2"
ndarray = { path = "..", features = ["approx"] }
ndarray-rand = { path = "../ndarray-rand/" }
rand = "0.6.0"
rand_distr = "0.2.1"

[dependencies.rand]
version = "0.7.0"
features = ["small_rng"]

[lib]
test = false
Expand Down
9 changes: 5 additions & 4 deletions numeric-tests/tests/accuracy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
extern crate approx;
extern crate rand_distr;
extern crate ndarray;
extern crate ndarray_rand;
extern crate rand;

use ndarray_rand::{RandomExt, F32};
use rand::{FromEntropy, Rng};
use rand::{Rng, SeedableRng};
use rand::rngs::SmallRng;

use ndarray::prelude::*;
Expand All @@ -14,7 +15,7 @@ use ndarray::{
};
use ndarray::linalg::general_mat_mul;

use rand::distributions::Normal;
use rand_distr::Normal;

use approx::{assert_abs_diff_eq, assert_relative_eq};

Expand Down Expand Up @@ -52,12 +53,12 @@ fn reference_mat_mul<A, S, S2>(lhs: &ArrayBase<S, Ix2>, rhs: &ArrayBase<S2, Ix2>
fn gen<D>(d: D) -> Array<f32, D>
where D: Dimension,
{
Array::random(d, F32(Normal::new(0., 1.)))
Array::random(d, F32(Normal::new(0., 1.).unwrap()))
}
fn gen_f64<D>(d: D) -> Array<f64, D>
where D: Dimension,
{
Array::random(d, Normal::new(0., 1.))
Array::random(d, Normal::new(0., 1.).unwrap())
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
//! needs matching memory layout to be efficient (with some exceptions).
//! + Efficient floating point matrix multiplication even for very large
//! matrices; can optionally use BLAS to improve it further.
//! - **Requires Rust 1.31**
//! - **Requires Rust 1.32**
//!
//! ## Crate Feature Flags
//!
Expand Down