Skip to content

Commit 6f22bbd

Browse files
authored
chore: update clippy lints (#272)
* chore: fix clippy lints --------- Co-authored-by: Luis Moreno <[email protected]>
1 parent dbdc2b2 commit 6f22bbd

File tree

13 files changed

+19
-28
lines changed

13 files changed

+19
-28
lines changed

src/cluster/dbscan.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>, D: Distance<Vec<TX>>>
315315
}
316316
}
317317

318-
while !neighbors.is_empty() {
319-
let neighbor = neighbors.pop().unwrap();
318+
while let Some(neighbor) = neighbors.pop() {
320319
let index = neighbor.0;
321320

322321
if y[index] == outlier {

src/dataset/diabetes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
4040
target: y,
4141
num_samples,
4242
num_features,
43-
feature_names: vec![
43+
feature_names: [
4444
"Age", "Sex", "BMI", "BP", "S1", "S2", "S3", "S4", "S5", "S6",
4545
]
4646
.iter()

src/dataset/digits.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ pub fn load_dataset() -> Dataset<f32, f32> {
2525
target: y,
2626
num_samples,
2727
num_features,
28-
feature_names: vec![
29-
"sepal length (cm)",
28+
feature_names: ["sepal length (cm)",
3029
"sepal width (cm)",
3130
"petal length (cm)",
32-
"petal width (cm)",
33-
]
31+
"petal width (cm)"]
3432
.iter()
3533
.map(|s| s.to_string())
3634
.collect(),
37-
target_names: vec!["setosa", "versicolor", "virginica"]
35+
target_names: ["setosa", "versicolor", "virginica"]
3836
.iter()
3937
.map(|s| s.to_string())
4038
.collect(),

src/dataset/iris.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
3636
target: y,
3737
num_samples,
3838
num_features,
39-
feature_names: vec![
39+
feature_names: [
4040
"sepal length (cm)",
4141
"sepal width (cm)",
4242
"petal length (cm)",
@@ -45,7 +45,7 @@ pub fn load_dataset() -> Dataset<f32, u32> {
4545
.iter()
4646
.map(|s| s.to_string())
4747
.collect(),
48-
target_names: vec!["setosa", "versicolor", "virginica"]
48+
target_names: ["setosa", "versicolor", "virginica"]
4949
.iter()
5050
.map(|s| s.to_string())
5151
.collect(),

src/linalg/basic/arrays.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
188188
_ => max,
189189
}
190190
};
191-
self.iterator(0)
192-
.fold(T::min_value(), |max, x| max_f(max, x))
191+
self.iterator(0).fold(T::min_value(), max_f)
193192
}
194193
/// return min value from the view
195194
fn min(&self) -> T
@@ -202,8 +201,7 @@ pub trait ArrayView1<T: Debug + Display + Copy + Sized>: Array<T, usize> {
202201
_ => min,
203202
}
204203
};
205-
self.iterator(0)
206-
.fold(T::max_value(), |max, x| min_f(max, x))
204+
self.iterator(0).fold(T::max_value(), min_f)
207205
}
208206
/// return the position of the max value of the view
209207
fn argmax(&self) -> usize

src/linalg/basic/matrix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ mod tests {
650650

651651
#[test]
652652
fn test_from_iterator() {
653-
let data = vec![1, 2, 3, 4, 5, 6];
653+
let data = [1, 2, 3, 4, 5, 6];
654654

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

src/linalg/basic/vector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ mod tests {
211211

212212
#[test]
213213
fn test_len() {
214-
let x = vec![1, 2, 3];
214+
let x = [1, 2, 3];
215215
assert_eq!(3, x.len());
216216
}
217217

src/linear/bg_solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod tests {
160160
fn bg_solver() {
161161
let a = DenseMatrix::from_2d_array(&[&[25., 15., -5.], &[15., 18., 0.], &[-5., 0., 11.]]);
162162
let b = vec![40., 51., 28.];
163-
let expected = vec![1.0, 2.0, 3.0];
163+
let expected = [1.0, 2.0, 3.0];
164164

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

src/linear/logistic_regression.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,7 @@ mod tests {
890890

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

893-
let error: i32 = y
894-
.into_iter()
895-
.zip(y_hat.into_iter())
896-
.map(|(a, b)| (a - b).abs())
897-
.sum();
893+
let error: i32 = y.into_iter().zip(y_hat).map(|(a, b)| (a - b).abs()).sum();
898894

899895
assert!(error <= 1);
900896

src/neighbors/knn_regressor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mod tests {
297297
let x =
298298
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
299299
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
300-
let y_exp = vec![1., 2., 3., 4., 5.];
300+
let y_exp = [1., 2., 3., 4., 5.];
301301
let knn = KNNRegressor::fit(
302302
&x,
303303
&y,
@@ -324,7 +324,7 @@ mod tests {
324324
let x =
325325
DenseMatrix::from_2d_array(&[&[1., 2.], &[3., 4.], &[5., 6.], &[7., 8.], &[9., 10.]]);
326326
let y: Vec<f64> = vec![1., 2., 3., 4., 5.];
327-
let y_exp = vec![2., 2., 3., 4., 4.];
327+
let y_exp = [2., 2., 3., 4., 4.];
328328
let knn = KNNRegressor::fit(&x, &y, Default::default()).unwrap();
329329
let y_hat = knn.predict(&x).unwrap();
330330
assert_eq!(5, Vec::len(&y_hat));

src/preprocessing/categorical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ mod tests {
277277
)]
278278
#[test]
279279
fn hash_encode_f64_series() {
280-
let series = vec![3.0, 1.0, 2.0, 1.0];
280+
let series = [3.0, 1.0, 2.0, 1.0];
281281
let hashable_series: Vec<CategoricalFloat> =
282282
series.iter().map(|v| v.to_category()).collect();
283283
let enc = CategoryMapper::from_positional_category_vec(hashable_series);

src/svm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Kernels;
5656
impl Kernels {
5757
/// Return a default linear
5858
pub fn linear() -> LinearKernel {
59-
LinearKernel::default()
59+
LinearKernel
6060
}
6161
/// Return a default RBF
6262
pub fn rbf() -> RBFKernel {

src/tree/decision_tree_regressor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ mod tests {
767767
assert!((y_hat[i] - y[i]).abs() < 0.1);
768768
}
769769

770-
let expected_y = vec![
770+
let expected_y = [
771771
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,
772772
114.85, 114.85, 114.85,
773773
];
@@ -788,7 +788,7 @@ mod tests {
788788
assert!((y_hat[i] - expected_y[i]).abs() < 0.1);
789789
}
790790

791-
let expected_y = vec![
791+
let expected_y = [
792792
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,
793793
113.4, 116.30, 116.30,
794794
];

0 commit comments

Comments
 (0)