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
This commit is contained in:
Benoit Jacob 2011-01-19 11:01:07 -05:00
parent bf0cffa897
commit 96f08213f7
9 changed files with 161 additions and 47 deletions

View File

@ -43,6 +43,8 @@ namespace Eigen {
* *
*/ */
#include "src/Eigen2Support/Macros.h"
#include "src/Eigen2Support/Meta.h"
#include "src/Eigen2Support/Lazy.h" #include "src/Eigen2Support/Lazy.h"
#include "src/Eigen2Support/Cwise.h" #include "src/Eigen2Support/Cwise.h"
#include "src/Eigen2Support/CwiseOperators.h" #include "src/Eigen2Support/CwiseOperators.h"

View File

@ -429,7 +429,11 @@ struct sqrt_default_impl<Scalar, true>
{ {
static inline Scalar run(const Scalar&) static inline Scalar run(const Scalar&)
{ {
#ifdef EIGEN2_SUPPORT
eigen_assert(!NumTraits<Scalar>::IsInteger);
#else
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
#endif
return Scalar(0); return Scalar(0);
} }
}; };

View File

@ -69,6 +69,12 @@ template<typename T> struct GenericNumTraits
AddCost = 1, AddCost = 1,
MulCost = 1 MulCost = 1
}; };
#ifdef EIGEN2_SUPPORT
enum {
HasFloatingPoint = !IsInteger
};
#endif
typedef T Real; typedef T Real;
typedef typename internal::conditional< typedef typename internal::conditional<

View File

@ -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

View File

