Prevent BDCSVD crash caused by index out of bounds.

(cherry picked from commit 028ab12586ee1244755455107fcba66493b336d6)
This commit is contained in:
Antonio Sánchez 2022-05-19 22:29:48 +00:00 committed by Rasmus Munk Larsen
parent a1e1612c28
commit e7248b26a1

View File

@ -978,8 +978,8 @@ void BDCSVD<MatrixType>::computeSingVals(const ArrayRef& col0, const ArrayRef& d
// perturb singular value slightly if it equals diagonal entry to avoid division by zero later // perturb singular value slightly if it equals diagonal entry to avoid division by zero later
// (deflation is supposed to avoid this from happening) // (deflation is supposed to avoid this from happening)
// - this does no seem to be necessary anymore - // - this does no seem to be necessary anymore -
// if (singVals[k] == left) singVals[k] *= 1 + NumTraits<RealScalar>::epsilon(); // if (singVals[k] == left) singVals[k] *= 1 + NumTraits<RealScalar>::epsilon();
// if (singVals[k] == right) singVals[k] *= 1 - NumTraits<RealScalar>::epsilon(); // if (singVals[k] == right) singVals[k] *= 1 - NumTraits<RealScalar>::epsilon();
} }
} }
@ -1033,7 +1033,14 @@ void BDCSVD<MatrixType>::perturbCol0
std::cout << " " << "j=" << j << "\n"; std::cout << " " << "j=" << j << "\n";
} }
#endif #endif
Index j = i<k ? i : perm(l-1); // Avoid index out of bounds.
// Will end up setting zhat(k) = 0.
if (l == 0) {
m_info = NumericalIssue;
prod = 0;
break;
}
Index j = i<k ? i : l > 0 ? perm(l-1) : i;
#ifdef EIGEN_BDCSVD_SANITY_CHECKS #ifdef EIGEN_BDCSVD_SANITY_CHECKS
if(!(dk!=Literal(0) || diag(i)!=Literal(0))) if(!(dk!=Literal(0) || diag(i)!=Literal(0)))
{ {