Skip to content

Update to Rust 2018 and replace quickcheck! with #[quickcheck] #40

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

Merged
merged 7 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -7,7 +7,7 @@ addons:
- libssl-dev
cache: cargo
rust:
- 1.31.0
- 1.34.0
- stable
- beta
- nightly
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "ndarray-stats"
version = "0.1.0"
authors = ["Jim Turner <ndarray-stats@turner.link>", "LukeMathWalker <rust@lpalmieri.com>"]
edition = "2018"

license = "MIT/Apache-2.0"

Expand Down
5 changes: 0 additions & 5 deletions benches/sort.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
extern crate criterion;
extern crate ndarray;
extern crate ndarray_stats;
extern crate rand;

use criterion::{
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion,
ParameterizedBenchmark, PlotConfiguration,
Expand Down
87 changes: 43 additions & 44 deletions src/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ where
/// # Example
///
/// ```
/// extern crate ndarray;
/// extern crate ndarray_stats;
/// use ndarray::{aview2, arr2};
/// use ndarray_stats::CorrelationExt;
///
Expand Down Expand Up @@ -98,8 +96,6 @@ where
///
/// variables is zero and division by zero panics for type A.
/// ```
/// extern crate ndarray;
/// extern crate ndarray_stats;
/// use ndarray::arr2;
/// use ndarray_stats::CorrelationExt;
///
Expand Down Expand Up @@ -175,31 +171,31 @@ mod cov_tests {
use super::*;
use ndarray::array;
use ndarray_rand::RandomExt;
use quickcheck::quickcheck;
use quickcheck_macros::quickcheck;
use rand;
use rand::distributions::Uniform;

quickcheck! {
fn constant_random_variables_have_zero_covariance_matrix(value: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::from_elem((n_random_variables, n_observations), value);
a.cov(1.).all_close(
&Array::zeros((n_random_variables, n_random_variables)),
1e-8
)
}
#[quickcheck]
fn constant_random_variables_have_zero_covariance_matrix(value: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::from_elem((n_random_variables, n_observations), value);
a.cov(1.).all_close(
&Array::zeros((n_random_variables, n_random_variables)),
1e-8,
)
}

fn covariance_matrix_is_symmetric(bound: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::random(
(n_random_variables, n_observations),
Uniform::new(-bound.abs(), bound.abs())
);
let covariance = a.cov(1.);
covariance.all_close(&covariance.t(), 1e-8)
}
#[quickcheck]
fn covariance_matrix_is_symmetric(bound: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::random(
(n_random_variables, n_observations),
Uniform::new(-bound.abs(), bound.abs()),
);
let covariance = a.cov(1.);
covariance.all_close(&covariance.t(), 1e-8)
}

#[test]
Expand Down Expand Up @@ -277,28 +273,31 @@ mod pearson_correlation_tests {
use super::*;
use ndarray::array;
use ndarray_rand::RandomExt;
use quickcheck::quickcheck;
use quickcheck_macros::quickcheck;
use rand::distributions::Uniform;

quickcheck! {
fn output_matrix_is_symmetric(bound: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::random(
(n_random_variables, n_observations),
Uniform::new(-bound.abs(), bound.abs())
);
let pearson_correlation = a.pearson_correlation();
pearson_correlation.all_close(&pearson_correlation.t(), 1e-8)
}
#[quickcheck]
fn output_matrix_is_symmetric(bound: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::random(
(n_random_variables, n_observations),
Uniform::new(-bound.abs(), bound.abs()),
);
let pearson_correlation = a.pearson_correlation();
pearson_correlation.all_close(&pearson_correlation.t(), 1e-8)
}

fn constant_random_variables_have_nan_correlation(value: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::from_elem((n_random_variables, n_observations), value);
let pearson_correlation = a.pearson_correlation();
pearson_correlation.iter().map(|x| x.is_nan()).fold(true, |acc, flag| acc & flag)
}
#[quickcheck]
fn constant_random_variables_have_nan_correlation(value: f64) -> bool {
let n_random_variables = 3;
let n_observations = 4;
let a = Array::from_elem((n_random_variables, n_observations), value);
let pearson_correlation = a.pearson_correlation();
pearson_correlation
.iter()
.map(|x| x.is_nan())
.fold(true, |acc, flag| acc & flag)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ where
#[cfg(test)]
mod tests {
use super::EntropyExt;
use crate::errors::{EmptyInput, MultiInputError};
use approx::assert_abs_diff_eq;
use errors::{EmptyInput, MultiInputError};
use ndarray::{array, Array1};
use noisy_float::types::n64;
use std::f64;
Expand Down
10 changes: 5 additions & 5 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt;
pub struct EmptyInput;

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

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

impl fmt::Display for ShapeMismatch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Array shapes do not match: {:?} and {:?}.",
Expand Down Expand Up @@ -92,7 +92,7 @@ impl MultiInputError {
}

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

impl fmt::Display for QuantileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
QuantileError::EmptyInput => write!(f, "Empty input."),
QuantileError::InvalidQuantile(q) => {
Expand Down
Loading