@ -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_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 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_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 typename NumTraits<T>::Real 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_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_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_exp (const T& x) { return internal::exp(x); }
template<typename T> inline T ei_log (const T& x) { return internal::log(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_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_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_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 #endif // EIGEN2_MATH_FUNCTIONS_H

View File

@ -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

View File

@ -3,6 +3,7 @@ add_custom_target(check_eigen2 COMMAND "ctest")
add_dependencies(check_eigen2 buildtests_eigen2) add_dependencies(check_eigen2 buildtests_eigen2)
add_definitions("-DEIGEN_NO_EIGEN2_DEPRECATED_WARNINGS") add_definitions("-DEIGEN_NO_EIGEN2_DEPRECATED_WARNINGS")
add_definitions("-DEIGEN2_SUPPORT")
# Macro to add a test # Macro to add a test
# #

View File

@ -110,6 +110,7 @@ namespace Eigen
#else // EIGEN_DEBUG_ASSERTS #else // EIGEN_DEBUG_ASSERTS
#undef ei_asset
#define ei_assert(a) \ #define ei_assert(a) \
if( (!(a)) && (!no_more_assert) ) \ if( (!(a)) && (!no_more_assert) ) \
{ \ { \
@ -145,12 +146,12 @@ namespace Eigen
std::exit(2); \ std::exit(2); \
} } while (0) } } while (0)
#define VERIFY_IS_APPROX(a, b) VERIFY(test_isApprox(a, b)) #define VERIFY_IS_APPROX(a, b) VERIFY(test_ei_isApprox(a, b))
#define VERIFY_IS_NOT_APPROX(a, b) VERIFY(!test_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_isMuchSmallerThan(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_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_isApproxOrLessThan(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_isApproxOrLessThan(a, b)) #define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_ei_isApproxOrLessThan(a, b))
#define CALL_SUBTEST(FUNC) do { \ #define CALL_SUBTEST(FUNC) do { \
g_test_stack.push_back(EI_PP_MAKE_STRING(FUNC)); \ 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 double test_precision<std::complex<double> >() { return test_precision<double>(); }
template<> inline long double test_precision<long double>() { return 1e-6; } template<> inline long double test_precision<long double>() { return 1e-6; }
inline bool test_isApprox(const int& a, const int& b) inline bool test_ei_isApprox(const int& a, const int& b)
{ return internal::isApprox(a, b, test_precision<int>()); } { return ei_isApprox(a, b, test_precision<int>()); }
inline bool test_isMuchSmallerThan(const int& a, const int& b) inline bool test_ei_isMuchSmallerThan(const int& a, const int& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<int>()); } { return ei_isMuchSmallerThan(a, b, test_precision<int>()); }
inline bool test_isApproxOrLessThan(const int& a, const int& b) inline bool test_ei_isApproxOrLessThan(const int& a, const int& b)
{ return internal::isApproxOrLessThan(a, b, test_precision<int>()); } { return ei_isApproxOrLessThan(a, b, test_precision<int>()); }
inline bool test_isApprox(const float& a, const float& b) inline bool test_ei_isApprox(const float& a, const float& b)
{ return internal::isApprox(a, b, test_precision<float>()); } { return ei_isApprox(a, b, test_precision<float>()); }
inline bool test_isMuchSmallerThan(const float& a, const float& b) inline bool test_ei_isMuchSmallerThan(const float& a, const float& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<float>()); } { return ei_isMuchSmallerThan(a, b, test_precision<float>()); }
inline bool test_isApproxOrLessThan(const float& a, const float& b) inline bool test_ei_isApproxOrLessThan(const float& a, const float& b)
{ return internal::isApproxOrLessThan(a, b, test_precision<float>()); } { return ei_isApproxOrLessThan(a, b, test_precision<float>()); }
inline bool test_isApprox(const double& a, const double& b) inline bool test_ei_isApprox(const double& a, const double& b)
{ return internal::isApprox(a, b, test_precision<double>()); } { return ei_isApprox(a, b, test_precision<double>()); }
inline bool test_isMuchSmallerThan(const double& a, const double& b) inline bool test_ei_isMuchSmallerThan(const double& a, const double& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<double>()); } { return ei_isMuchSmallerThan(a, b, test_precision<double>()); }
inline bool test_isApproxOrLessThan(const double& a, const double& b) inline bool test_ei_isApproxOrLessThan(const double& a, const double& b)
{ return internal::isApproxOrLessThan(a, b, test_precision<double>()); } { return ei_isApproxOrLessThan(a, b, test_precision<double>()); }
inline bool test_isApprox(const std::complex<float>& a, const std::complex<float>& b) inline bool test_ei_isApprox(const std::complex<float>& a, const std::complex<float>& b)
{ return internal::isApprox(a, b, test_precision<std::complex<float> >()); } { return ei_isApprox(a, b, test_precision<std::complex<float> >()); }
inline bool test_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b) inline bool test_ei_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); } { return ei_isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); }
inline bool test_isApprox(const std::complex<double>& a, const std::complex<double>& b) inline bool test_ei_isApprox(const std::complex<double>& a, const std::complex<double>& b)
{ return internal::isApprox(a, b, test_precision<std::complex<double> >()); } { return ei_isApprox(a, b, test_precision<std::complex<double> >()); }
inline bool test_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b) inline bool test_ei_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); } { return ei_isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); }
inline bool test_isApprox(const long double& a, const long double& b) inline bool test_ei_isApprox(const long double& a, const long double& b)
{ return internal::isApprox(a, b, test_precision<long double>()); } { return ei_isApprox(a, b, test_precision<long double>()); }
inline bool test_isMuchSmallerThan(const long double& a, const long double& b) inline bool test_ei_isMuchSmallerThan(const long double& a, const long double& b)
{ return internal::isMuchSmallerThan(a, b, test_precision<long double>()); } { return ei_isMuchSmallerThan(a, b, test_precision<long double>()); }
inline bool test_isApproxOrLessThan(const long double& a, const long double& b) inline bool test_ei_isApproxOrLessThan(const long double& a, const long double& b)
{ return internal::isApproxOrLessThan(a, b, test_precision<long double>()); } { return ei_isApproxOrLessThan(a, b, test_precision<long double>()); }
template<typename Type1, typename Type2> 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>()); return a.isApprox(b, test_precision<typename Type1::Scalar>());
} }
template<typename Derived1, typename Derived2> 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) 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> template<typename Derived>
inline bool test_isMuchSmallerThan(const MatrixBase<Derived>& m, inline bool test_ei_isMuchSmallerThan(const MatrixBase<Derived>& m,
const typename NumTraits<typename internal::traits<Derived>::Scalar>::Real& s) 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 } // end namespace Eigen

View File

@ -71,7 +71,7 @@ template<typename MatrixType> void inverse_general_4x4(int repeat)
RealScalar absdet; RealScalar absdet;
do { do {
m = MatrixType::Random(); m = MatrixType::Random();
absdet = internal::abs(m.determinant()); absdet = ei_abs(m.determinant());
} while(absdet < 10 * epsilon<Scalar>()); } while(absdet < 10 * epsilon<Scalar>());
MatrixType inv = m.inverse(); MatrixType inv = m.inverse();
double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon<Scalar>() ); double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon<Scalar>() );