Skip to content

Commit 9482b22

Browse files
committed
fix clippy issues
1 parent 8e8cb3e commit 9482b22

4 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/alm/alm_factory.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,20 @@ where
260260
f1_u_plus_y_over_c
261261
.iter_mut()
262262
.zip(y_lagrange_mult.iter())
263-
.for_each(|(ti, yi)| *ti = *ti + *yi / penalty_scale);
263+
.for_each(|(ti, yi)| *ti += *yi / penalty_scale);
264264
s.copy_from_slice(&f1_u_plus_y_over_c);
265265
set_c.project(&mut s);
266266
let dist_sq: T = matrix_operations::norm2_squared_diff(&f1_u_plus_y_over_c, &s);
267267
let scaling: T = half::<T>() * penalty_parameter;
268-
*cost = *cost + scaling * dist_sq;
268+
*cost += scaling * dist_sq;
269269
}
270270
if let Some(f2) = &self.mapping_f2 {
271271
let c = xi[0];
272272
let mut z = vec![T::zero(); self.n2];
273273
f2(u, &mut z)?;
274274
let norm_sq: T = matrix_operations::norm2_squared(&z);
275275
let scaling: T = half::<T>() * c;
276-
*cost = *cost + scaling * norm_sq;
276+
*cost += scaling * norm_sq;
277277
}
278278
Ok(())
279279
}
@@ -325,7 +325,7 @@ where
325325
f1_u_plus_y_over_c
326326
.iter_mut()
327327
.zip(y_lagrange_mult.iter())
328-
.for_each(|(ti, yi)| *ti = *ti + *yi / c_penalty_parameter);
328+
.for_each(|(ti, yi)| *ti += *yi / c_penalty_parameter);
329329
s_aux_var.copy_from_slice(&f1_u_plus_y_over_c); // s = t
330330
set_c.project(&mut s_aux_var); // s = Proj_C(F1(u) + y/c)
331331

@@ -340,7 +340,7 @@ where
340340
// grad += c*t
341341
grad.iter_mut()
342342
.zip(jac_prod.iter())
343-
.for_each(|(gradi, jac_prodi)| *gradi = *gradi + c_penalty_parameter * *jac_prodi);
343+
.for_each(|(gradi, jac_prodi)| *gradi += c_penalty_parameter * *jac_prodi);
344344
}
345345

346346
// Compute second part: JF2(u)'*F2(u)
@@ -354,7 +354,7 @@ where
354354

355355
// grad += c * jf2u_times_f2u_aux
356356
grad.iter_mut().zip(jf2u_times_f2u_aux.iter()).for_each(
357-
|(gradi, jf2u_times_f2u_aux_i)| *gradi = *gradi + c * *jf2u_times_f2u_aux_i,
357+
|(gradi, jf2u_times_f2u_aux_i)| *gradi += c * *jf2u_times_f2u_aux_i,
358358
);
359359
}
360360
Ok(())

src/alm/alm_optimizer.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,21 +1027,27 @@ mod tests {
10271027
FunctionCallResult,
10281028
};
10291029

