From 68117c267c45faa7540e73d733eacc947dd3a8af Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 1 Dec 2009 13:51:35 -0500 Subject: [PATCH] ColPivQR: now the unit tests even succeeds: * with random matrices multiplied by 1e+8 (i.e. fixed wrong absolute fuzzy compare) * with 10,000 repetitions (i.e. the fuzzy compare is really clever) and when it occasionnally fails, less than once in 10,000 repeats, it is only on the exact rank computation. --- Eigen/src/QR/ColPivHouseholderQR.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index 1865417d4..b6135ac0b 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -350,6 +350,8 @@ ColPivHouseholderQR& ColPivHouseholderQR::compute(const for(int k = 0; k < cols; ++k) colSqNorms.coeffRef(k) = m_qr.col(k).squaredNorm(); + RealScalar threshold_helper = colSqNorms.maxCoeff() * ei_abs2(epsilon()) / rows; + m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) m_maxpivot = RealScalar(0); @@ -369,11 +371,12 @@ ColPivHouseholderQR& ColPivHouseholderQR::compute(const // we store that back into our table: it can't hurt to correct our table. colSqNorms.coeffRef(biggest_col_index) = biggest_col_sq_norm; - // if the pivot is smaller than epsilon, terminate to avoid generating nan/inf values. + // if the current biggest column is smaller than epsilon times the initial biggest column, + // terminate to avoid generating nan/inf values. // Note that here, if we test instead for "biggest == 0", we get a failure every 1000 (or so) // repetitions of the unit test, with the result of solve() filled with large values of the order - // of 1/epsilon. - if(biggest_col_sq_norm < ei_abs2(epsilon())) + // of 1/(size*epsilon). + if(biggest_col_sq_norm < threshold_helper * (rows-k)) { m_nonzero_pivots = k; m_hCoeffs.end(size-k).setZero();