diff --git a/src/lm/test_init_step.rs b/src/lm/test_init_step.rs index 43783db..b64f3c6 100644 --- a/src/lm/test_init_step.rs +++ b/src/lm/test_init_step.rs @@ -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() { @@ -20,8 +16,10 @@ fn nan_or_inf_none_residual() { assert!(err.objective_function.is_nan()); // residuals return inf - let problem = - MockProblem::::new(Vector2::zeros(), vec![Some(Vector3::new(1., 1., INFINITY))]); + let problem = MockProblem::::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, @@ -33,7 +31,7 @@ fn nan_or_inf_none_residual() { // residuals return nan let problem = - MockProblem::::new(Vector2::zeros(), vec![Some(Vector3::new(1., 1., NAN))]); + MockProblem::::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, @@ -56,8 +54,10 @@ fn already_zero() { assert_eq!(problem.calls(), [MockCall::Residuals].as_ref()); assert!(err.objective_function.is_zero()); - let problem = - MockProblem::::new(Vector1::new(10.), vec![Some(Vector1::new(MIN_POSITIVE))]); + let problem = MockProblem::::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); diff --git a/src/lm/test_update_diag.rs b/src/lm/test_update_diag.rs index e991d13..a088b49 100644 --- a/src/lm/test_update_diag.rs +++ b/src/lm/test_update_diag.rs @@ -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() { @@ -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") ); } @@ -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 ); } diff --git a/src/qr.rs b/src/qr.rs index 65b870d..9afc1b6 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -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., @@ -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.);