Skip to content

Commit ba75f9f

Browse files
authored
chore: fix clippy (#283)
* chore: fix clippy Co-authored-by: Luis Moreno <[email protected]>
1 parent 239c004 commit ba75f9f

29 files changed

+194
-236
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install Rust toolchain
3737
uses: actions-rs/toolchain@v1
3838
with:
39-
toolchain: stable
39+
toolchain: 1.81 # 1.82 seems to break wasm32 tests https://github.com/rustwasm/wasm-bindgen/issues/4274
4040
target: ${{ matrix.platform.target }}
4141
profile: minimal
4242
default: true

src/algorithm/neighbour/cover_tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
124124
current_cover_set.push((d, &self.root));
125125

126126
let mut heap = HeapSelection::with_capacity(k);
127-
heap.add(std::f64::MAX);
127+
heap.add(f64::MAX);
128128

129129
let mut empty_heap = true;
130130
if !self.identical_excluded || self.get_data_value(self.root.idx) != p {
@@ -145,7 +145,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
145145
}
146146

147147
let upper_bound = if empty_heap {
148-
std::f64::INFINITY
148+
f64::INFINITY
149149
} else {
150150
*heap.peek()
151151
};
@@ -291,7 +291,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
291291
} else {
292292
let max_dist = self.max(point_set);
293293
let next_scale = (max_scale - 1).min(self.get_scale(max_dist));
294-
if next_scale == std::i64::MIN {
294+
if next_scale == i64::MIN {
295295
let mut children: Vec<Node> = Vec::new();
296296
let mut leaf = self.new_leaf(p);
297297
children.push(leaf);
@@ -435,7 +435,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
435435

436436
fn get_scale(&self, d: f64) -> i64 {
437437
if d == 0f64 {
438-
std::i64::MIN
438+
i64::MIN
439439
} else {
440440
(self.inv_log_base * d.ln()).ceil() as i64
441441
}

src/algorithm/neighbour/fastpair.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ pub struct FastPair<'a, T: RealNumber + FloatNumber, M: Array2<T>> {
5252
}
5353

5454
impl<'a, T: RealNumber + FloatNumber, M: Array2<T>> FastPair<'a, T, M> {
55-
///
5655
/// Constructor
57-
/// Instantiate and inizialise the algorithm
58-
///
56+
/// Instantiate and initialize the algorithm
5957
pub fn new(m: &'a M) -> Result<Self, Failed> {
6058
if m.shape().0 < 3 {
6159
return Err(Failed::because(
@@ -74,10 +72,8 @@ impl<'a, T: RealNumber + FloatNumber, M: Array2<T>> FastPair<'a, T, M> {
7472
Ok(init)
7573
}
7674

77-
///
7875
/// Initialise `FastPair` by passing a `Array2`.
7976
/// Build a FastPairs data-structure from a set of (new) points.
80-
///
8177
fn init(&mut self) {
8278
// basic measures
8379
let len = self.samples.shape().0;
@@ -158,9 +154,7 @@ impl<'a, T: RealNumber + FloatNumber, M: Array2<T>> FastPair<'a, T, M> {
158154
self.neighbours = neighbours;
159155
}
160156

161-
///
162157
/// Find closest pair by scanning list of nearest neighbors.
163-
///
164158
#[allow(dead_code)]
165159
pub fn closest_pair(&self) -> PairwiseDistance<T> {
166160
let mut a = self.neighbours[0]; // Start with first point
@@ -217,9 +211,7 @@ mod tests_fastpair {
217211
use super::*;
218212
use crate::linalg::basic::{arrays::Array, matrix::DenseMatrix};
219213

220-
///
221214
/// Brute force algorithm, used only for comparison and testing
222-
///
223215
pub fn closest_pair_brute(fastpair: &FastPair<f64, DenseMatrix<f64>>) -> PairwiseDistance<f64> {
224216
use itertools::Itertools;
225217
let m = fastpair.samples.shape().0;

src/algorithm/neighbour/linear_search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<T, D: Distance<T>> LinearKNNSearch<T, D> {
6161

6262
for _ in 0..k {
6363
heap.add(KNNPoint {
64-
distance: std::f64::INFINITY,
64+
distance: f64::INFINITY,
6565
index: None,
6666
});
6767
}
@@ -215,7 +215,7 @@ mod tests {
215215
};
216216

217217
let point_inf = KNNPoint {
218-
distance: std::f64::INFINITY,
218+
distance: f64::INFINITY,
219219
index: Some(3),
220220
};
221221

src/algorithm/sort/heap_select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mod tests {
133133
#[test]
134134
fn test_add1() {
135135
let mut heap = HeapSelection::with_capacity(3);
136-
heap.add(std::f64::INFINITY);
136+
heap.add(f64::INFINITY);
137137
heap.add(-5f64);
138138
heap.add(4f64);
139139
heap.add(-1f64);
@@ -151,7 +151,7 @@ mod tests {
151151
#[test]
152152
fn test_add2() {
153153
let mut heap = HeapSelection::with_capacity(3);
154-
heap.add(std::f64::INFINITY);
154+
heap.add(f64::INFINITY);
155155
heap.add(0.0);
156156
heap.add(8.4852);
157157
heap.add(5.6568);

src/algorithm/sort/quick_sort.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use num_traits::Num;
33
pub trait QuickArgSort {
44
fn quick_argsort_mut(&mut self) -> Vec<usize>;
55

6+
#[allow(dead_code)]
67
fn quick_argsort(&self) -> Vec<usize>;
78
}
89

src/cluster/kmeans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> PartialEq for KMeans<
9696
return false;
9797
}
9898
for j in 0..self.centroids[i].len() {
99-
if (self.centroids[i][j] - other.centroids[i][j]).abs() > std::f64::EPSILON {
99+
if (self.centroids[i][j] - other.centroids[i][j]).abs() > f64::EPSILON {
100100
return false;
101101
}
102102
}
@@ -270,7 +270,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>
270270

271271
let (n, d) = data.shape();
272272

273-
let mut distortion = std::f64::MAX;
273+
let mut distortion = f64::MAX;
274274
let mut y = KMeans::<TX, TY, X, Y>::kmeans_plus_plus(data, parameters.k, parameters.seed);
275275
let mut size = vec![0; parameters.k];
276276
let mut centroids = vec![vec![0f64; d]; parameters.k];
@@ -331,7 +331,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>
331331
let mut row = vec![0f64; x.shape().1];
332332

333333
for i in 0..n {
334-
let mut min_dist = std::f64::MAX;
334+
let mut min_dist = f64::MAX;
335335
let mut best_cluster = 0;
336336

337337
for j in 0..self.k {
@@ -361,7 +361,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>
361361
.cloned()
362362
.collect();
363363

364-
let mut d = vec![std::f64::MAX; n];
364+
let mut d = vec![f64::MAX; n];
365365
let mut row = vec![TX::zero(); data.shape().1];
366366

367367
for j in 1..k {

0 commit comments

Comments
 (0)