add MatrixBase::stableNorm() avoiding over/under-flow

using it in QR reduced the error of Keir test from 1e-12 to 1e-24 but
that's much more expensive !
This commit is contained in:
Gael Guennebaud
2009-01-28 22:11:56 +00:00
parent 42b237b83a
commit 36c8a64923
6 changed files with 46 additions and 6 deletions

View File

@@ -103,6 +103,28 @@ struct ei_functor_traits<ei_scalar_max_op<Scalar> > {
};
};
/** \internal
* \brief Template functor to compute the hypot of two scalars
*
* \sa MatrixBase::stableNorm(), class Redux
*/
template<typename Scalar> struct ei_scalar_hypot_op EIGEN_EMPTY_STRUCT {
// typedef typename NumTraits<Scalar>::Real result_type;
EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& _x, const Scalar& _y) const
{
// typedef typename NumTraits<T>::Real RealScalar;
// RealScalar _x = ei_abs(x);
// RealScalar _y = ei_abs(y);
Scalar p = std::max(_x, _y);
Scalar q = std::min(_x, _y);
Scalar qp = q/p;
return p * ei_sqrt(Scalar(1) + qp*qp);
}
};
template<typename Scalar>
struct ei_functor_traits<ei_scalar_hypot_op<Scalar> > {
enum { Cost = 5 * NumTraits<Scalar>::MulCost };
};
// other binary functors: