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

chore: update clippy lints #272

Merged
merged 2 commits into from
Nov 21, 2023
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
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
2 changes: 1 addition & 1 deletion src/dataset/diabetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
target: y,
num_samples,
num_features,
feature_names: vec![
feature_names: [
"Age", "Sex", "BMI", "BP", "S1", "S2", "S3", "S4", "S5", "S6",
]
.iter()
Expand Down
8 changes: 3 additions & 5 deletions src/dataset/digits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ pub fn load_dataset() -> Dataset<f32, f32> {
target: y,
num_samples,
num_features,
feature_names: vec![
"sepal length (cm)",
feature_names: ["sepal length (cm)",
"sepal width (cm)",
"petal length (cm)",
"petal width (cm)",
]
"petal width (cm)"]
.iter()
.map(|s| s.to_string())
.collect(),
target_names: vec!["setosa", "versicolor", "virginica"]
target_names: ["setosa", "versicolor", "virginica"]
.iter()
.map(|s| s.to_string())
.collect(),
Expand Down
4 changes: 2 additions & 2 deletions src/dataset/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
target: y,
num_samples,
num_features,
feature_names: vec![
feature_names: [
"sepal length (cm)",
"sepal width (cm)",
"petal length (cm)",
Expand All @@ -45,7 +45,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
.iter()
.map(|s| s.to_string())
.collect(),
target_names: vec!["setosa", "versicolor", "virginica"]
target_names: ["setosa", "versicolor", "virginica"]
.iter()
.map(|s| s.to_string())
.collect(),
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
Loading