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

@ -1033,7 +1033,14 @@ void BDCSVD<MatrixType>::perturbCol0
std::cout << " " << "j=" << j << "\n";
}
#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
if(!(dk!=Literal(0) || diag(i)!=Literal(0)))
{