Skip to content

Commit e6df0ae

Browse files
committed
Update to Rust 2018 idioms
1 parent 346f377 commit e6df0ae

File tree

14 files changed

+21
-112
lines changed

14 files changed

+21
-112
lines changed

benches/sort.rs

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 4 deletions
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
///

src/errors.rs

Lines changed: 5 additions & 5 deletions
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) => {

src/histogram/bins.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::ops::{Index, Range};
99
/// # Example:
1010
///
1111
/// ```
12-
/// extern crate ndarray_stats;
13-
/// extern crate noisy_float;
1412
/// use ndarray_stats::histogram::{Edges, Bins};
1513
/// use noisy_float::types::n64;
1614
///
@@ -41,19 +39,15 @@ impl<A: Ord> From<Vec<A>> for Edges<A> {
4139
/// # Example:
4240
///
4341
/// ```
44-
/// extern crate ndarray_stats;
45-
/// #[macro_use(array)]
46-
/// extern crate ndarray;
42+
/// use ndarray::array;
4743
/// use ndarray_stats::histogram::Edges;
4844
///
49-
/// # fn main() {
5045
/// let edges = Edges::from(array![1, 15, 10, 10, 20]);
5146
/// // The array gets sorted!
5247
/// assert_eq!(
5348
/// edges[2],
5449
/// 15
5550
/// );
56-
/// # }
5751
/// ```
5852
fn from(mut edges: Vec<A>) -> Self {
5953
// sort the array in-place
@@ -72,7 +66,6 @@ impl<A: Ord + Clone> From<Array1<A>> for Edges<A> {
7266
/// # Example:
7367
///
7468
/// ```
75-
/// extern crate ndarray_stats;
7669
/// use ndarray_stats::histogram::Edges;
7770
///
7871
/// let edges = Edges::from(vec![1, 15, 10, 20]);
@@ -98,7 +91,6 @@ impl<A: Ord> Index<usize> for Edges<A> {
9891
/// # Example:
9992
///
10093
/// ```
101-
/// extern crate ndarray_stats;
10294
/// use ndarray_stats::histogram::Edges;
10395
///
10496
/// let edges = Edges::from(vec![1, 5, 10, 20]);
@@ -118,8 +110,6 @@ impl<A: Ord> Edges<A> {
118110
/// # Example:
119111
///
120112
/// ```
121-
/// extern crate ndarray_stats;
122-
/// extern crate noisy_float;
123113
/// use ndarray_stats::histogram::Edges;
124114
/// use noisy_float::types::n64;
125115
///
@@ -139,8 +129,6 @@ impl<A: Ord> Edges<A> {
139129
/// # Example:
140130
///
141131
/// ```
142-
/// extern crate ndarray;
143-
/// extern crate ndarray_stats;
144132
/// use ndarray::array;
145133
/// use ndarray_stats::histogram::Edges;
146134
///
@@ -150,7 +138,7 @@ impl<A: Ord> Edges<A> {
150138
/// array![0, 3, 5].view()
151139
/// );
152140
/// ```
153-
pub fn as_array_view(&self) -> ArrayView1<A> {
141+
pub fn as_array_view(&self) -> ArrayView1<'_, A> {
154142
ArrayView1::from(&self.edges)
155143
}
156144

@@ -162,7 +150,6 @@ impl<A: Ord> Edges<A> {
162150
/// # Example:
163151
///
164152
/// ```
165-
/// extern crate ndarray_stats;
166153
/// use ndarray_stats::histogram::Edges;
167154
///
168155
/// let edges = Edges::from(vec![0, 2, 3]);
@@ -202,8 +189,6 @@ impl<A: Ord> Edges<A> {
202189
/// # Example:
203190
///
204191
/// ```
205-
/// extern crate ndarray_stats;
206-
/// extern crate noisy_float;
207192
/// use ndarray_stats::histogram::{Edges, Bins};
208193
/// use noisy_float::types::n64;
209194
///
@@ -238,8 +223,6 @@ impl<A: Ord> Bins<A> {
238223
/// # Example:
239224
///
240225
/// ```
241-
/// extern crate ndarray_stats;
242-
/// extern crate noisy_float;
243226
/// use ndarray_stats::histogram::{Edges, Bins};
244227
/// use noisy_float::types::n64;
245228
///
@@ -264,7 +247,6 @@ impl<A: Ord> Bins<A> {
264247
/// # Example:
265248
///
266249
/// ```
267-
/// extern crate ndarray_stats;
268250
/// use ndarray_stats::histogram::{Edges, Bins};
269251
///
270252
/// let edges = Edges::from(vec![0, 2, 4, 6]);
@@ -291,7 +273,6 @@ impl<A: Ord> Bins<A> {
291273
/// # Example:
292274
///
293275
/// ```
294-
/// extern crate ndarray_stats;
295276
/// use ndarray_stats::histogram::{Edges, Bins};
296277
///
297278
/// let edges = Edges::from(vec![0, 2, 4, 6]);
@@ -323,7 +304,6 @@ impl<A: Ord> Bins<A> {
323304
/// # Example:
324305
///
325306
/// ```
326-
/// extern crate ndarray_stats;
327307
/// use ndarray_stats::histogram::{Edges, Bins};
328308
///
329309
/// let edges = Edges::from(vec![1, 5, 10, 20]);

src/histogram/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt;
77
pub struct BinNotFound;
88

99
impl fmt::Display for BinNotFound {
10-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1111
write!(f, "No bin has been found.")
1212
}
1313
}
@@ -48,7 +48,7 @@ impl BinsBuildError {
4848
}
4949

5050
impl fmt::Display for BinsBuildError {
51-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5252
write!(f, "The strategy failed to determine a non-zero bin width.")
5353
}
5454
}

src/histogram/grid.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ use std::ops::Range;
3737
/// # Example:
3838
///
3939
/// ```
40-
/// extern crate ndarray_stats;
41-
/// extern crate ndarray;
42-
/// extern crate noisy_float;
4340
/// use ndarray::{Array, array};
4441
/// use ndarray_stats::{HistogramExt,
4542
/// histogram::{Histogram, Grid, GridBuilder,
4643
/// Edges, Bins, strategies::Auto}};
4744
/// use noisy_float::types::{N64, n64};
4845
///
49-
/// # fn main() {
5046
/// // 1-dimensional observations, as a (n_observations, 1) 2-d matrix
5147
/// let observations = Array::from_shape_vec(
5248
/// (12, 1),
@@ -65,7 +61,6 @@ use std::ops::Range;
6561
/// // Bins are left inclusive, right exclusive!
6662
/// let expected = array![4, 3, 3, 1, 0, 1];
6763
/// assert_eq!(histogram_matrix, expected.into_dyn());
68-
/// # }
6964
/// ```
7065
#[derive(Clone, Debug, Eq, PartialEq)]
7166
pub struct Grid<A: Ord> {

src/histogram/histograms.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ impl<A: Ord> Histogram<A> {
2424
///
2525
/// # Example:
2626
/// ```
27-
/// extern crate ndarray_stats;
28-
/// extern crate ndarray;
29-
/// extern crate noisy_float;
3027
/// use ndarray::array;
3128
/// use ndarray_stats::histogram::{Edges, Bins, Histogram, Grid};
3229
/// use noisy_float::types::n64;
@@ -70,7 +67,7 @@ impl<A: Ord> Histogram<A> {
7067
}
7168

7269
/// Borrows a view on the histogram counts matrix.
73-
pub fn counts(&self) -> ArrayViewD<usize> {
70+
pub fn counts(&self) -> ArrayViewD<'_, usize> {
7471
self.counts.view()
7572
}
7673

@@ -103,10 +100,7 @@ where
103100
/// # Example:
104101
///
105102
/// ```
106-
/// extern crate ndarray_stats;
107-
/// #[macro_use(array)]
108-
/// extern crate ndarray;
109-
/// extern crate noisy_float;
103+
/// use ndarray::array;
110104
/// use ndarray_stats::{
111105
/// HistogramExt,
112106
/// histogram::{
@@ -116,7 +110,6 @@ where
116110
/// };
117111
/// use noisy_float::types::{N64, n64};
118112
///
119-
/// # fn main() {
120113
/// let observations = array![
121114
/// [n64(1.), n64(0.5)],
122115
/// [n64(-0.5), n64(1.)],
@@ -142,7 +135,6 @@ where
142135
/// [0, 1, 0],
143136
/// ];
144137
/// assert_eq!(histogram_matrix, expected.into_dyn());
145-
/// # }
146138
/// ```
147139
fn histogram(&self, grid: Grid<A>) -> Histogram<A>
148140
where

src/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@
2525
//! [`NumPy`]: https://docs.scipy.org/doc/numpy-1.14.1/reference/routines.statistics.html
2626
//! [`StatsBase.jl`]: https://juliastats.github.io/StatsBase.jl/latest/
2727
28-
extern crate indexmap;
29-
extern crate itertools;
30-
extern crate ndarray;
31-
extern crate noisy_float;
32-
extern crate num_integer;
33-
extern crate num_traits;
34-
extern crate rand;
35-
36-
#[cfg(test)]
37-
extern crate approx;
38-
#[cfg(test)]
39-
extern crate ndarray_rand;
40-
#[cfg(test)]
41-
extern crate quickcheck;
42-
4328
pub use crate::correlation::CorrelationExt;
4429
pub use crate::entropy::EntropyExt;
4530
pub use crate::histogram::HistogramExt;

src/maybe_nan/impl_not_none.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<T> DerefMut for NotNone<T> {
2424
}
2525

2626
impl<T: fmt::Display> fmt::Display for NotNone<T> {
27-
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
27+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
2828
self.deref().fmt(f)
2929
}
3030
}

src/maybe_nan/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pub trait MaybeNan: Sized {
3636
/// order of the elements is unspecified. However, this method is
3737
/// idempotent, and given the same input data, the result is always ordered
3838
/// the same way.
39-
fn remove_nan_mut(_: ArrayViewMut1<Self>) -> ArrayViewMut1<Self::NotNan>;
39+
fn remove_nan_mut(_: ArrayViewMut1<'_, Self>) -> ArrayViewMut1<'_, Self::NotNan>;
4040
}
4141

4242
/// Returns a view with the NaN values removed.
4343
///
4444
/// This modifies the input view by moving elements as necessary.
45-
fn remove_nan_mut<A: MaybeNan>(mut view: ArrayViewMut1<A>) -> ArrayViewMut1<A> {
45+
fn remove_nan_mut<A: MaybeNan>(mut view: ArrayViewMut1<'_, A>) -> ArrayViewMut1<'_, A> {
4646
if view.len() == 0 {
4747
return view.slice_move(s![..0]);
4848
}
@@ -100,7 +100,7 @@ macro_rules! impl_maybenan_for_fxx {
100100
}
101101
}
102102

103-
fn remove_nan_mut(view: ArrayViewMut1<$fxx>) -> ArrayViewMut1<$Nxx> {
103+
fn remove_nan_mut(view: ArrayViewMut1<'_, $fxx>) -> ArrayViewMut1<'_, $Nxx> {
104104
let not_nan = remove_nan_mut(view);
105105
// This is safe because `remove_nan_mut` has removed the NaN
106106
// values, and `$Nxx` is a thin wrapper around `$fxx`.
@@ -150,7 +150,7 @@ macro_rules! impl_maybenan_for_opt_never_nan {
150150
}
151151
}
152152

153-
fn remove_nan_mut(view: ArrayViewMut1<Self>) -> ArrayViewMut1<Self::NotNan> {
153+
fn remove_nan_mut(view: ArrayViewMut1<'_, Self>) -> ArrayViewMut1<'_, Self::NotNan> {
154154
let not_nan = remove_nan_mut(view);
155155
// This is safe because `remove_nan_mut` has removed the `None`
156156
// values, and `NotNone<$ty>` is a thin wrapper around `Option<$ty>`.

0 commit comments

Comments
 (0)