From 96f08213f7a837908caafe197cb8a3e2eb277622 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 19 Jan 2011 11:01:07 -0500 Subject: [PATCH] big eigen2support fix, aimed at users who relied on internal eigen2 stuff: now we dont need customizations in test/eigen2/main.h anymore. These tests already build: eigen2_basicstuff eigen2_adjoint eigen2_linearstructure eigen2_prec_inverse_4x4 --- Eigen/Eigen2Support | 2 + Eigen/src/Core/MathFunctions.h | 4 ++ Eigen/src/Core/NumTraits.h | 6 ++ Eigen/src/Eigen2Support/Macros.h | 38 +++++++++++ Eigen/src/Eigen2Support/MathFunctions.h | 27 +++++++- Eigen/src/Eigen2Support/Meta.h | 39 +++++++++++ test/eigen2/CMakeLists.txt | 1 + test/eigen2/main.h | 89 +++++++++++++------------ test/eigen2/prec_inverse_4x4.cpp | 2 +- 9 files changed, 161 insertions(+), 47 deletions(-) create mode 100644 Eigen/src/Eigen2Support/Macros.h create mode 100644 Eigen/src/Eigen2Support/Meta.h diff --git a/Eigen/Eigen2Support b/Eigen/Eigen2Support index 7307903a4..37c2f163d 100644 --- a/Eigen/Eigen2Support +++ b/Eigen/Eigen2Support @@ -43,6 +43,8 @@ namespace Eigen { * */ +#include "src/Eigen2Support/Macros.h" +#include "src/Eigen2Support/Meta.h" #include "src/Eigen2Support/Lazy.h" #include "src/Eigen2Support/Cwise.h" #include "src/Eigen2Support/CwiseOperators.h" diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 1f7643d64..8e7def187 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -429,7 +429,11 @@ struct sqrt_default_impl { static inline Scalar run(const Scalar&) { +#ifdef EIGEN2_SUPPORT + eigen_assert(!NumTraits::IsInteger); +#else EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) +#endif return Scalar(0); } }; diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h index edc2ad2c4..7f7af9af2 100644 --- a/Eigen/src/Core/NumTraits.h +++ b/Eigen/src/Core/NumTraits.h @@ -69,6 +69,12 @@ template struct GenericNumTraits AddCost = 1, MulCost = 1 }; + +#ifdef EIGEN2_SUPPORT + enum { + HasFloatingPoint = !IsInteger + }; +#endif typedef T Real; typedef typename internal::conditional< diff --git a/Eigen/src/Eigen2Support/Macros.h b/Eigen/src/Eigen2Support/Macros.h new file mode 100644 index 000000000..0f812a3dc --- /dev/null +++ b/Eigen/src/Eigen2Support/Macros.h @@ -0,0 +1,38 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Benoit Jacob +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN2_MACROS_H +#define EIGEN2_MACROS_H + +#ifndef ei_assert + #define ei_assert eigen_assert +#endif + +#ifndef ei_internal_assert + #define ei_internal_assert eigen_internal_assert +#endif + +#define EIGEN_ALIGN_128 EIGEN_ALIGN16 + +#endif // EIGEN2_MACROS_H diff --git a/Eigen/src/Eigen2Support/MathFunctions.h b/Eigen/src/Eigen2Support/MathFunctions.h index 144a11d60..fdcfc01bb 100644 --- a/Eigen/src/Eigen2Support/MathFunctions.h +++ b/Eigen/src/Eigen2Support/MathFunctions.h @@ -28,8 +28,8 @@ template inline typename NumTraits::Real ei_real(const T& x) { return internal::real(x); } template inline typename NumTraits::Real ei_imag(const T& x) { return internal::imag(x); } template inline T ei_conj(const T& x) { return internal::conj(x); } -template inline T ei_abs (const T& x) { return internal::abs(x); } -template inline T ei_abs2(const T& x) { return internal::abs2(x); } +template inline typename NumTraits::Real ei_abs (const T& x) { return internal::abs(x); } +template inline typename NumTraits::Real ei_abs2(const T& x) { return internal::abs2(x); } template inline T ei_sqrt(const T& x) { return internal::sqrt(x); } template inline T ei_exp (const T& x) { return internal::exp(x); } template inline T ei_log (const T& x) { return internal::log(x); } @@ -37,5 +37,28 @@ template inline T ei_sin (const T& x) { return internal::sin(x); } template inline T ei_cos (const T& x) { return internal::cos(x); } template inline T ei_atan2(const T& x,const T& y) { return internal::atan2(x,y); } template inline T ei_pow (const T& x,const T& y) { return internal::pow(x,y); } +template inline T ei_random () { return internal::random(); } +template inline T ei_random (const T& x, const T& y) { return internal::random(x, y); } + +template +inline bool ei_isMuchSmallerThan(const Scalar& x, const OtherScalar& y, + typename NumTraits::Real precision = NumTraits::dummy_precision()) +{ + return internal::isMuchSmallerThan(x, y, precision); +} + +template +inline bool ei_isApprox(const Scalar& x, const Scalar& y, + typename NumTraits::Real precision = NumTraits::dummy_precision()) +{ + return internal::isMuchSmallerThan(x, y, precision); +} + +template +inline bool ei_isApproxOrLessThan(const Scalar& x, const Scalar& y, + typename NumTraits::Real precision = NumTraits::dummy_precision()) +{ + return internal::isMuchSmallerThan(x, y, precision); +} #endif // EIGEN2_MATH_FUNCTIONS_H diff --git a/Eigen/src/Eigen2Support/Meta.h b/Eigen/src/Eigen2Support/Meta.h new file mode 100644 index 000000000..f78db2b8d --- /dev/null +++ b/Eigen/src/Eigen2Support/Meta.h @@ -0,0 +1,39 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Benoit Jacob +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN2_META_H +#define EIGEN2_META_H + +template +struct ei_traits : internal::traits +{}; + +template +struct ei_is_same_type +{ + enum { ret = internal::is_same::value }; +}; + + +#endif // EIGEN2_META_H diff --git a/test/eigen2/CMakeLists.txt b/test/eigen2/CMakeLists.txt index 2828275bc..c92257224 100644 --- a/test/eigen2/CMakeLists.txt +++ b/test/eigen2/CMakeLists.txt @@ -3,6 +3,7 @@ add_custom_target(check_eigen2 COMMAND "ctest") add_dependencies(check_eigen2 buildtests_eigen2) add_definitions("-DEIGEN_NO_EIGEN2_DEPRECATED_WARNINGS") +add_definitions("-DEIGEN2_SUPPORT") # Macro to add a test # diff --git a/test/eigen2/main.h b/test/eigen2/main.h index d919ee91a..65d56377a 100644 --- a/test/eigen2/main.h +++ b/test/eigen2/main.h @@ -110,6 +110,7 @@ namespace Eigen #else // EIGEN_DEBUG_ASSERTS + #undef ei_asset #define ei_assert(a) \ if( (!(a)) && (!no_more_assert) ) \ { \ @@ -145,12 +146,12 @@ namespace Eigen std::exit(2); \ } } while (0) -#define VERIFY_IS_APPROX(a, b) VERIFY(test_isApprox(a, b)) -#define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_isApprox(a, b)) -#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) VERIFY(test_isMuchSmallerThan(a, b)) -#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_isMuchSmallerThan(a, b)) -#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_isApproxOrLessThan(a, b)) -#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_isApproxOrLessThan(a, b)) +#define VERIFY_IS_APPROX(a, b) VERIFY(test_ei_isApprox(a, b)) +#define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_ei_isApprox(a, b)) +#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) VERIFY(test_ei_isMuchSmallerThan(a, b)) +#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_ei_isMuchSmallerThan(a, b)) +#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_ei_isApproxOrLessThan(a, b)) +#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_ei_isApproxOrLessThan(a, b)) #define CALL_SUBTEST(FUNC) do { \ g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \ @@ -168,62 +169,62 @@ template<> inline float test_precision >() { return test_pre template<> inline double test_precision >() { return test_precision(); } template<> inline long double test_precision() { return 1e-6; } -inline bool test_isApprox(const int& a, const int& b) -{ return internal::isApprox(a, b, test_precision()); } -inline bool test_isMuchSmallerThan(const int& a, const int& b) -{ return internal::isMuchSmallerThan(a, b, test_precision()); } -inline bool test_isApproxOrLessThan(const int& a, const int& b) -{ return internal::isApproxOrLessThan(a, b, test_precision()); } +inline bool test_ei_isApprox(const int& a, const int& b) +{ return ei_isApprox(a, b, test_precision()); } +inline bool test_ei_isMuchSmallerThan(const int& a, const int& b) +{ return ei_isMuchSmallerThan(a, b, test_precision()); } +inline bool test_ei_isApproxOrLessThan(const int& a, const int& b) +{ return ei_isApproxOrLessThan(a, b, test_precision()); } -inline bool test_isApprox(const float& a, const float& b) -{ return internal::isApprox(a, b, test_precision()); } -inline bool test_isMuchSmallerThan(const float& a, const float& b) -{ return internal::isMuchSmallerThan(a, b, test_precision()); } -inline bool test_isApproxOrLessThan(const float& a, const float& b) -{ return internal::isApproxOrLessThan(a, b, test_precision()); } +inline bool test_ei_isApprox(const float& a, const float& b) +{ return ei_isApprox(a, b, test_precision()); } +inline bool test_ei_isMuchSmallerThan(const float& a, const float& b) +{ return ei_isMuchSmallerThan(a, b, test_precision()); } +inline bool test_ei_isApproxOrLessThan(const float& a, const float& b) +{ return ei_isApproxOrLessThan(a, b, test_precision()); } -inline bool test_isApprox(const double& a, const double& b) -{ return internal::isApprox(a, b, test_precision()); } -inline bool test_isMuchSmallerThan(const double& a, const double& b) -{ return internal::isMuchSmallerThan(a, b, test_precision()); } -inline bool test_isApproxOrLessThan(const double& a, const double& b) -{ return internal::isApproxOrLessThan(a, b, test_precision()); } +inline bool test_ei_isApprox(const double& a, const double& b) +{ return ei_isApprox(a, b, test_precision()); } +inline bool test_ei_isMuchSmallerThan(const double& a, const double& b) +{ return ei_isMuchSmallerThan(a, b, test_precision()); } +inline bool test_ei_isApproxOrLessThan(const double& a, const double& b) +{ return ei_isApproxOrLessThan(a, b, test_precision()); } -inline bool test_isApprox(const std::complex& a, const std::complex& b) -{ return internal::isApprox(a, b, test_precision >()); } -inline bool test_isMuchSmallerThan(const std::complex& a, const std::complex& b) -{ return internal::isMuchSmallerThan(a, b, test_precision >()); } +inline bool test_ei_isApprox(const std::complex& a, const std::complex& b) +{ return ei_isApprox(a, b, test_precision >()); } +inline bool test_ei_isMuchSmallerThan(const std::complex& a, const std::complex& b) +{ return ei_isMuchSmallerThan(a, b, test_precision >()); } -inline bool test_isApprox(const std::complex& a, const std::complex& b) -{ return internal::isApprox(a, b, test_precision >()); } -inline bool test_isMuchSmallerThan(const std::complex& a, const std::complex& b) -{ return internal::isMuchSmallerThan(a, b, test_precision >()); } +inline bool test_ei_isApprox(const std::complex& a, const std::complex& b) +{ return ei_isApprox(a, b, test_precision >()); } +inline bool test_ei_isMuchSmallerThan(const std::complex& a, const std::complex& b) +{ return ei_isMuchSmallerThan(a, b, test_precision >()); } -inline bool test_isApprox(const long double& a, const long double& b) -{ return internal::isApprox(a, b, test_precision()); } -inline bool test_isMuchSmallerThan(const long double& a, const long double& b) -{ return internal::isMuchSmallerThan(a, b, test_precision()); } -inline bool test_isApproxOrLessThan(const long double& a, const long double& b) -{ return internal::isApproxOrLessThan(a, b, test_precision()); } +inline bool test_ei_isApprox(const long double& a, const long double& b) +{ return ei_isApprox(a, b, test_precision()); } +inline bool test_ei_isMuchSmallerThan(const long double& a, const long double& b) +{ return ei_isMuchSmallerThan(a, b, test_precision()); } +inline bool test_ei_isApproxOrLessThan(const long double& a, const long double& b) +{ return ei_isApproxOrLessThan(a, b, test_precision()); } template -inline bool test_isApprox(const Type1& a, const Type2& b) +inline bool test_ei_isApprox(const Type1& a, const Type2& b) { return a.isApprox(b, test_precision()); } template -inline bool test_isMuchSmallerThan(const MatrixBase& m1, +inline bool test_ei_isMuchSmallerThan(const MatrixBase& m1, const MatrixBase& m2) { - return m1.isMuchSmallerThan(m2, test_precision::Scalar>()); + return m1.isMuchSmallerThan(m2, test_precision::Scalar>()); } template -inline bool test_isMuchSmallerThan(const MatrixBase& m, - const typename NumTraits::Scalar>::Real& s) +inline bool test_ei_isMuchSmallerThan(const MatrixBase& m, + const typename NumTraits::Scalar>::Real& s) { - return m.isMuchSmallerThan(s, test_precision::Scalar>()); + return m.isMuchSmallerThan(s, test_precision::Scalar>()); } } // end namespace Eigen diff --git a/test/eigen2/prec_inverse_4x4.cpp b/test/eigen2/prec_inverse_4x4.cpp index 4eed047fe..762c8ea32 100644 --- a/test/eigen2/prec_inverse_4x4.cpp +++ b/test/eigen2/prec_inverse_4x4.cpp @@ -71,7 +71,7 @@ template void inverse_general_4x4(int repeat) RealScalar absdet; do { m = MatrixType::Random(); - absdet = internal::abs(m.determinant()); + absdet = ei_abs(m.determinant()); } while(absdet < 10 * epsilon()); MatrixType inv = m.inverse(); double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon() );