From 22ae236d4ea404122ff68966f1572a236f239335 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 14 Aug 2009 15:12:32 -0400 Subject: machine_epsilon -> epsilon as wrapper around numeric_traits --- Eigen/src/Cholesky/LDLT.h | 2 +- Eigen/src/Core/MathFunctions.h | 15 +++++++-------- Eigen/src/LU/LU.h | 2 +- Eigen/src/SVD/JacobiSquareSVD.h | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index e652fd213..1cb1294ac 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -180,7 +180,7 @@ void LDLT::compute(const MatrixType& a) // in "Analysis of the Cholesky Decomposition of a Semi-definite Matrix" by // Nicholas J. Higham. Also see "Accuracy and Stability of Numerical // Algorithms" page 217, also by Higham. - cutoff = ei_abs(machine_epsilon() * size * biggest_in_corner); + cutoff = ei_abs(epsilon() * size * biggest_in_corner); m_sign = ei_real(m_matrix.diagonal().coeff(index_of_biggest_in_corner)) > 0 ? 1 : -1; } diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index d68c483b2..16091caf0 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2006-2009 Benoit Jacob // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -25,8 +25,13 @@ #ifndef EIGEN_MATHFUNCTIONS_H #define EIGEN_MATHFUNCTIONS_H +template typename NumTraits::Real epsilon() +{ + return std::numeric_limits::Real>::epsilon(); +} + template inline typename NumTraits::Real precision(); -template inline typename NumTraits::Real machine_epsilon(); + template inline T ei_random(T a, T b); template inline T ei_random(); template inline T ei_random_amplitude() @@ -51,7 +56,6 @@ template inline typename NumTraits::Real ei_hypot(T x, T y) **************/ template<> inline int precision() { return 0; } -template<> inline int machine_epsilon() { return 0; } inline int ei_real(int x) { return x; } inline int& ei_real_ref(int& x) { return x; } inline int ei_imag(int) { return 0; } @@ -106,7 +110,6 @@ inline bool ei_isApproxOrLessThan(int a, int b, int = precision()) **************/ template<> inline float precision() { return 1e-5f; } -template<> inline float machine_epsilon() { return 1.192e-07f; } inline float ei_real(float x) { return x; } inline float& ei_real_ref(float& x) { return x; } inline float ei_imag(float) { return 0.f; } @@ -154,7 +157,6 @@ inline bool ei_isApproxOrLessThan(float a, float b, float prec = precision inline double precision() { return 1e-12; } -template<> inline double machine_epsilon() { return 2.220e-16; } inline double ei_real(double x) { return x; } inline double& ei_real_ref(double& x) { return x; } @@ -203,7 +205,6 @@ inline bool ei_isApproxOrLessThan(double a, double b, double prec = precision inline float precision >() { return precision(); } -template<> inline float machine_epsilon >() { return machine_epsilon(); } inline float ei_real(const std::complex& x) { return std::real(x); } inline float ei_imag(const std::complex& x) { return std::imag(x); } inline float& ei_real_ref(std::complex& x) { return reinterpret_cast(&x)[0]; } @@ -240,7 +241,6 @@ inline bool ei_isApprox(const std::complex& a, const std::complex& **********************/ template<> inline double precision >() { return precision(); } -template<> inline double machine_epsilon >() { return machine_epsilon(); } inline double ei_real(const std::complex& x) { return std::real(x); } inline double ei_imag(const std::complex& x) { return std::imag(x); } inline double& ei_real_ref(std::complex& x) { return reinterpret_cast(&x)[0]; } @@ -278,7 +278,6 @@ inline bool ei_isApprox(const std::complex& a, const std::complex inline long double precision() { return precision(); } -template<> inline long double machine_epsilon() { return 1.084e-19l; } inline long double ei_real(long double x) { return x; } inline long double& ei_real_ref(long double& x) { return x; } inline long double ei_imag(long double) { return 0.; } diff --git a/Eigen/src/LU/LU.h b/Eigen/src/LU/LU.h index f36951fda..733fa0cbc 100644 --- a/Eigen/src/LU/LU.h +++ b/Eigen/src/LU/LU.h @@ -390,7 +390,7 @@ void LU::compute(const MatrixType& matrix) // this formula comes from experimenting (see "LU precision tuning" thread on the list) // and turns out to be identical to Higham's formula used already in LDLt. - m_precision = machine_epsilon() * size; + m_precision = epsilon() * size; IntColVectorType rows_transpositions(matrix.rows()); IntRowVectorType cols_transpositions(matrix.cols()); diff --git a/Eigen/src/SVD/JacobiSquareSVD.h b/Eigen/src/SVD/JacobiSquareSVD.h index 82133f7be..32adb1301 100644 --- a/Eigen/src/SVD/JacobiSquareSVD.h +++ b/Eigen/src/SVD/JacobiSquareSVD.h @@ -102,7 +102,7 @@ void JacobiSquareSVD::compute(const MatrixType& if(ComputeU) m_matrixU = MatrixUType::Identity(size,size); if(ComputeV) m_matrixV = MatrixUType::Identity(size,size); m_singularValues.resize(size); - const RealScalar precision = 2 * machine_epsilon(); + const RealScalar precision = 2 * epsilon(); sweep_again: for(int p = 1; p < size; ++p) -- cgit v1.2.3