1030+
type DummyParametricGradient = fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult;
1031+
type DummyParametricCost = fn(&[f64], &[f64], &mut f64) -> FunctionCallResult;
1032+
type DummyMapping = MappingType;
1033+
type DummyConstraint = Ball2<'static>;
1034+
type DummyAlmProblem = AlmProblem<
1035+
DummyMapping,
1036+
DummyMapping,
1037+
DummyParametricGradient,
1038+
DummyParametricCost,
1039+
DummyConstraint,
1040+
DummyConstraint,
1041+
DummyConstraint,
1042+
>;
1043+
10301044
fn make_dummy_alm_problem(
10311045
n1: usize,
10321046
n2: usize,
1033-
) -> AlmProblem<
1034-
impl Fn(&[f64], &mut [f64]) -> FunctionCallResult,
1035-
impl Fn(&[f64], &mut [f64]) -> FunctionCallResult,
1036-
impl Fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult,
1037-
impl Fn(&[f64], &[f64], &mut f64) -> FunctionCallResult,
1038-
impl Constraint,
1039-
impl Constraint,
1040-
impl Constraint,
1041-
> {
1047+
) -> DummyAlmProblem {
10421048
// Main problem data
1043-
let psi = void_parameteric_cost;
1044-
let d_psi = void_parameteric_gradient;
1049+
let psi: DummyParametricCost = void_parameteric_cost;
1050+
let d_psi: DummyParametricGradient = void_parameteric_gradient;
10451051
let bounds = Ball2::new(None, 10.0);
10461052
// ALM-type data
10471053
let f1: Option<MappingType> = if n1 == 0 {
@@ -1085,7 +1091,7 @@ mod tests {
10851091

10861092
// Test: with_initial_penalty
10871093
let alm_optimizer = alm_optimizer.with_initial_penalty(7.0);
1088-
assert!(!alm_optimizer.alm_cache.xi.is_none());
1094+
assert!(alm_optimizer.alm_cache.xi.is_some());
10891095
if let Some(xi) = &alm_optimizer.alm_cache.xi {
10901096
unit_test_utils::assert_nearly_equal(
10911097
7.0,

src/cholesky_factorizer.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,7 @@ mod tests {
241241
let _ = factorizer.factorize(&a);
242242
assert!(3 == factorizer.dimension(), "wrong dimension");
243243
let expected_l = [2.0, 0.0, 0.0, 6.0, 1.0, 0.0, -8.0, 5.0, 3.0];
244-
unit_test_utils::nearly_equal_array(
245-
&expected_l,
246-
&factorizer.cholesky_factor(),
247-
1e-10,
248-
1e-12,
249-
);
244+
unit_test_utils::nearly_equal_array(&expected_l, factorizer.cholesky_factor(), 1e-10, 1e-12);
250245
}
251246

252247
#[test]

src/constraints/tests.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ fn t_finite_set_project_wrong_dimension() {
177177

178178
#[test]
179179
fn t_rectangle_bounded() {
180-
let xmin = vec![2.0; 5];
181-
let xmax = vec![4.5; 5];
180+
let xmin = [2.0; 5];
181+
let xmax = [4.5; 5];
182182
let rectangle = Rectangle::new(Some(&xmin[..]), Some(&xmax[..]));
183183
let mut x = [1.0, 2.0, 3.0, 4.0, 5.0];
184184

@@ -195,8 +195,8 @@ fn t_rectangle_bounded() {
195195

196196
#[test]
197197
fn t_rectangle_bounded_f32() {
198-
let xmin = vec![2.0_f32; 3];
199-
let xmax = vec![4.5_f32; 3];
198+
let xmin = [2.0_f32; 3];
199+
let xmax = [4.5_f32; 3];
200200
let rectangle = Rectangle::new(Some(&xmin[..]), Some(&xmax[..]));
201201
let mut x = [1.0_f32, 3.0, 5.0];
202202

@@ -226,8 +226,8 @@ fn t_rectangle_infinite_bounds() {
226226
#[test]
227227
#[should_panic]
228228
fn t_rectangle_incompatible_dims() {
229-
let xmin = vec![1.0; 5];
230-
let xmax = vec![2.0; 4];
229+
let xmin = [1.0; 5];
230+
let xmax = [2.0; 4];
231231
let _rectangle = Rectangle::new(Some(&xmin[..]), Some(&xmax[..]));
232232
}
233233

@@ -259,7 +259,7 @@ fn t_rectangle_bounded_negative_entries() {
259259

260260
#[test]
261261
fn t_rectangle_only_xmin() {
262-
let xmin = vec![2.0; 5];
262+
let xmin = [2.0; 5];
263263
let rectangle = Rectangle::new(Some(&xmin[..]), None);
264264
let mut x = [1.0, 2.0, 3.0, 4.0, 5.0];
265265

@@ -276,7 +276,7 @@ fn t_rectangle_only_xmin() {
276276

277277
#[test]
278278
fn t_rectangle_only_xmax() {
279-
let xmax = vec![-3.0; 5];
279+
let xmax = [-3.0; 5];
280280
let rectangle = Rectangle::new(None, Some(&xmax[..]));
281281
let mut x = [-10.0, -20.0, 0.0, 5.0, 3.0];
282282

@@ -1059,7 +1059,7 @@ fn t_ball1_alpha_negative() {
10591059
fn t_epigraph_squared_norm_inside() {
10601060
let epi = EpigraphSquaredNorm::new();
10611061
let mut x = [1., 2., 10.];
1062-
let x_correct = x.clone();
1062+
let x_correct = x;
10631063
epi.project(&mut x);
10641064
unit_test_utils::assert_nearly_equal_array(
10651065
&x_correct,
@@ -1088,7 +1088,7 @@ fn t_epigraph_squared_norm_correctness() {
10881088
let mut x = [1., 2., 3., 4.];
10891089
let x_correct = [
10901090
0.560142228903570,
1091-
1.120284457807140,
1091+
1.120_284_457_807_14,
10921092
1.680426686710711,
10931093
4.392630432414829,
10941094
];
@@ -1123,7 +1123,7 @@ fn t_affine_space() {
11231123
let x_correct = [
11241124
1.888564346697095,
11251125
5.629857182200888,
1126-
1.796204902230790,
1126+
1.796_204_902_230_79,
11271127
2.888362906715977,
11281128
];
11291129
unit_test_utils::assert_nearly_equal_array(
@@ -1334,7 +1334,7 @@ fn is_norm_p_projection(
13341334
fn t_ballp_at_origin_projection() {
13351335
let radius = 0.8;
13361336
let mut x = [1.0, -1.0, 6.0];
1337-
let x0 = x.clone();
1337+
let x0 = x;
13381338
let p = 3.;
13391339
let tol = 1e-16;
13401340
let max_iters: usize = 200;
@@ -1347,7 +1347,7 @@ fn t_ballp_at_origin_projection() {
13471347
fn t_ballp_at_origin_x_already_inside() {
13481348
let radius = 1.5;
13491349
let mut x = [0.5, -0.2, 0.1];
1350-
let x0 = x.clone();
1350+
let x0 = x;
13511351
let p = 3.;
13521352
let tol = 1e-16;
13531353
let max_iters: usize = 1200;

0 commit comments

Comments
 (0)