From 1acd48f6f1b684317e7cd893d973ba67ab4f7290 Mon Sep 17 00:00:00 2001 From: YuhanLiin Date: Wed, 9 Mar 2022 21:04:43 -0500 Subject: [PATCH] Address review comments --- src/linalg/svd.rs | 10 +++++++++- tests/linalg/svd.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index 42a6abb3..06bae4a3 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use std::any::TypeId; +use approx::AbsDiffEq; use num::{One, Zero}; use crate::allocator::Allocator; @@ -93,7 +94,14 @@ where /// The singular values are not guaranteed to be sorted in any particular order. /// If a descending order is required, consider using `new` instead. pub fn new_unordered(matrix: OMatrix, compute_u: bool, compute_v: bool) -> Self { - Self::try_new_unordered(matrix, compute_u, compute_v, crate::convert(1e-15), 0).unwrap() + Self::try_new_unordered( + matrix, + compute_u, + compute_v, + T::RealField::default_epsilon() * crate::convert(5.0), + 0, + ) + .unwrap() } /// Attempts to compute the Singular Value Decomposition of `matrix` using implicit shift. diff --git a/tests/linalg/svd.rs b/tests/linalg/svd.rs index 7eabe3d0..8e83df81 100644 --- a/tests/linalg/svd.rs +++ b/tests/linalg/svd.rs @@ -462,8 +462,8 @@ fn svd_sorted() { } #[test] -// Exercises bug reported in issue #983 of nalgebra -fn svd_consistent() { +// Exercises bug reported in issue #983 of nalgebra (https://github.com/dimforge/nalgebra/issues/983) +fn svd_regression_issue_983() { let m = nalgebra::dmatrix![ 10.74785316637712f64, -5.994983325167452, -6.064492921857296; -4.149751381521569, 20.654504205822462, -4.470436210703133; @@ -475,12 +475,12 @@ fn svd_consistent() { let svd3 = m.clone().svd(true, false); let svd4 = m.svd(false, false); - assert_relative_eq!(svd1.singular_values, svd2.singular_values, epsilon = 1e-5); - assert_relative_eq!(svd1.singular_values, svd3.singular_values, epsilon = 1e-5); - assert_relative_eq!(svd1.singular_values, svd4.singular_values, epsilon = 1e-5); + assert_relative_eq!(svd1.singular_values, svd2.singular_values, epsilon = 1e-9); + assert_relative_eq!(svd1.singular_values, svd3.singular_values, epsilon = 1e-9); + assert_relative_eq!(svd1.singular_values, svd4.singular_values, epsilon = 1e-9); assert_relative_eq!( svd1.singular_values, nalgebra::dvector![3.16188022e+01, 2.23811978e+01, 0.], - epsilon = 1e-5 + epsilon = 1e-6 ); }