Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-ant committed Jul 22, 2024
1 parent b6330ff commit 7d4d54b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
22 changes: 11 additions & 11 deletions src/lm/test_init_step.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use super::test_helpers::{MockCall, MockProblem};
use super::{LevenbergMarquardt, TerminationReason, LM};
use alloc::vec;
use approx::assert_relative_eq;
#[cfg(not(feature = "minpack-compat"))]
use core::f64::{INFINITY, MIN_POSITIVE, NAN};

use nalgebra::{Dim, Dyn, OMatrix, OVector, Vector2, Vector3, U0, U2, U3};

use super::test_helpers::{MockCall, MockProblem};
use super::{LevenbergMarquardt, TerminationReason, LM};

#[test]
#[cfg(not(feature = "minpack-compat"))]
fn nan_or_inf_none_residual() {
Expand All @@ -20,8 +16,10 @@ fn nan_or_inf_none_residual() {
assert!(err.objective_function.is_nan());

// residuals return inf
let problem =
MockProblem::<U2, U3>::new(Vector2::zeros(), vec![Some(Vector3::new(1., 1., INFINITY))]);
let problem = MockProblem::<U2, U3>::new(
Vector2::zeros(),
vec![Some(Vector3::new(1., 1., f64::INFINITY))],
);
let (mut problem, err) = LM::new(&LevenbergMarquardt::new(), problem).err().unwrap();
assert_eq!(
err.termination,
Expand All @@ -33,7 +31,7 @@ fn nan_or_inf_none_residual() {

// residuals return nan
let problem =
MockProblem::<U2, U3>::new(Vector2::zeros(), vec![Some(Vector3::new(1., 1., NAN))]);
MockProblem::<U2, U3>::new(Vector2::zeros(), vec![Some(Vector3::new(1., 1., f64::NAN))]);
let (mut problem, err) = LM::new(&LevenbergMarquardt::new(), problem).err().unwrap();
assert_eq!(
err.termination,
Expand All @@ -56,8 +54,10 @@ fn already_zero() {
assert_eq!(problem.calls(), [MockCall::Residuals].as_ref());
assert!(err.objective_function.is_zero());

let problem =
MockProblem::<U1, U1>::new(Vector1::new(10.), vec![Some(Vector1::new(MIN_POSITIVE))]);
let problem = MockProblem::<U1, U1>::new(
Vector1::new(10.),
vec![Some(Vector1::new(f64::MIN_POSITIVE))],
);
let (mut problem, err) = LM::new(&LevenbergMarquardt::new(), problem).err().unwrap();
assert_eq!(err.termination, TerminationReason::ResidualsZero);
assert_eq!(err.number_of_evaluations, 1);
Expand Down
21 changes: 10 additions & 11 deletions src/lm/test_update_diag.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use ::core::f64::{INFINITY, NAN};
use alloc::vec;

use approx::assert_relative_eq;
use nalgebra::*;

use super::test_helpers::{MockCall, MockProblem};

use super::{LevenbergMarquardt, TerminationReason, LM};
use crate::qr::PivotedQR;
use alloc::vec;
use approx::assert_relative_eq;
use nalgebra::*;

#[test]
fn gnorm_and_gtol() {
Expand Down Expand Up @@ -80,11 +76,11 @@ fn nan_inf_xnorm() {
if cfg!(not(feature = "minpack-compat")) {
let jacobian = Matrix3x2::new(1., 2., 4., -2., 0.5, 0.1);
assert_eq!(
setup(Vector2::new(INFINITY, 0.), jacobian.clone()),
setup(Vector2::new(f64::INFINITY, 0.), jacobian.clone()),
TerminationReason::Numerical("subproblem x")
);
assert_eq!(
setup(Vector2::new(NAN, 0.), jacobian.clone()),
setup(Vector2::new(f64::NAN, 0.), jacobian.clone()),
TerminationReason::Numerical("subproblem x")
);
}
Expand All @@ -96,11 +92,14 @@ fn nan_inf_xnorm() {
TerminationReason::Numerical("jacobian")
};
assert_eq!(
setup(x.clone(), Matrix3x2::new(INFINITY, 2., 4., -2., 0.5, 0.1)),
setup(
x.clone(),
Matrix3x2::new(f64::INFINITY, 2., 4., -2., 0.5, 0.1)
),
termination_reason
);
assert_eq!(
setup(x.clone(), Matrix3x2::new(NAN, 2., 4., -2., 0.5, 0.1)),
setup(x.clone(), Matrix3x2::new(f64::NAN, 2., 4., -2., 0.5, 0.1)),
termination_reason
);
}
Expand Down
14 changes: 12 additions & 2 deletions src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ fn test_cholesky_upper() {

#[test]
fn test_column_max_norm() {
use ::core::f64::NAN;
use nalgebra::*;
let a = Matrix4x3::from_column_slice(&[
14., -12., 20., -11., 19., 38., -4., -11., -14., 12., -20., 11.,
Expand All @@ -867,7 +866,18 @@ fn test_column_max_norm() {
assert_relative_eq!(max_at_b.unwrap(), 0.88499332, epsilon = 1e-8);

let a = Matrix4x3::from_column_slice(&[
NAN, -12., 20., -11., 19., 38., -4., -11., -14., 12., -20., 11.,
f64::NAN,
-12.,
20.,
-11.,
19.,
38.,
-4.,
-11.,
-14.,
12.,
-20.,
11.,
]);
let qr = PivotedQR::new(a);
let b = Vector4::new(1., 2., 3., 4.);
Expand Down

0 comments on commit 7d4d54b

Please sign in to comment.