From 7ea9ecee081fc80f2c0c3a23f0985abddfdd5d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Br=C3=B6nneg=C3=A5rd?= <1162652+rasmusgo@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:20:44 +0100 Subject: [PATCH] Test for axes with zero magnitude --- src/linalg/bidiagonal.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index 3036e9f1..fd32e744 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -8,6 +8,7 @@ use simba::scalar::ComplexField; use crate::geometry::Reflection; use crate::linalg::householder; +use crate::num::Zero; use std::mem::MaybeUninit; /// The bidiagonalization of a general matrix. @@ -227,7 +228,10 @@ where for i in (0..dim - shift).rev() { let axis = self.uv.view_range(i + shift.., i); - // TODO: sometimes, the axis might have a zero magnitude. + // Sometimes, the axis might have a zero magnitude. + if axis.magnitude().is_zero() { + continue; + } let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.view_range_mut(i + shift.., i..); @@ -263,7 +267,10 @@ where let axis = self.uv.view_range(i, i + shift..); let mut axis_packed = axis_packed.rows_range_mut(i + shift..); axis_packed.tr_copy_from(&axis); - // TODO: sometimes, the axis might have a zero magnitude. + // Sometimes, the axis might have a zero magnitude. + if axis_packed.magnitude().is_zero() { + continue; + } let refl = Reflection::new(Unit::new_unchecked(axis_packed), T::zero()); let mut res_rows = res.view_range_mut(i.., i + shift..);