From ac1a5856cfd8e1da1fd31d742734e8659d159a5a Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 4 May 2026 19:59:00 -0600 Subject: [PATCH] chore: fix clippy warnings in NSGA-III, SPEA2, and compare example - nsga3: drop redundant `.into_iter()` in extend call; use `#[allow(clippy::needless_range_loop)]` on the back-substitution loop where `j` indexes into the matrix; remove an unneeded `return` keyword in a closure. - spea2: switch `pool.extend(x.drain(..))` to `pool.append(&mut x)`. - examples/compare.rs DTLZ2 evaluator: same `needless_range_loop` silencer on the inner cosine product loop. --- examples/compare.rs | 1 + src/algorithms/nsga3.rs | 6 ++++-- src/algorithms/spea2.rs | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/compare.rs b/examples/compare.rs index f735138..cfe9001 100644 --- a/examples/compare.rs +++ b/examples/compare.rs @@ -79,6 +79,7 @@ impl Problem for Dtlz2 { let mut f = vec![0.0_f64; m]; for i in 0..m { let mut prod = scale; + #[allow(clippy::needless_range_loop)] // Body indexes `x[j]`. for j in 0..(m - i - 1) { prod *= (x[j] * std::f64::consts::FRAC_PI_2).cos(); } diff --git a/src/algorithms/nsga3.rs b/src/algorithms/nsga3.rs index 3c66bc3..04f7695 100644 --- a/src/algorithms/nsga3.rs +++ b/src/algorithms/nsga3.rs @@ -119,7 +119,7 @@ where // --- Combine + survival selection --- let mut combined: Vec> = Vec::with_capacity(2 * n); - combined.extend(population.into_iter()); + combined.extend(population); combined.extend(offspring); population = environmental_selection(&combined, &objectives, &reference_points, n, &mut rng); } @@ -325,6 +325,7 @@ fn solve_intercepts(oriented: &[Vec], extremes: &[usize]) -> Option> = extremes.iter().map(|&i| oriented[i].clone()).collect(); let mut b: Vec = vec![1.0; m]; // Forward elimination with partial pivoting. + #[allow(clippy::needless_range_loop)] // Body indexes both `a` and `b` by row. for k in 0..m { let mut pivot = k; for i in (k + 1)..m { @@ -339,6 +340,7 @@ fn solve_intercepts(oriented: &[Vec], extremes: &[usize]) -> Option], extremes: &[usize]) -> Option = x .into_iter() - .map(|v| if v.abs() < 1e-12 { return f64::NAN } else { 1.0 / v }) + .map(|v| if v.abs() < 1e-12 { f64::NAN } else { 1.0 / v }) .collect(); if intercepts.iter().any(|v| !v.is_finite() || *v <= 0.0) { return None; diff --git a/src/algorithms/spea2.rs b/src/algorithms/spea2.rs index c4bcdf1..88c451e 100644 --- a/src/algorithms/spea2.rs +++ b/src/algorithms/spea2.rs @@ -87,8 +87,8 @@ where // --- Combine pool, compute fitness --- let mut pool: Vec> = Vec::with_capacity(population.len() + archive.len()); - pool.extend(population.drain(..)); - pool.extend(archive.drain(..)); + pool.append(&mut population); + pool.append(&mut archive); let fitness = compute_fitness(&pool, &objectives); // --- Build the next archive ---