diff options
-rw-r--r-- | Eigen/Eigen2Support | 2 | ||||
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/NumTraits.h | 6 | ||||
-rw-r--r-- | Eigen/src/Eigen2Support/Macros.h | 38 | ||||
-rw-r--r-- | Eigen/src/Eigen2Support/MathFunctions.h | 27 | ||||
-rw-r--r-- | Eigen/src/Eigen2Support/Meta.h | 39 | ||||
-rw-r--r-- | test/eigen2/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/eigen2/main.h | 99 | ||||
-rw-r--r-- | test/eigen2/prec_inverse_4x4.cpp | 2 |
9 files changed, 166 insertions, 52 deletions
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<Scalar, true> { static inline Scalar run(const Scalar&) { +#ifdef EIGEN2_SUPPORT + eigen_assert(!NumTraits<Scalar>::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<typename T> 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 <jacob.benoit.1@gmail.com> +// +// 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 <http://www.gnu.org/licenses/>. + +#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<typename T> inline typename NumTraits<T>::Real ei_real(const T& x) { return internal::real(x); } template<typename T> inline typename NumTraits<T>::Real ei_imag(const T& x) { return internal::imag(x); } template<typename T> inline T ei_conj(const T& x) { return internal::conj(x); } -template<typename T> inline T ei_abs (const T& x) { return internal::abs(x); } -template<typename T> inline T ei_abs2(const T& x) { return internal::abs2(x); } +template<typename T> inline typename NumTraits<T>::Real ei_abs (const T& x) { return internal::abs(x); } +template<typename T> inline typename NumTraits<T>::Real ei_abs2(const T& x) { return internal::abs2(x); } template<typename T> inline T ei_sqrt(const T& x) { return internal::sqrt(x); } template<typename T> inline T ei_exp (const T& x) { return internal::exp(x); } template<typename T> inline T ei_log (const T& x) { return internal::log(x); } @@ -37,5 +37,28 @@ template<typename T> inline T ei_sin (const T& x) { return internal::sin(x); } template<typename T> inline T ei_cos (const T& x) { return internal::cos(x); } template<typename T> inline T ei_atan2(const T& x,const T& y) { return internal::atan2(x,y); } template<typename T> inline T ei_pow (const T& x,const T& y) { return internal::pow(x,y); } +template<typename T> inline T ei_random () { return internal::random<T>(); } +template<typename T> inline T ei_random (const T& x, const T& y) { return internal::random(x, y); } + +template<typename Scalar, typename OtherScalar> +inline bool ei_isMuchSmallerThan(const Scalar& x, const OtherScalar& y, + typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) +{ + return internal::isMuchSmallerThan(x, y, precision); +} + +template<typename Scalar> +inline bool ei_isApprox(const Scalar& x, const Scalar& y, + typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) +{ + return internal::isMuchSmallerThan(x, y, precision); +} + +template<typename Scalar> +inline bool ei_isApproxOrLessThan(const Scalar& x, const Scalar& y, + typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::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 <jacob.benoit.1@gmail.com> +// +// 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 <http://www.gnu.org/licenses/>. + +#ifndef EIGEN2_META_H +#define EIGEN2_META_H + +template<typename T> +struct ei_traits : internal::traits<T> +{}; + +template<typename T, typename U> +struct ei_is_same_type +{ + enum { ret = internal::is_same<T, U>::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<std::complex<float> >() { return test_pre template<> inline double test_precision<std::complex<double> >() { return test_precision<double>(); } template<> inline long double test_precision<long double>() { return 1e-6; } -inline bool test_isApprox(const int& a, const int& b) -{ return internal::isApprox(a, b, test_precision<int>()); } -inline bool test_isMuchSmallerThan(const int& a, const int& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<int>()); } -inline bool test_isApproxOrLessThan(const int& a, const int& b) -{ return internal::isApproxOrLessThan(a, b, test_precision<int>()); } - -inline bool test_isApprox(const float& a, const float& b) -{ return internal::isApprox(a, b, test_precision<float>()); } -inline bool test_isMuchSmallerThan(const float& a, const float& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<float>()); } -inline bool test_isApproxOrLessThan(const float& a, const float& b) -{ return internal::isApproxOrLessThan(a, b, test_precision<float>()); } - -inline bool test_isApprox(const double& a, const double& b) -{ return internal::isApprox(a, b, test_precision<double>()); } -inline bool test_isMuchSmallerThan(const double& a, const double& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<double>()); } -inline bool test_isApproxOrLessThan(const double& a, const double& b) -{ return internal::isApproxOrLessThan(a, b, test_precision<double>()); } - -inline bool test_isApprox(const std::complex<float>& a, const std::complex<float>& b) -{ return internal::isApprox(a, b, test_precision<std::complex<float> >()); } -inline bool test_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); } - -inline bool test_isApprox(const std::complex<double>& a, const std::complex<double>& b) -{ return internal::isApprox(a, b, test_precision<std::complex<double> >()); } -inline bool test_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); } - -inline bool test_isApprox(const long double& a, const long double& b) -{ return internal::isApprox(a, b, test_precision<long double>()); } -inline bool test_isMuchSmallerThan(const long double& a, const long double& b) -{ return internal::isMuchSmallerThan(a, b, test_precision<long double>()); } -inline bool test_isApproxOrLessThan(const long double& a, const long double& b) -{ return internal::isApproxOrLessThan(a, b, test_precision<long double>()); } +inline bool test_ei_isApprox(const int& a, const int& b) +{ return ei_isApprox(a, b, test_precision<int>()); } +inline bool test_ei_isMuchSmallerThan(const int& a, const int& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<int>()); } +inline bool test_ei_isApproxOrLessThan(const int& a, const int& b) +{ return ei_isApproxOrLessThan(a, b, test_precision<int>()); } + +inline bool test_ei_isApprox(const float& a, const float& b) +{ return ei_isApprox(a, b, test_precision<float>()); } +inline bool test_ei_isMuchSmallerThan(const float& a, const float& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<float>()); } +inline bool test_ei_isApproxOrLessThan(const float& a, const float& b) +{ return ei_isApproxOrLessThan(a, b, test_precision<float>()); } + +inline bool test_ei_isApprox(const double& a, const double& b) +{ return ei_isApprox(a, b, test_precision<double>()); } +inline bool test_ei_isMuchSmallerThan(const double& a, const double& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<double>()); } +inline bool test_ei_isApproxOrLessThan(const double& a, const double& b) +{ return ei_isApproxOrLessThan(a, b, test_precision<double>()); } + +inline bool test_ei_isApprox(const std::complex<float>& a, const std::complex<float>& b) +{ return ei_isApprox(a, b, test_precision<std::complex<float> >()); } +inline bool test_ei_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); } + +inline bool test_ei_isApprox(const std::complex<double>& a, const std::complex<double>& b) +{ return ei_isApprox(a, b, test_precision<std::complex<double> >()); } +inline bool test_ei_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); } + +inline bool test_ei_isApprox(const long double& a, const long double& b) +{ return ei_isApprox(a, b, test_precision<long double>()); } +inline bool test_ei_isMuchSmallerThan(const long double& a, const long double& b) +{ return ei_isMuchSmallerThan(a, b, test_precision<long double>()); } +inline bool test_ei_isApproxOrLessThan(const long double& a, const long double& b) +{ return ei_isApproxOrLessThan(a, b, test_precision<long double>()); } template<typename Type1, typename Type2> -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<typename Type1::Scalar>()); } template<typename Derived1, typename Derived2> -inline bool test_isMuchSmallerThan(const MatrixBase<Derived1>& m1, +inline bool test_ei_isMuchSmallerThan(const MatrixBase<Derived1>& m1, const MatrixBase<Derived2>& m2) { - return m1.isMuchSmallerThan(m2, test_precision<typename internal::traits<Derived1>::Scalar>()); + return m1.isMuchSmallerThan(m2, test_precision<typename ei_traits<Derived1>::Scalar>()); } template<typename Derived> -inline bool test_isMuchSmallerThan(const MatrixBase<Derived>& m, - const typename NumTraits<typename internal::traits<Derived>::Scalar>::Real& s) +inline bool test_ei_isMuchSmallerThan(const MatrixBase<Derived>& m, + const typename NumTraits<typename ei_traits<Derived>::Scalar>::Real& s) { - return m.isMuchSmallerThan(s, test_precision<typename internal::traits<Derived>::Scalar>()); + return m.isMuchSmallerThan(s, test_precision<typename ei_traits<Derived>::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<typename MatrixType> 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<Scalar>()); MatrixType inv = m.inverse(); double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon<Scalar>() ); |