Skip to content

Commit

Permalink
chore: update clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed Nov 21, 2023
1 parent dbdc2b2 commit d372300
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/cluster/dbscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>, D: Distance<Vec<TX>>>
}
}

while !neighbors.is_empty() {
let neighbor = neighbors.pop().unwrap();
while let Some(neighbor) = neighbors.pop() {
let index = neighbor.0;

if y[index] == outlier {
Expand Down
6 changes: 2 additions & 4 deletions src/linalg/basic/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
_ => max,
}
};
self.iterator(0)
.fold(T::min_value(), |max, x| max_f(max, x))
self.iterator(0).fold(T::min_value(), max_f)
}
/// return min value from the view
fn min(&self) -> T
Expand All @@ -202,8 +201,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
_ => min,
}
};
self.iterator(0)
.fold(T::max_value(), |max, x| min_f(max, x))
self.iterator(0).fold(T::max_value(), min_f)
}
/// return the position of the max value of the view
fn argmax(&self) -> usize
Expand Down
2 changes: 1 addition & 1 deletion src/linalg/basic/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ mod tests {

#[test]
fn test_from_iterator() {
let data = vec![1, 2, 3, 4, 5, 6];
let data = [1, 2, 3, 4, 5, 6];

let m = DenseMatrix::from_iterator(data.iter(), 2, 3, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/linalg/basic/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mod tests {

#[test]
fn test_len() {
let x = vec![1, 2, 3];
let x = [1, 2, 3];
assert_eq!(3, x.len());
}

Expand Down
2 changes: 1 addition & 1 deletion src/linear/bg_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod tests {
fn bg_solver() {
let a = DenseMatrix::from_2d_array(&[&[25., 15., -5.], &[15., 18., 0.], &[-5., 0., 11.]]);
let b = vec![40., 51., 28.];
let expected = vec![1.0, 2.0, 3.0];
let expected = [1.0, 2.0, 3.0];

let mut x = Vec::zeros(3);

Expand Down
6 changes: 1 addition & 5 deletions src/linear/logistic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,7 @@ mod tests {

let y_hat = lr.predict(&x).unwrap();

let error: i32 = y
.into_iter()
.zip(y_hat.into_iter())
.map(|(a, b)| (a - b).abs())
.sum();
let error: i32 = y.into_iter().zip(y_hat).map(|(a, b)| (a - b).abs()).sum();

assert!(error <= 1);

Expand Down
4 changes: 2 additions & 2 deletions src/neighbors/knn_regressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod tests {
let x =
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
let y_exp = vec![1., 2., 3., 4., 5.];
let y_exp = [1., 2., 3., 4., 5.];
let knn = KNNRegressor::fit(
&x,
&y,
Expand All @@ -324,7 +324,7 @@ mod tests {
let x =
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
let y_exp = vec![2., 2., 3., 4., 4.];
let y_exp = [2., 2., 3., 4., 4.];
let knn = KNNRegressor::fit(&x, &y, Default::default()).unwrap();
let y_hat = knn.predict(&x).unwrap();
assert_eq!(5, Vec::len(&y_hat));
Expand Down
2 changes: 1 addition & 1 deletion src/preprocessing/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ mod tests {
)]
#[test]
fn hash_encode_f64_series() {
let series = vec![3.0, 1.0, 2.0, 1.0];
let series = [3.0, 1.0, 2.0, 1.0];
let hashable_series: Vec<CategoricalFloat> =
series.iter().map(|v| v.to_category()).collect();
let enc = CategoryMapper::from_positional_category_vec(hashable_series);
Expand Down
2 changes: 1 addition & 1 deletion src/svm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct Kernels;
impl Kernels {
/// Return a default linear
pub fn linear() -> LinearKernel {
LinearKernel::default()
LinearKernel
}
/// Return a default RBF
pub fn rbf() -> RBFKernel {
Expand Down
4 changes: 2 additions & 2 deletions src/tree/decision_tree_regressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ mod tests {
assert!((y_hat[i] - y[i]).abs() < 0.1);
}

let expected_y = vec![
let expected_y = [
87.3, 87.3, 87.3, 87.3, 98.9, 98.9, 98.9, 98.9, 98.9, 107.9, 107.9, 107.9, 114.85,
114.85, 114.85, 114.85,
];
Expand All @@ -788,7 +788,7 @@ mod tests {
assert!((y_hat[i] - expected_y[i]).abs() < 0.1);
}

let expected_y = vec![
let expected_y = [
83.0, 88.35, 88.35, 89.5, 97.15, 97.15, 99.5, 99.5, 101.2, 104.6, 109.6, 109.6, 113.4,
113.4, 116.30, 116.30,
];
Expand Down

0 comments on commit d372300

Please sign in to comment.