Skip to content

Commit eb589ab

Browse files
jturner314LukeMathWalker
authored andcommitted
Update to Rust 2018 and replace quickcheck! with #[quickcheck] (#40)
* Update to Rust 2018 * Replace quickcheck! with #[quickcheck] * Update to Rust 2018 idioms * Run cargo fmt * Bump Rust version to 1.34 * Fix merge mistakes
1 parent 4c52651 commit eb589ab

17 files changed

+186
-277
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ addons:
77
- libssl-dev
88
cache: cargo
99
rust:
10-
- 1.31.0
10+
- 1.34.0
1111
- stable
1212
- beta
1313
- nightly

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "ndarray-stats"
33
version = "0.1.0"
44
authors = ["Jim Turner <[email protected]>", "LukeMathWalker <[email protected]>"]
5+
edition = "2018"
56

67
license = "MIT/Apache-2.0"
78

benches/sort.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
extern crate criterion;
2-
extern crate ndarray;
3-
extern crate ndarray_stats;
4-
extern crate rand;
5-
61
use criterion::{
72
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion,
83
ParameterizedBenchmark, PlotConfiguration,

src/correlation.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ where
4949
/// # Example
5050
///
5151
/// ```
52-
/// extern crate ndarray;
53-
/// extern crate ndarray_stats;
5452
/// use ndarray::{aview2, arr2};
5553
/// use ndarray_stats::CorrelationExt;
5654
///
@@ -98,8 +96,6 @@ where
9896
///
9997
/// variables is zero and division by zero panics for type A.
10098
/// ```
101-
/// extern crate ndarray;
102-
/// extern crate ndarray_stats;
10399
/// use ndarray::arr2;
104100
/// use ndarray_stats::CorrelationExt;
105101
///
@@ -175,31 +171,31 @@ mod cov_tests {
175171
use super::*;
176172
use ndarray::array;
177173
use ndarray_rand::RandomExt;
178-
use quickcheck::quickcheck;
174+
use quickcheck_macros::quickcheck;
179175
use rand;
180176
use rand::distributions::Uniform;
181177

182-
quickcheck! {
183-
fn constant_random_variables_have_zero_covariance_matrix(value: f64) -> bool {
184-
let n_random_variables = 3;
185-
let n_observations = 4;
186-
let a = Array::from_elem((n_random_variables, n_observations), value);
187-
a.cov(1.).all_close(
188-
&Array::zeros((n_random_variables, n_random_variables)),
189-
1e-8
190-
)
191-
}
178+
#[quickcheck]
179+
fn constant_random_variables_have_zero_covariance_matrix(value: f64) -> bool {
180+
let n_random_variables = 3;
181+
let n_observations = 4;
182+
let a = Array::from_elem((n_random_variables, n_observations), value);
183+
a.cov(1.).all_close(
184+
&Array::zeros((n_random_variables, n_random_variables)),
185+
1e-8,
186+
)
187+
}
192188

193-
fn covariance_matrix_is_symmetric(bound: f64) -> bool {
194-
let n_random_variables = 3;
195-
let n_observations = 4;
196-
let a = Array::random(
197-
(n_random_variables, n_observations),
198-
Uniform::new(-bound.abs(), bound.abs())
199-
);
200-
let covariance = a.cov(1.);
201-
covariance.all_close(&covariance.t(), 1e-8)
202-
}
189+
#[quickcheck]
190+
fn covariance_matrix_is_symmetric(bound: f64) -> bool {
191+
let n_random_variables = 3;
192+
let n_observations = 4;
193+
let a = Array::random(
194+
(n_random_variables, n_observations),
195+
Uniform::new(-bound.abs(), bound.abs()),
196+
);
197+
let covariance = a.cov(1.);
198+
covariance.all_close(&covariance.t(), 1e-8)
203199
}
204200

205201
#[test]
@@ -277,28 +273,31 @@ mod pearson_correlation_tests {
277273
use super::*;
278274
use ndarray::array;
279275
use ndarray_rand::RandomExt;
280-
use quickcheck::quickcheck;
276+
use quickcheck_macros::quickcheck;
281277
use rand::distributions::Uniform;
282278

283-
quickcheck! {
284-
fn output_matrix_is_symmetric(bound: f64) -> bool {
285-
let n_random_variables = 3;
286-
let n_observations = 4;
287-
let a = Array::random(
288-
(n_random_variables, n_observations),
289-
Uniform::new(-bound.abs(), bound.abs())
290-
);
291-
let pearson_correlation = a.pearson_correlation();
292-
pearson_correlation.all_close(&pearson_correlation.t(), 1e-8)
293-
}
279+
#[quickcheck]
280+
fn output_matrix_is_symmetric(bound: f64) -> bool {
281+
let n_random_variables = 3;
282+
let n_observations = 4;
283+
let a = Array::random(
284+
(n_random_variables, n_observations),
285+
Uniform::new(-bound.abs(), bound.abs()),
286+
);
287+
let pearson_correlation = a.pearson_correlation();
288+
pearson_correlation.all_close(&pearson_correlation.t(), 1e-8)
289+
}
294290

295-
fn constant_random_variables_have_nan_correlation(value: f64) -> bool {
296-
let n_random_variables = 3;
297-
let n_observations = 4;
298-
let a = Array::from_elem((n_random_variables, n_observations), value);
299-
let pearson_correlation = a.pearson_correlation();
300-
pearson_correlation.iter().map(|x| x.is_nan()).fold(true, |acc, flag| acc & flag)
301-
}
291+
#[quickcheck]
292+
fn constant_random_variables_have_nan_correlation(value: f64) -> bool {
293+
let n_random_variables = 3;
294+
let n_observations = 4;
295+
let a = Array::from_elem((n_random_variables, n_observations), value);
296+
let pearson_correlation = a.pearson_correlation();
297+
pearson_correlation
298+
.iter()
299+
.map(|x| x.is_nan())
300+
.fold(true, |acc, flag| acc & flag)
302301
}
303302

304303
#[test]

src/entropy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ where
221221
#[cfg(test)]
222222
mod tests {
223223
use super::EntropyExt;
224+
use crate::errors::{EmptyInput, MultiInputError};
224225
use approx::assert_abs_diff_eq;
225-
use errors::{EmptyInput, MultiInputError};
226226
use ndarray::{array, Array1};
227227
use noisy_float::types::n64;
228228
use std::f64;

src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt;
88
pub struct EmptyInput;
99

1010
impl fmt::Display for EmptyInput {
11-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1212
write!(f, "Empty input.")
1313
}
1414
}
@@ -25,7 +25,7 @@ pub enum MinMaxError {
2525
}
2626

2727
impl fmt::Display for MinMaxError {
28-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2929
match self {
3030
MinMaxError::EmptyInput => write!(f, "Empty input."),
3131
MinMaxError::UndefinedOrder => {
@@ -53,7 +53,7 @@ pub struct ShapeMismatch {
5353
}
5454

5555
impl fmt::Display for ShapeMismatch {
56-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5757
write!(
5858
f,
5959
"Array shapes do not match: {:?} and {:?}.",
@@ -92,7 +92,7 @@ impl MultiInputError {
9292
}
9393

9494
impl fmt::Display for MultiInputError {
95-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9696
match self {
9797
MultiInputError::EmptyInput => write!(f, "Empty input."),
9898
MultiInputError::ShapeMismatch(e) => write!(f, "Shape mismatch: {}", e),
@@ -124,7 +124,7 @@ pub enum QuantileError {
124124
}
125125

126126
impl fmt::Display for QuantileError {
127-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128128
match self {
129129
QuantileError::EmptyInput => write!(f, "Empty input."),
130130
QuantileError::InvalidQuantile(q) => {

0 commit comments

Comments
 (0)