diff options
author | 2014-09-02 14:49:23 +0200 | |
---|---|---|
committer | 2014-09-02 14:49:23 +0200 | |
commit | 18fbe7e7d4cdb737ef5775bbb32fe62b6f8ef70e (patch) | |
tree | 102f60e51633c94db94af71a2c734f06880c8f76 /Eigen/src | |
parent | 3eb5253ca1352391f4ea31c4a2dd06c34c4a33e7 (diff) |
Fix stableNorm() with respect to NaN and inf, and add respective unit tests. blueNorm() and hypotNorm() are broken wrt to NaN/inf
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Core/StableNorm.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Eigen/src/Core/StableNorm.h b/Eigen/src/Core/StableNorm.h index 525620bad..07a021505 100644 --- a/Eigen/src/Core/StableNorm.h +++ b/Eigen/src/Core/StableNorm.h @@ -20,7 +20,7 @@ inline void stable_norm_kernel(const ExpressionType& bl, Scalar& ssq, Scalar& sc using std::max; Scalar maxCoeff = bl.cwiseAbs().maxCoeff(); - if (maxCoeff>scale) + if(maxCoeff>scale) { ssq = ssq * numext::abs2(scale/maxCoeff); Scalar tmp = Scalar(1)/maxCoeff; @@ -29,12 +29,21 @@ inline void stable_norm_kernel(const ExpressionType& bl, Scalar& ssq, Scalar& sc invScale = NumTraits<Scalar>::highest(); scale = Scalar(1)/invScale; } + else if(maxCoeff>NumTraits<Scalar>::highest()) // we got a INF + { + invScale = Scalar(1); + scale = maxCoeff; + } else { scale = maxCoeff; invScale = tmp; } } + else if(maxCoeff!=maxCoeff) // we got a NaN + { + scale = maxCoeff; + } // TODO if the maxCoeff is much much smaller than the current scale, // then we can neglect this sub vector |