diff options
author | 2009-01-28 22:11:56 +0000 | |
---|---|---|
committer | 2009-01-28 22:11:56 +0000 | |
commit | 36c8a649238221cc370268b6d877e89caed8805f (patch) | |
tree | 5af31a0301460e954ff867737899ac4d60c27196 /Eigen/src/Core/Functors.h | |
parent | 42b237b83a16739c586f139db2e6da928b717b84 (diff) |
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 !
Diffstat (limited to 'Eigen/src/Core/Functors.h')
-rw-r--r-- | Eigen/src/Core/Functors.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index c8ca3dac1..8b9516ae6 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -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: |