Skip to content

Commit 0d8a9d8

Browse files
fix-clippy (#319)
* Fix clippy Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> * Remove unused `hilbert` field for `k_means` Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> * Fix warnings Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> * Remaining clippy suggestions Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> * Update src/algorithms/k_means.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Applying @imrn99 suggestion Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> --------- Signed-off-by: Cedric Chevalier <cedric.chevalier@cea.fr> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6813840 commit 0d8a9d8

16 files changed

Lines changed: 33 additions & 40 deletions

File tree

benches/rcb_cartesian.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::Criterion;
2-
use criterion::black_box;
32
use criterion::criterion_group;
43
use criterion::criterion_main;
4+
use std::hint::black_box;
55
use std::num::NonZeroUsize;
66

77
pub fn bench(c: &mut Criterion) {
@@ -37,7 +37,7 @@ pub fn bench(c: &mut Criterion) {
3737
})
3838
.build()
3939
.unwrap();
40-
group.bench_function(&thread_count.to_string(), |b| {
40+
group.bench_function(thread_count.to_string(), |b| {
4141
pool.install(|| {
4242
b.iter(|| grid.rcb(black_box(&mut partition), black_box(&weights), 12))
4343
});

ffi/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Constant {
5151
T: 'a + Copy + Send + Sync,
5252
{
5353
let value = *(self.value as *const T);
54-
coupe::rayon::iter::repeatn(value, self.len)
54+
coupe::rayon::iter::repeat_n(value, self.len)
5555
}
5656
}
5757

src/algorithms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where
105105

106106
fn partition(&mut self, part_ids: &mut [usize], _: ()) -> Result<Self::Metadata, Self::Error> {
107107
for part_id in part_ids {
108-
*part_id = self.rng.gen_range(0..self.part_count);
108+
*part_id = self.rng.random_range(0..self.part_count);
109109
}
110110
Ok(())
111111
}

src/algorithms/hilbert_curve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn encode_2d(x: u64, y: u64, order: usize) -> u64 {
331331
order,
332332
);
333333

334-
const LUT: [u16; 16_384] = {
334+
static LUT: [u16; 16_384] = {
335335
let mut lut = [0; 16_384];
336336
let mut i: usize = 0;
337337
while i < 16_384 {

src/algorithms/k_means.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ fn imbalance(weights: &[f64]) -> f64 {
4646
/// - `delta_threshold`: the distance threshold for the cluster movements under which the algorithm stops.
4747
/// - `max_iter`: the maximum number of times each cluster will move before stopping the algorithm
4848
/// - `max_balance_iter`: the maximum number of iterations of the load balancing loop. It will limit how much each cluster
49-
/// influence can grow between each cluster movement.
49+
/// influence can grow between each cluster movement.
5050
/// - `erode`: sets whether or not cluster influence is modified according to errosion's rules between each cluster movement
51-
/// - `hilbert`: sets wheter or not an Hilbert curve is used to create the initial partition. If false, a Z curve is used instead.
5251
/// - `mbr_early_break`: sets whether or not bounding box optimization is enabled.
5352
#[derive(Debug, Clone, Copy)]
5453
pub struct BalancedKmeansSettings {
@@ -58,7 +57,6 @@ pub struct BalancedKmeansSettings {
5857
pub max_iter: usize,
5958
pub max_balance_iter: usize,
6059
pub erode: bool,
61-
pub hilbert: bool,
6260
pub mbr_early_break: bool,
6361
}
6462

@@ -71,7 +69,6 @@ impl Default for BalancedKmeansSettings {
7169
max_iter: 50,
7270
max_balance_iter: 1, // for now, `max_balance_iter > 1` yields poor convergence time
7371
erode: false, // for now, `erode` yields` enabled yields wrong results
74-
hilbert: true,
7572
mbr_early_break: false, // for now, `mbr_early_break` enabled yields wrong results
7673
}
7774
}
@@ -129,7 +126,7 @@ fn balanced_k_means_with_initial_partition<const D: usize>(
129126
// Generate initial lower and upper bounds. These two variables represent bounds on
130127
// the effective distance between an point and the cluster it is assigned to.
131128
let mut lbs: Vec<_> = points.par_iter().map(|_| 0.).collect();
132-
let mut ubs: Vec<_> = points.par_iter().map(|_| std::f64::MAX).collect(); // we use f64::MAX to represent infinity
129+
let mut ubs: Vec<_> = points.par_iter().map(|_| f64::MAX).collect(); // we use f64::MAX to represent infinity
133130

134131
balanced_k_means_iter(
135132
Inputs { points, weights },
@@ -480,8 +477,8 @@ fn best_values<const D: usize>(
480477
f64, // new ub
481478
Option<ClusterId>, // new cluster assignment for the current point (None if the same assignment is kept)
482479
) {
483-
let mut best_value = std::f64::MAX;
484-
let mut snd_best_value = std::f64::MAX;
480+
let mut best_value = f64::MAX;
481+
let mut snd_best_value = f64::MAX;
485482
let mut assignment = None;
486483

487484
for (((center, id), distance_to_mbr), influence) in centers
@@ -621,7 +618,6 @@ where
621618
max_iter: self.max_iter,
622619
max_balance_iter: self.max_balance_iter,
623620
erode: self.erode,
624-
hilbert: self.hilbert,
625621
mbr_early_break: self.mbr_early_break,
626622
};
627623
balanced_k_means_with_initial_partition(points, weights, settings, part_ids);

src/algorithms/kernighan_lin.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ fn kernighan_lin_2_impl<T>(
5959
let mut new_cut_size = cut_size;
6060

6161
for iter in 0.. {
62-
if let Some(max_passes) = max_passes {
63-
if iter >= max_passes {
64-
break;
65-
}
62+
if max_passes.is_some_and(|max| iter >= max) {
63+
break;
6664
}
6765

6866
cut_size = new_cut_size;
@@ -78,8 +76,7 @@ fn kernighan_lin_2_impl<T>(
7876
let mut locks = vec![false; initial_partition.len()];
7977

8078
// pass loop
81-
for _ in 0..(initial_partition.len() / 2).min(max_flips_per_pass.unwrap_or(std::usize::MAX))
82-
{
79+
for _ in 0..(initial_partition.len() / 2).min(max_flips_per_pass.unwrap_or(usize::MAX)) {
8380
// construct gains
8481
for (idx, gain) in gains.iter_mut().enumerate() {
8582
for (j, w) in adjacency.neighbors(idx) {

src/algorithms/multi_jagged.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn is_prime(n: u32) -> bool {
2525
let p: u32 = (f64::from(n)).sqrt() as u32;
2626

2727
for i in 2..=p {
28-
if n % i == 0 {
28+
if n.is_multiple_of(i) {
2929
return false;
3030
}
3131
}
@@ -43,7 +43,7 @@ fn prime_factors(mut n: u32) -> Vec<u32> {
4343
let mut primes = (2..).filter(|n| is_prime(*n));
4444
let mut current = primes.next().unwrap();
4545
while n > 1 {
46-
while n % current == 0 {
46+
while n.is_multiple_of(current) {
4747
ret.push(current);
4848
n /= current;
4949
}
@@ -239,7 +239,7 @@ pub(crate) fn compute_split_positions(
239239
let mut scan = permutation
240240
.par_iter()
241241
.enumerate()
242-
.fold_with((std::usize::MAX, 0.), |(low, acc), (idx, val)| {
242+
.fold_with((usize::MAX, 0.), |(low, acc), (idx, val)| {
243243
(usize::min(idx, low), acc + weights[*val])
244244
})
245245
.collect::<Vec<_>>()

src/algorithms/recursive_bisection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T
3535
// * `MaybeUninit` does not drop, so there are no double-frees
3636
// And thus the conversion is safe
3737
//std::intrinsics::assert_inhabited::<[T; N]>();
38-
(&array as *const _ as *const [T; N]).read()
38+
unsafe { (&array as *const _ as *const [T; N]).read() }
3939
}
4040

4141
fn array_init<F, T, const N: usize>(mut f: F) -> [T; N]

src/algorithms/z_curve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::sync::atomic::{self, AtomicPtr};
3636
// in 2D, an order greater than 64 will overflow u128.
3737
// maybe it would be more appropriate to use a BigInt
3838
type HashType = u128;
39-
const HASH_TYPE_MAX: HashType = std::u128::MAX;
39+
const HASH_TYPE_MAX: HashType = u128::MAX;
4040

4141
fn z_curve_partition<const D: usize>(
4242
partition: &mut [usize],

src/cartesian/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<const D: usize> Grid<D> {
7878
_ => {
7979
for (s, p) in self.size.into_iter().zip(&mut pos) {
8080
*p = i % s;
81-
i = i / s;
81+
i /= s;
8282
}
8383
}
8484
}
@@ -244,7 +244,7 @@ where
244244

245245
let mut neighbor = self.vertex;
246246
let axis = i / 2;
247-
let new_coord = if (i % 2) == 0 {
247+
let new_coord = if i.is_multiple_of(2) {
248248
usize::checked_sub(neighbor[axis], 1)
249249
} else {
250250
Some(neighbor[axis] + 1)

0 commit comments

Comments
 (0)